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

Function ScaleInto

libs/drape_frontend/screen_operations.cpp:104–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104ScreenBase const ScaleInto(ScreenBase const & screen, m2::RectD const & boundRect)
105{
106 ScreenBase res = screen;
107
108 double scale = 1;
109 m2::RectD clipRect = res.ClipRect();
110
111 auto const DoScale = [&scale, &clipRect, &boundRect](double k)
112 {
113 // https://github.com/organicmaps/organicmaps/issues/544
114 if (k > 0)
115 {
116 scale /= k;
117 clipRect.Scale(k);
118 }
119 else
120 {
121 // Will break in Debug, log in Release.
122 LOG(LERROR, ("Bad scale factor =", k, "Bound rect =", boundRect, "Clip rect =", clipRect));
123 }
124 };
125
126 ASSERT(boundRect.IsPointInside(clipRect.Center()), ("center point should be inside boundRect"));
127
128 if (clipRect.minX() < boundRect.minX())
129 DoScale((boundRect.minX() - clipRect.Center().x) / (clipRect.minX() - clipRect.Center().x));
130
131 if (clipRect.maxX() > boundRect.maxX())
132 DoScale((boundRect.maxX() - clipRect.Center().x) / (clipRect.maxX() - clipRect.Center().x));
133
134 if (clipRect.minY() < boundRect.minY())
135 DoScale((boundRect.minY() - clipRect.Center().y) / (clipRect.minY() - clipRect.Center().y));
136
137 if (clipRect.maxY() > boundRect.maxY())
138 DoScale((boundRect.maxY() - clipRect.Center().y) / (clipRect.maxY() - clipRect.Center().y));
139
140 res.Scale(scale);
141 res.SetOrg(clipRect.Center());
142
143 return res;
144}
145
146ScreenBase const ShrinkAndScaleInto(ScreenBase const & screen, m2::RectD const & boundRect)
147{

Callers 3

ApplyScaleFunction · 0.85
SetFromScreenMethod · 0.85
ScaleImplMethod · 0.85

Calls 9

ASSERTFunction · 0.85
minXMethod · 0.80
maxXMethod · 0.80
minYMethod · 0.80
maxYMethod · 0.80
SetOrgMethod · 0.80
ScaleMethod · 0.45
IsPointInsideMethod · 0.45
CenterMethod · 0.45

Tested by

no test coverage detected