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

Function CalcProjectionToSegment

libs/routing/fake_ending.cpp:21–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19using namespace std;
20
21LatLonWithAltitude CalcProjectionToSegment(LatLonWithAltitude const & begin, LatLonWithAltitude const & end,
22 m2::PointD const & point)
23{
24 m2::ParametrizedSegment<m2::PointD> segment(mercator::FromLatLon(begin.GetLatLon()),
25 mercator::FromLatLon(end.GetLatLon()));
26
27 auto const projectedPoint = segment.ClosestPointTo(point);
28 auto const distBeginToEnd = ms::DistanceOnEarth(begin.GetLatLon(), end.GetLatLon());
29
30 auto const projectedLatLon = mercator::ToLatLon(projectedPoint);
31
32 double constexpr kEpsMeters = 2.0;
33 if (AlmostEqualAbs(distBeginToEnd, 0.0, kEpsMeters))
34 return LatLonWithAltitude(projectedLatLon, begin.GetAltitude());
35
36 auto const distBeginToProjection = ms::DistanceOnEarth(begin.GetLatLon(), projectedLatLon);
37
38 auto const altitude =
39 begin.GetAltitude() + (end.GetAltitude() - begin.GetAltitude()) * distBeginToProjection / distBeginToEnd;
40 return LatLonWithAltitude(projectedLatLon, altitude);
41}
42
43bool Projection::operator==(Projection const & other) const
44{

Callers 2

MakeFakeEndingFunction · 0.85
GetFakeEndingMethod · 0.85

Calls 8

LatLonWithAltitudeClass · 0.85
ClosestPointToMethod · 0.80
FromLatLonFunction · 0.50
DistanceOnEarthFunction · 0.50
ToLatLonFunction · 0.50
AlmostEqualAbsFunction · 0.50
GetLatLonMethod · 0.45
GetAltitudeMethod · 0.45

Tested by

no test coverage detected