Skip to content

Commit

Permalink
Merge pull request #1271 from awulkiew/fix/closest_points
Browse files Browse the repository at this point in the history
[strategies] Fix spherical closest_points strategy for PointOfSegment different than model::point
  • Loading branch information
vissarion committed Jul 24, 2024
2 parents 8dc75e6 + f079580 commit 373d518
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Boost.Geometry

// Copyright (c) 2024 Adam Wulkiewicz, Lodz, Poland.

// Copyright (c) 2021, Oracle and/or its affiliates.

// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
Expand All @@ -16,6 +18,8 @@
#include <boost/config.hpp>
#include <boost/concept_check.hpp>

#include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>

#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/core/access.hpp>
#include <boost/geometry/core/coordinate_promotion.hpp>
Expand Down Expand Up @@ -85,13 +89,21 @@ class cross_track
{
using CT = typename calculation_type<Point, PointOfSegment>::type;

model::point
<
CT,
dimension<PointOfSegment>::value,
typename coordinate_system<PointOfSegment>::type
> result;

// http://williams.best.vwh.net/avform.htm#XTE
CT d3 = m_strategy.apply(sp1, sp2);

if (geometry::math::equals(d3, 0.0))
{
// "Degenerate" segment, return either d1 or d2
return sp1;
geometry::detail::conversion::convert_point_to_point(sp1, result);
return result;
}

CT d1 = m_strategy.apply(sp1, p);
Expand Down Expand Up @@ -159,24 +171,18 @@ class cross_track
false
>(lon1, lat1, s14_sph, a12, srs::sphere<CT>(earth_radius));

model::point
<
CT,
dimension<PointOfSegment>::value,
typename coordinate_system<PointOfSegment>::type
> cp;

geometry::set_from_radian<0>(cp, res_direct.lon2);
geometry::set_from_radian<1>(cp, res_direct.lat2);
geometry::set_from_radian<0>(result, res_direct.lon2);
geometry::set_from_radian<1>(result, res_direct.lat2);

return cp;
return result;
}
else
{
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK
std::cout << "Projection OUTSIDE the segment" << std::endl;
#endif
return d1 < d2 ? sp1 : sp2;
geometry::detail::conversion::convert_point_to_point(d1 < d2 ? sp1 : sp2, result);
return result;
}
}

Expand Down

0 comments on commit 373d518

Please sign in to comment.