| 19 | using namespace std; |
| 20 | |
| 21 | LatLonWithAltitude 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 | |
| 43 | bool Projection::operator==(Projection const & other) const |
| 44 | { |
no test coverage detected