From 718f431b2aa4ad0a6e350e9b1436dcdc2883acce Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 28 Jul 2010 18:07:06 +0000 Subject: [PATCH] Added point-ring distance plus testcase [SVN r64414] --- .../boost/geometry/algorithms/distance.hpp | 52 +++++++++++++++++-- test/algorithms/distance.cpp | 6 +++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/include/boost/geometry/algorithms/distance.hpp b/include/boost/geometry/algorithms/distance.hpp index 45e86eff9..0784065a9 100644 --- a/include/boost/geometry/algorithms/distance.hpp +++ b/include/boost/geometry/algorithms/distance.hpp @@ -15,6 +15,8 @@ #include +#include + #include #include #include @@ -249,12 +251,18 @@ using strategy::distance::services::return_type; template < typename GeometryTag1, typename GeometryTag2, - typename G1, typename G2, + typename Geometry1, typename Geometry2, typename StrategyTag, typename Strategy, bool IsMulti1, bool IsMulti2 > struct distance -{}; +{ + BOOST_MPL_ASSERT_MSG + ( + false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE + , (types) + ); +}; template @@ -267,7 +275,7 @@ struct distance > : detail::distance::point_to_point {}; -/// Point-line version 1, where point-point strategy is specified +// Point-line version 1, where point-point strategy is specified template struct distance < @@ -297,7 +305,7 @@ struct distance }; -/// Point-line version 2, where point-segment strategy is specified +// Point-line version 2, where point-segment strategy is specified template struct distance < @@ -319,7 +327,41 @@ struct distance } }; -/// Point-polygon , where point-segment strategy is specified +// Point-ring , where point-segment strategy is specified +template +struct distance +< + point_tag, ring_tag, + Point, Ring, + strategy_tag_distance_point_point, Strategy, + false, false +> +{ + typedef typename return_type::type return_type; + + static inline return_type apply(Point const& point, + Ring const& ring, + Strategy const& strategy) + { + typedef typename strategy::distance::services::default_strategy + < + segment_tag, + Point, + typename point_type::type + >::type ps_strategy_type; + + std::pair + dc = detail::distance::point_to_ring + < + Point, Ring, Strategy, ps_strategy_type + >::apply(point, ring, strategy, ps_strategy_type()); + + return dc.second ? return_type(0) : dc.first; + } +}; + + +// Point-polygon , where point-segment strategy is specified template struct distance < diff --git a/test/algorithms/distance.cpp b/test/algorithms/distance.cpp index ac2fdbdcc..18b7a5357 100644 --- a/test/algorithms/distance.cpp +++ b/test/algorithms/distance.cpp @@ -179,6 +179,12 @@ void test_all() test_geometry >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0)); test_geometry, P>("LINESTRING(1 1,4 4)", "POINT(1 3)", sqrt(2.0)); + + test_geometry >("POINT(1 3)", "POLYGON((1 1,4 4,5 0,1 1))", sqrt(2.0)); + test_geometry >("POINT(3 1)", "POLYGON((1 1,4 4,5 0,1 1))", 0.0); + // other way round + test_geometry, P>("POLYGON((1 1,4 4,5 0,1 1))", "POINT(3 1)", 0.0); + // This one COMPILES but should THROW - because boost::array is not variably sized //test_geometry >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0));