$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r64414 - in sandbox/geometry: boost/geometry/algorithms libs/geometry/test/algorithms
From: barend.gehrels_at_[hidden]
Date: 2010-07-28 14:07:07
Author: barendgehrels
Date: 2010-07-28 14:07:06 EDT (Wed, 28 Jul 2010)
New Revision: 64414
URL: http://svn.boost.org/trac/boost/changeset/64414
Log:
Added point-ring distance plus testcase
Text files modified: 
   sandbox/geometry/boost/geometry/algorithms/distance.hpp     |    52 ++++++++++++++++++++++++++++++++++++--- 
   sandbox/geometry/libs/geometry/test/algorithms/distance.cpp |     6 ++++                                    
   2 files changed, 53 insertions(+), 5 deletions(-)
Modified: sandbox/geometry/boost/geometry/algorithms/distance.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/algorithms/distance.hpp	(original)
+++ sandbox/geometry/boost/geometry/algorithms/distance.hpp	2010-07-28 14:07:06 EDT (Wed, 28 Jul 2010)
@@ -15,6 +15,8 @@
 
 #include <boost/static_assert.hpp>
 
+#include <boost/mpl/assert.hpp>
+
 #include <boost/geometry/core/cs.hpp>
 #include <boost/geometry/core/is_multi.hpp>
 #include <boost/geometry/core/reverse_dispatch.hpp>
@@ -249,12 +251,18 @@
 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<Geometry1, Geometry2>)
+        );
+};
 
 
 template <typename P1, typename P2, typename Strategy>
@@ -267,7 +275,7 @@
 > : detail::distance::point_to_point<P1, P2, Strategy>
 {};
 
-/// Point-line version 1, where point-point strategy is specified
+// Point-line version 1, where point-point strategy is specified
 template <typename Point, typename Linestring, typename Strategy>
 struct distance
 <
@@ -297,7 +305,7 @@
 };
 
 
-/// Point-line version 2, where point-segment strategy is specified
+// Point-line version 2, where point-segment strategy is specified
 template <typename Point, typename Linestring, typename Strategy>
 struct distance
 <
@@ -319,7 +327,41 @@
     }
 };
 
-/// Point-polygon , where point-segment strategy is specified
+// Point-ring , where point-segment strategy is specified
+template <typename Point, typename Ring, typename Strategy>
+struct distance
+<
+    point_tag, ring_tag,
+    Point, Ring,
+    strategy_tag_distance_point_point, Strategy,
+    false, false
+>
+{
+    typedef typename return_type<Strategy>::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<Ring>::type
+            >::type ps_strategy_type;
+
+        std::pair<return_type, bool>
+            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 <typename Point, typename Polygon, typename Strategy>
 struct distance
 <
Modified: sandbox/geometry/libs/geometry/test/algorithms/distance.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/algorithms/distance.cpp	(original)
+++ sandbox/geometry/libs/geometry/test/algorithms/distance.cpp	2010-07-28 14:07:06 EDT (Wed, 28 Jul 2010)
@@ -179,6 +179,12 @@
     test_geometry<P, bg::linestring<P> >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0));
     test_geometry<bg::linestring<P>, P>("LINESTRING(1 1,4 4)", "POINT(1 3)", sqrt(2.0));
 
+
+    test_geometry<P, bg::linear_ring<P> >("POINT(1 3)", "POLYGON((1 1,4 4,5 0,1 1))", sqrt(2.0));
+    test_geometry<P, bg::linear_ring<P> >("POINT(3 1)", "POLYGON((1 1,4 4,5 0,1 1))", 0.0);
+    // other way round
+    test_geometry<bg::linear_ring<P>, 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<P, boost::array<P, 2> >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0));