| 144 | } |
| 145 | |
| 146 | ScreenBase 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()) |
no test coverage detected