Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76003 - in trunk: boost/geometry/algorithms libs/geometry/doc/src/docutils/tools/support_status
From: bruno.lalande_at_[hidden]
Date: 2011-12-16 18:16:23


Author: bruno.lalande
Date: 2011-12-16 18:16:22 EST (Fri, 16 Dec 2011)
New Revision: 76003
URL: http://svn.boost.org/trac/boost/changeset/76003

Log:
Had dispatch::distance take care of the default strategy retrieval/inversion.
Text files modified:
   trunk/boost/geometry/algorithms/distance.hpp | 86 +++++++++++++++++++++++++++------------
   trunk/libs/geometry/doc/src/docutils/tools/support_status/support_status.cpp | 11 ----
   2 files changed, 60 insertions(+), 37 deletions(-)

Modified: trunk/boost/geometry/algorithms/distance.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/distance.hpp (original)
+++ trunk/boost/geometry/algorithms/distance.hpp 2011-12-16 18:16:22 EST (Fri, 16 Dec 2011)
@@ -234,6 +234,18 @@
 };
 
 
+// Helper metafunction for default strategy retrieval
+template <typename Geometry1, typename Geometry2>
+struct default_strategy
+ : strategy::distance::services::default_strategy
+ <
+ point_tag,
+ typename point_type<Geometry1>::type,
+ typename point_type<Geometry2>::type
+ >
+{};
+
+
 }} // namespace detail::distance
 #endif // DOXYGEN_NO_DETAIL
 
@@ -242,12 +254,14 @@
 namespace dispatch
 {
 
+
 using strategy::distance::services::return_type;
 
 
 template
 <
- typename Geometry1, typename Geometry2, typename Strategy,
+ typename Geometry1, typename Geometry2,
+ typename Strategy = typename detail::distance::default_strategy<Geometry1, Geometry2>::type,
     typename Tag1 = typename tag_cast<typename tag<Geometry1>::type, multi_tag>::type,
     typename Tag2 = typename tag_cast<typename tag<Geometry2>::type, multi_tag>::type,
     typename StrategyTag = typename strategy::distance::services::tag<Strategy>::type,
@@ -280,7 +294,8 @@
     Geometry1, Geometry2, Strategy,
     Tag1, Tag2, StrategyTag,
     true
->: distance<Geometry2, Geometry1, Strategy, Tag2, Tag1, StrategyTag, false>
+>
+ : distance<Geometry2, Geometry1, Strategy, Tag2, Tag1, StrategyTag, false>
 {
     static inline typename return_type<Strategy>::type apply(
         Geometry1 const& g1,
@@ -296,6 +311,44 @@
     }
 };
 
+// If reversal is needed and we got the strategy by default, invert it before
+// proceeding to the reversal.
+template
+<
+ typename Geometry1, typename Geometry2,
+ typename Tag1, typename Tag2, typename StrategyTag
+>
+struct distance
+<
+ Geometry1, Geometry2,
+ typename detail::distance::default_strategy<Geometry1, Geometry2>::type,
+ Tag1, Tag2, StrategyTag,
+ true
+>
+ : distance
+ <
+ Geometry2, Geometry1,
+ typename detail::distance::default_strategy<Geometry2, Geometry1>::type,
+ Tag2, Tag1, StrategyTag,
+ false
+ >
+{
+ typedef typename detail::distance::default_strategy<Geometry2, Geometry1>::type Strategy;
+
+ static inline typename return_type<Strategy>::type apply(
+ Geometry1 const& g1,
+ Geometry2 const& g2,
+ Strategy const& strategy)
+ {
+ return distance
+ <
+ Geometry2, Geometry1, Strategy,
+ Tag2, Tag1, StrategyTag,
+ false
+ >::apply(g2, g1, strategy);
+ }
+};
+
 
 // Point-line version 1, where point-point strategy is specified
 template <typename Point, typename Linestring, typename Strategy>
@@ -491,8 +544,8 @@
 */
 template <typename Geometry1, typename Geometry2, typename Strategy>
 inline typename strategy::distance::services::return_type<Strategy>::type distance(
- Geometry1 const& geometry1,
- Geometry2 const& geometry2, Strategy const& strategy)
+ Geometry1 const& geometry1, Geometry2 const& geometry2,
+ Strategy const& strategy)
 {
     concept::check<Geometry1 const>();
     concept::check<Geometry2 const>();
@@ -525,29 +578,8 @@
     concept::check<Geometry1 const>();
     concept::check<Geometry2 const>();
 
- typedef typename point_type<Geometry1>::type point1_type;
- typedef typename point_type<Geometry2>::type point2_type;
-
- // Define a point-point-distance-strategy
- // for either the normal case, either the reversed case
- typedef typename boost::mpl::if_c
- <
- geometry::reverse_dispatch<Geometry1, Geometry2>::type::value,
- typename strategy::distance::services::default_strategy
- <
- point_tag,
- point2_type,
- point1_type
- >::type,
- typename strategy::distance::services::default_strategy
- <
- point_tag,
- point1_type,
- point2_type
- >::type
- >::type strategy;
-
- return distance(geometry1, geometry2, strategy());
+ return distance(geometry1, geometry2,
+ typename detail::distance::default_strategy<Geometry1, Geometry2>::type());
 }
 
 }} // namespace boost::geometry

Modified: trunk/libs/geometry/doc/src/docutils/tools/support_status/support_status.cpp
==============================================================================
--- trunk/libs/geometry/doc/src/docutils/tools/support_status/support_status.cpp (original)
+++ trunk/libs/geometry/doc/src/docutils/tools/support_status/support_status.cpp 2011-12-16 18:16:22 EST (Fri, 16 Dec 2011)
@@ -31,16 +31,7 @@
 
 
 template <typename G1, typename G2>
-struct check_distance
- : boost::geometry::dispatch::distance<
- G1,
- G2,
- typename boost::geometry::strategy::distance::services::default_strategy<
- boost::geometry::point_tag,
- G1,
- G2
- >::type
- >
+struct check_distance: boost::geometry::dispatch::distance<G1, G2>
 {};
 
 template <typename G1, typename G2>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk