diff options
author | vng <viktor.govako@gmail.com> | 2013-10-29 17:46:47 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:04:18 +0300 |
commit | 36824a459cf539d024a5c0bd07e2e7257b986ffd (patch) | |
tree | 1f4289eadd3343a5d24c52712380bfb353d89c9d /map/track.cpp | |
parent | ed59cfa77b60fc1e19f9a4709fc38d406a91172c (diff) |
[tracks] Track::GetLengthMeters.
Diffstat (limited to 'map/track.cpp')
-rw-r--r-- | map/track.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/map/track.cpp b/map/track.cpp index 0f84f75e1f..f645f06279 100644 --- a/map/track.cpp +++ b/map/track.cpp @@ -1,5 +1,7 @@ #include "track.hpp" +#include "../indexer/mercator.hpp" + #include "../graphics/screen.hpp" #include "../graphics/pen.hpp" #include "../graphics/depth_constants.hpp" @@ -7,6 +9,7 @@ #include "../geometry/distance.hpp" #include "../geometry/simplification.hpp" +#include "../geometry/distance_on_sphere.hpp" #include "../base/timer.hpp" #include "../base/logging.hpp" @@ -80,6 +83,25 @@ void Track::CreateDisplayList(graphics::Screen * dlScreen, MatrixT const & matri dlScreen->endFrame(); } +double Track::GetLengthMeters() const +{ + double res = 0.0; + + PolylineD::IterT i = m_polyline.Begin(); + double lat1 = MercatorBounds::YToLat(i->y); + double lon1 = MercatorBounds::XToLon(i->x); + for (++i; i != m_polyline.End(); ++i) + { + double const lat2 = MercatorBounds::YToLat(i->y); + double const lon2 = MercatorBounds::XToLon(i->x); + res += ms::DistanceOnEarth(lat1, lon1, lat2, lon2); + lat1 = lat2; + lon1 = lon2; + } + + return res; +} + double Track::GetShortestSquareDistance(m2::PointD const & point) const { double res = numeric_limits<double>::max(); |