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

Function GetDistanceMeters

libs/search/geocoder.cpp:285–299  ·  view source on GitHub ↗

Returns shortest distance from the |pivot| to the |rect|. NOTE* calculations below are incorrect, because shortest distance on the Mercator's plane is not the same as shortest distance on the Earth. But we assume that it is not an issue here.

Source from the content-addressed store, hash-verified

283// on the Mercator's plane is not the same as shortest distance on the
284// Earth. But we assume that it is not an issue here.
285double GetDistanceMeters(m2::PointD const & pivot, m2::RectD const & rect)
286{
287 if (rect.IsPointInside(pivot))
288 return 0.0;
289
290 double distance = numeric_limits<double>::max();
291
292 rect.ForEachSide([&](m2::PointD const & a, m2::PointD const & b)
293 {
294 m2::ParametrizedSegment<m2::PointD> segment(a, b);
295 distance = min(distance, mercator::DistanceOnEarth(pivot, segment.ClosestPointTo(pivot)));
296 });
297
298 return distance;
299}
300
301unique_ptr<MwmContext> GetWorldContext(DataSource const & dataSource)
302{

Callers 1

OrderCountriesMethod · 0.70

Calls 4

ForEachSideMethod · 0.80
ClosestPointToMethod · 0.80
DistanceOnEarthFunction · 0.50
IsPointInsideMethod · 0.45

Tested by

no test coverage detected