| 102 | } |
| 103 | |
| 104 | ScreenBase 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 | |
| 146 | ScreenBase const ShrinkAndScaleInto(ScreenBase const & screen, m2::RectD const & boundRect) |
| 147 | { |