Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77107 - in trunk: boost/geometry/algorithms boost/geometry/strategies/cartesian libs/geometry/doc libs/geometry/test/algorithms libs/geometry/test/strategies
From: barend.gehrels_at_[hidden]
Date: 2012-02-24 07:32:39


Author: barendgehrels
Date: 2012-02-24 07:32:38 EST (Fri, 24 Feb 2012)
New Revision: 77107
URL: http://svn.boost.org/trac/boost/changeset/77107

Log:
Boost.Geometry applied patch from ticket https://svn.boost.org/trac/boost/ticket/6584 and fixed a related bug about the return type of strategies/projected_point which was integer for integer points (and should have been promoted to FP, fixed)
Text files modified:
   trunk/boost/geometry/algorithms/distance.hpp | 2
   trunk/boost/geometry/strategies/cartesian/distance_projected_point.hpp | 22 +++++++-----
   trunk/libs/geometry/doc/release_notes.qbk | 3 +
   trunk/libs/geometry/test/algorithms/distance.cpp | 4 ++
   trunk/libs/geometry/test/strategies/projected_point.cpp | 71 ++++++++++++++++++++++++++++-----------
   5 files changed, 71 insertions(+), 31 deletions(-)

Modified: trunk/boost/geometry/algorithms/distance.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/distance.hpp (original)
+++ trunk/boost/geometry/algorithms/distance.hpp 2012-02-24 07:32:38 EST (Fri, 24 Feb 2012)
@@ -130,7 +130,7 @@
         // check if other segments are closer
         for (++prev, ++it; it != boost::end(view); ++prev, ++it)
         {
- return_type const ds = ps_strategy.apply(point, *prev, *it);
+ return_type const ds = eps_strategy.apply(point, *prev, *it);
             if (geometry::math::equals(ds, zero))
             {
                 return ds;

Modified: trunk/boost/geometry/strategies/cartesian/distance_projected_point.hpp
==============================================================================
--- trunk/boost/geometry/strategies/cartesian/distance_projected_point.hpp (original)
+++ trunk/boost/geometry/strategies/cartesian/distance_projected_point.hpp 2012-02-24 07:32:38 EST (Fri, 24 Feb 2012)
@@ -75,23 +75,27 @@
 class projected_point
 {
 public :
- typedef typename strategy::distance::services::return_type<Strategy>::type calculation_type;
-
-private :
-
     // The three typedefs below are necessary to calculate distances
     // from segments defined in integer coordinates.
 
     // Integer coordinates can still result in FP distances.
     // There is a division, which must be represented in FP.
     // So promote.
- typedef typename promote_floating_point<calculation_type>::type fp_type;
+ typedef typename promote_floating_point
+ <
+ typename strategy::distance::services::return_type
+ <
+ Strategy
+ >::type
+ >::type calculation_type;
+
+private :
 
     // A projected point of points in Integer coordinates must be able to be
     // represented in FP.
     typedef model::point
         <
- fp_type,
+ calculation_type,
             dimension<PointOfSegment>::value,
             typename coordinate_system<PointOfSegment>::type
> fp_point_type;
@@ -139,19 +143,19 @@
         boost::ignore_unused_variable_warning(strategy);
 
         calculation_type const zero = calculation_type();
- fp_type const c1 = dot_product(w, v);
+ calculation_type const c1 = dot_product(w, v);
         if (c1 <= zero)
         {
             return strategy.apply(p, p1);
         }
- fp_type const c2 = dot_product(v, v);
+ calculation_type const c2 = dot_product(v, v);
         if (c2 <= c1)
         {
             return strategy.apply(p, p2);
         }
 
         // See above, c1 > 0 AND c2 > c1 so: c2 != 0
- fp_type const b = c1 / c2;
+ calculation_type const b = c1 / c2;
 
         fp_strategy_type fp_strategy
             = strategy::distance::services::get_similar

Modified: trunk/libs/geometry/doc/release_notes.qbk
==============================================================================
--- trunk/libs/geometry/doc/release_notes.qbk (original)
+++ trunk/libs/geometry/doc/release_notes.qbk 2012-02-24 07:32:38 EST (Fri, 24 Feb 2012)
@@ -19,10 +19,13 @@
 [*Breaking changes]
 
 [*Bugfixes]
+* the return type of comparable projected point strategy for integer points was wrong (integer), fixed
 
 [*Solved tickets]
 
 * [@https://svn.boost.org/trac/boost/ticket/6585 6585] patch for alternative syntax multipoint, applied
+* [@https://svn.boost.org/trac/boost/ticket/6584 6584] patch for bug in distance, applied
+
 
 [*Additional functionality]
 

Modified: trunk/libs/geometry/test/algorithms/distance.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/distance.cpp (original)
+++ trunk/libs/geometry/test/algorithms/distance.cpp 2012-02-24 07:32:38 EST (Fri, 24 Feb 2012)
@@ -194,7 +194,11 @@
     test_geometry<P, P>("POINT(0 3)", "POINT(4 0)", 5.0);
     test_geometry<P, bg::model::linestring<P> >("POINT(1 3)", "LINESTRING(1 1,4 4)", sqrt(2.0));
     test_geometry<P, bg::model::linestring<P> >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0));
+ test_geometry<P, bg::model::linestring<P> >("POINT(50 50)", "LINESTRING(50 40, 40 50)", sqrt(50.0));
+ test_geometry<P, bg::model::linestring<P> >("POINT(50 50)", "LINESTRING(50 40, 40 50, 0 90)", sqrt(50.0));
     test_geometry<bg::model::linestring<P>, P>("LINESTRING(1 1,4 4)", "POINT(1 3)", sqrt(2.0));
+ test_geometry<bg::model::linestring<P>, P>("LINESTRING(50 40, 40 50)", "POINT(50 50)", sqrt(50.0));
+ test_geometry<bg::model::linestring<P>, P>("LINESTRING(50 40, 40 50, 0 90)", "POINT(50 50)", sqrt(50.0));
 
     // Rings
     test_geometry<P, bg::model::ring<P> >("POINT(1 3)", "POLYGON((1 1,4 4,5 0,1 1))", sqrt(2.0));

Modified: trunk/libs/geometry/test/strategies/projected_point.cpp
==============================================================================
--- trunk/libs/geometry/test/strategies/projected_point.cpp (original)
+++ trunk/libs/geometry/test/strategies/projected_point.cpp 2012-02-24 07:32:38 EST (Fri, 24 Feb 2012)
@@ -87,33 +87,62 @@
 }
 
 
-template <typename P1, typename P2>
-void test_all_2d()
+template <typename P1, typename P2, typename T>
+void test_all_2d(std::string const& wkt_p,
+ std::string const& wkt_sp1,
+ std::string const& wkt_sp2,
+ T expected_distance)
 {
     P1 p;
     P2 sp1, sp2;
- bg::read_wkt("POINT(1 1)", p);
- bg::read_wkt("POINT(0 0)", sp1);
- bg::read_wkt("POINT(2 3)", sp2);
-
- typedef typename bg::strategy::distance::projected_point
- <
- P1,
- P2
- > strategy_type;
-
- BOOST_CONCEPT_ASSERT
- (
- (bg::concept::PointSegmentDistanceStrategy<strategy_type>)
- );
-
+ bg::read_wkt(wkt_p, p);
+ bg::read_wkt(wkt_sp1, sp1);
+ bg::read_wkt(wkt_sp2, sp2);
+
+ {
+ typedef bg::strategy::distance::projected_point
+ <
+ P1,
+ P2
+ > strategy_type;
+
+ BOOST_CONCEPT_ASSERT
+ (
+ (bg::concept::PointSegmentDistanceStrategy<strategy_type>)
+ );
+
+ strategy_type strategy;
+ typedef typename bg::strategy::distance::services::return_type<strategy_type>::type return_type;
+ return_type d = strategy.apply(p, sp1, sp2);
+ BOOST_CHECK_CLOSE(d, expected_distance, 0.001);
+ }
+
+ // Test combination with the comparable strategy
+ {
+ typedef bg::strategy::distance::projected_point
+ <
+ P1,
+ P2,
+ void,
+ bg::strategy::distance::comparable::pythagoras<P1, P2>
+ > strategy_type;
+ strategy_type strategy;
+ typedef typename bg::strategy::distance::services::return_type<strategy_type>::type return_type;
+ return_type d = strategy.apply(p, sp1, sp2);
+ T expected_squared_distance = expected_distance * expected_distance;
+ BOOST_CHECK_CLOSE(d, expected_squared_distance, 0.01);
+ }
 
- strategy_type strategy;
- typedef typename bg::strategy::distance::services::return_type<strategy_type>::type return_type;
- return_type d = strategy.apply(p, sp1, sp2);
- BOOST_CHECK_CLOSE(d, return_type(0.27735203958327), 0.001);
 }
 
+template <typename P1, typename P2>
+void test_all_2d()
+{
+ test_all_2d<P1, P2>("POINT(1 1)", "POINT(0 0)", "POINT(2 3)", 0.27735203958327);
+ test_all_2d<P1, P2>("POINT(2 2)", "POINT(1 4)", "POINT(4 1)", 0.5 * sqrt(2.0));
+ test_all_2d<P1, P2>("POINT(6 1)", "POINT(1 4)", "POINT(4 1)", 2.0);
+ test_all_2d<P1, P2>("POINT(1 6)", "POINT(1 4)", "POINT(4 1)", 2.0);
+}
 
 template <typename P>
 void test_all_2d()


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