diff --git a/include/boost/geometry/formulas/distance_point_segment.hpp b/include/boost/geometry/formulas/distance_point_segment.hpp index 6363aac8b..a6ce5c77f 100644 --- a/include/boost/geometry/formulas/distance_point_segment.hpp +++ b/include/boost/geometry/formulas/distance_point_segment.hpp @@ -25,26 +25,25 @@ template typename Inverse_type_distance, typename Direct_type > -class cross_track_geo_formula{ +class distance_point_segment{ public: + template CT static inline apply(CT lon1, CT lat1, //p1 CT lon2, CT lat2, //p2 - CT lon3, CT lat3) //query point p3 + CT lon3, CT lat3, //query point p3 + Spheroid const& spheroid, + CT earth_radius = + geometry::srs::sphere().get_radius<1>()) { int print = 0; // Constants - geometry::srs::spheroid spheroid; CT const f = flattening(spheroid); CT const pi = math::pi(); CT const half_pi = math::pi() / CT(2); - geometry::srs::sphere sphere; - CT const earth_radius = sphere.get_radius<1>(); - //CT const earth_radius = 6372795; - //CT const earth_radius = 6378137; // Convert to radians lon1 = math::as_radian(lon1); diff --git a/include/boost/geometry/strategies/geographic/distance_cross_track.hpp b/include/boost/geometry/strategies/geographic/distance_cross_track.hpp index b339f8f45..64009ee6a 100644 --- a/include/boost/geometry/strategies/geographic/distance_cross_track.hpp +++ b/include/boost/geometry/strategies/geographic/distance_cross_track.hpp @@ -49,18 +49,15 @@ namespace boost { namespace geometry namespace strategy { namespace distance { - /*! -\brief Strategy functor for distance point to segment calculation +\brief Strategy functor for distance point to segment calculation on ellipsoid \ingroup strategies -\details Class which calculates the distance of a point to a segment, for points on a sphere or globe -\see http://williams.best.vwh.net/avform.htm +\details Class which calculates the distance of a point to a segment, for points +on the ellipsoid +\see https://arxiv.org/abs/1102.1215 +\tparam FormulaPolicy underlying point-point distance strategy +\tparam Spheroid is the spheroidal model used \tparam CalculationType \tparam_calculation -\tparam Strategy underlying point-point distance strategy -\qbk{ -[heading See also] -[link geometry.reference.algorithms.distance.distance_3_with_strategy distance (with strategy)] -} */ template < @@ -84,21 +81,21 @@ public : > {}; - inline cross_track_geo() + struct distance_strategy + { + typedef geographic type; + }; + + inline typename distance_strategy::type get_distance_strategy() const + { + typedef typename distance_strategy::type distance_type; + return distance_type(m_spheroid); + } + + explicit cross_track_geo(Spheroid const& spheroid = Spheroid()) + : m_spheroid(spheroid) {} - typedef geographic - < - FormulaPolicy, Spheroid, CalculationType - > DistanceStrategy; - - /* - template - inline T comparable_to_distance(T& a) const - { - return a; - } -*/ template inline typename return_type::type apply(Point const& p, PointOfSegment const& sp1, PointOfSegment const& sp2) const @@ -136,7 +133,7 @@ public : false > direct_type; - return geometry::formula::cross_track_geo_formula + return geometry::formula::distance_point_segment < CT, units_type, @@ -145,14 +142,12 @@ public : direct_type >::apply(get<0>(sp1), get<1>(sp1), get<0>(sp2), get<1>(sp2), - get<0>(p), get<1>(p)); + get<0>(p), get<1>(p), + m_spheroid); } - //TODO: apply a more general strategy getter - inline DistanceStrategy get_distance_strategy() const - { - return DistanceStrategy(); - } +private : + Spheroid m_spheroid; }; @@ -278,32 +273,6 @@ public : } }; -/* -template -< - typename FormulaPolicy, - typename P, - typename PS -> -struct result_from_comparable - < - cross_track_geo, P, PS - > -{ -private : - typedef cross_track_geo strategy_type; -// typedef typename return_type::type return_type; -public : - template - static inline T apply(strategy_type const& strategy, - T const& comparable_distance) - { - //T c = T(2.0) * asin(math::sqrt(a)); - //return c * strategy.radius(); - return comparable_distance; - } -}; -*/ template struct default_strategy diff --git a/include/boost/geometry/strategies/geographic/intersection.hpp b/include/boost/geometry/strategies/geographic/intersection.hpp index 84acd149c..f4c2c1436 100644 --- a/include/boost/geometry/strategies/geographic/intersection.hpp +++ b/include/boost/geometry/strategies/geographic/intersection.hpp @@ -118,7 +118,6 @@ struct geographic_segments return strategy_type(m_spheroid); } - template struct distance_strategy { typedef distance::geographic @@ -129,10 +128,9 @@ struct geographic_segments > type; }; - template - inline typename distance_strategy::type get_distance_strategy() const + inline typename distance_strategy::type get_distance_strategy() const { - typedef typename distance_strategy::type strategy_type; + typedef typename distance_strategy::type strategy_type; return strategy_type(m_spheroid); } diff --git a/test/algorithms/distance/distance_geo_pl_l.cpp b/test/algorithms/distance/distance_geo_pl_l.cpp index f30665de8..83858f64d 100644 --- a/test/algorithms/distance/distance_geo_pl_l.cpp +++ b/test/algorithms/distance/distance_geo_pl_l.cpp @@ -44,13 +44,13 @@ typedef bg::strategy::distance::vincenty vincenty_pp; // Strategies for point-segment distance -typedef bg::strategy::distance::cross_track_geo +typedef bg::strategy::distance::cross_track_geo andoyer_strategy; -typedef bg::strategy::distance::cross_track_geo +typedef bg::strategy::distance::cross_track_geo thomas_strategy; -typedef bg::strategy::distance::cross_track_geo +typedef bg::strategy::distance::cross_track_geo vincenty_strategy; //=========================================================================== diff --git a/test/algorithms/distance/test_distance_geo_common.hpp b/test/algorithms/distance/test_distance_geo_common.hpp index 5a820dc90..1f831d447 100644 --- a/test/algorithms/distance/test_distance_geo_common.hpp +++ b/test/algorithms/distance/test_distance_geo_common.hpp @@ -1,4 +1,3 @@ - // Boost.Geometry (aka GGL, Generic Geometry Library) // Unit Test