MCPcopy Create free account
hub / github.com/comaps/comaps / ShrinkAndScaleInto

Function ShrinkAndScaleInto

libs/drape_frontend/screen_operations.cpp:146–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146ScreenBase const ShrinkAndScaleInto(ScreenBase const & screen, m2::RectD const & boundRect)
147{
148 ScreenBase res = screen;
149
150 m2::RectD globalRect = res.ClipRect();
151
152 m2::PointD newOrg = res.GetOrg();
153 double scale = 1;
154 double offs = 0;
155
156 if (globalRect.minX() < boundRect.minX())
157 {
158 offs = boundRect.minX() - globalRect.minX();
159 globalRect.Offset(offs, 0);
160 newOrg.x += offs;
161
162 if (globalRect.maxX() > boundRect.maxX())
163 {
164 double k = boundRect.SizeX() / globalRect.SizeX();
165 scale /= k;
166 /// scaling always occur pinpointed to the rect center...
167 globalRect.Scale(k);
168 /// ...so we should shift a rect after scale
169 globalRect.Offset(boundRect.minX() - globalRect.minX(), 0);
170 }
171 }
172
173 if (globalRect.maxX() > boundRect.maxX())
174 {
175 offs = boundRect.maxX() - globalRect.maxX();
176 globalRect.Offset(offs, 0);
177 newOrg.x += offs;
178
179 if (globalRect.minX() < boundRect.minX())
180 {
181 double k = boundRect.SizeX() / globalRect.SizeX();
182 scale /= k;
183 globalRect.Scale(k);
184 globalRect.Offset(boundRect.maxX() - globalRect.maxX(), 0);
185 }
186 }
187
188 if (globalRect.minY() < boundRect.minY())
189 {
190 offs = boundRect.minY() - globalRect.minY();
191 globalRect.Offset(0, offs);
192 newOrg.y += offs;
193
194 if (globalRect.maxY() > boundRect.maxY())
195 {
196 double k = boundRect.SizeY() / globalRect.SizeY();
197 scale /= k;
198 globalRect.Scale(k);
199 globalRect.Offset(0, boundRect.minY() - globalRect.minY());
200 }
201 }
202
203 if (globalRect.maxY() > boundRect.maxY())

Callers 6

OnSizeMethod · 0.85
OnMoveMethod · 0.85
OnSetCenterMethod · 0.85
OnNewVisibleViewportMethod · 0.85
OnScrollMethod · 0.85
SetFollowAndRotateMethod · 0.85

Calls 10

minXMethod · 0.80
maxXMethod · 0.80
SizeXMethod · 0.80
minYMethod · 0.80
maxYMethod · 0.80
SizeYMethod · 0.80
SetOrgMethod · 0.80
OffsetMethod · 0.45
ScaleMethod · 0.45
CenterMethod · 0.45

Tested by

no test coverage detected