Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2012-08-14 14:31:08 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:42:04 +0300
commitf2bc36fe8be84c8b22d6a07495d8fad70a4c34f0 (patch)
tree76538e82fb5c8079f061be83ade8b9c7db191136 /map/ruler.cpp
parente95659641b14b01e5104332815f6ab6bc8207391 (diff)
fixed Ruler to behave correctly during screen rotation.
Diffstat (limited to 'map/ruler.cpp')
-rw-r--r--map/ruler.cpp33
1 files changed, 21 insertions, 12 deletions
diff --git a/map/ruler.cpp b/map/ruler.cpp
index ee8a952d03..0c78d047b0 100644
--- a/map/ruler.cpp
+++ b/map/ruler.cpp
@@ -7,6 +7,7 @@
#include "../yg/skin.hpp"
#include "../indexer/mercator.hpp"
+#include "../geometry/distance_on_sphere.hpp"
#include "../base/logging.hpp"
#include "../base/string_utils.hpp"
@@ -208,25 +209,33 @@ void Ruler::update()
m2::PointD pt0 = m_screen.PtoG(pivot() - m2::PointD(minPxWidth / 2, 0));
m2::PointD pt1 = m_screen.PtoG(pivot() + m2::PointD(minPxWidth / 2, 0));
- /// correction factor, calculated from Y-coordinate.
- double const lonDiffCorrection = cos(MercatorBounds::YToLat(glbPivot.y) / 180.0 * math::pi);
-
- /// longitude difference between two points
- double lonDiff = fabs(MercatorBounds::XToLon(pt0.x) - MercatorBounds::XToLon(pt1.x));
+ double DistanceInMetres = ms::DistanceOnEarth(MercatorBounds::YToLat(pt0.y),
+ MercatorBounds::XToLon(pt0.x),
+ MercatorBounds::YToLat(pt1.y),
+ MercatorBounds::XToLon(pt1.x));
/// converting into metres
- CalcMetresDiff(m_conversionFn(lonDiff / MercatorBounds::degreeInMetres * lonDiffCorrection));
+ CalcMetresDiff(m_conversionFn(DistanceInMetres));
bool higherThanMax = m_metresDiff > m_maxUnitsWidth;
bool lessThanMin = m_metresDiff < m_minUnitsWidth;
- /// translating metres into pixels
- double scalerWidthLatDiff = (double)m_metresDiff * MercatorBounds::degreeInMetres / lonDiffCorrection;
- double scalerWidthXDiff = MercatorBounds::LonToX(glbPivot.x + scalerWidthLatDiff / 2)
- - MercatorBounds::LonToX(glbPivot.x - scalerWidthLatDiff / 2);
+ double scalerWidthInPx = minPxWidth;
+
+ if (!higherThanMax && !lessThanMin)
+ {
+ double a = ang::AngleTo(pt0, pt1);
+ m2::RectD r = MercatorBounds::RectByCenterXYAndSizeInMeters(glbPivot.x,
+ glbPivot.y,
+ cos(a) * m_metresDiff / 2,
+ sin(a) * m_metresDiff / 2);
- double scalerWidthInPx = m_screen.GtoP(glbPivot).x - m_screen.GtoP(glbPivot + m2::PointD(scalerWidthXDiff, 0)).x;
- scalerWidthInPx = (higherThanMax || lessThanMin) ? minPxWidth : abs(my::rounds(scalerWidthInPx));
+ pt0 = m_screen.GtoP(m2::PointD(r.minX(), r.minY()));
+ pt1 = m_screen.GtoP(m2::PointD(r.maxX(), r.maxY()));
+
+ scalerWidthInPx = pt0.Length(pt1);
+ scalerWidthInPx = abs(my::rounds(scalerWidthInPx));
+ }
m2::PointD scalerOrg = pivot() + m2::PointD(-scalerWidthInPx / 2, rulerHeight / 2);