Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79757 - in trunk: boost/geometry/strategies/cartesian libs/geometry/test/algorithms
From: barend.gehrels_at_[hidden]
Date: 2012-07-26 12:16:44


Author: barendgehrels
Date: 2012-07-26 12:16:43 EDT (Thu, 26 Jul 2012)
New Revision: 79757
URL: http://svn.boost.org/trac/boost/changeset/79757

Log:
[geometry] Applied (slightly adapted) patch by Karsten Ahnert sent to me Jul 25, fixing disjoint for degenerate segments
Text files modified:
   trunk/boost/geometry/strategies/cartesian/cart_intersect.hpp | 26 +++++++++++++++++++++-----
   trunk/libs/geometry/test/algorithms/disjoint.cpp | 6 ++++++
   2 files changed, 27 insertions(+), 5 deletions(-)

Modified: trunk/boost/geometry/strategies/cartesian/cart_intersect.hpp
==============================================================================
--- trunk/boost/geometry/strategies/cartesian/cart_intersect.hpp (original)
+++ trunk/boost/geometry/strategies/cartesian/cart_intersect.hpp 2012-07-26 12:16:43 EDT (Thu, 26 Jul 2012)
@@ -120,6 +120,22 @@
         typedef side::side_by_triangle<coordinate_type> side;
         side_info sides;
 
+ coordinate_type const zero = 0;
+ bool const a_is_point = math::equals(dx_a, zero) && math::equals(dy_a, zero);
+ bool const b_is_point = math::equals(dx_b, zero) && math::equals(dy_b, zero);
+
+ if(a_is_point && b_is_point)
+ {
+ if(math::equals(get<1,0>(a), get<1,0>(b)) && math::equals(get<1,1>(a), get<1,1>(b)))
+ {
+ Policy::degenerate(a, true);
+ }
+ else
+ {
+ return Policy::disjoint();
+ }
+ }
+
         bool collinear_use_first = math::abs(dx_a) + math::abs(dx_b) >= math::abs(dy_a) + math::abs(dy_b);
 
         sides.set<0>
@@ -143,7 +159,7 @@
 
         bool collinear = sides.collinear();
 
- robustness_verify_collinear(a, b, sides, collinear);
+ robustness_verify_collinear(a, b, a_is_point, b_is_point, sides, collinear);
         robustness_verify_meeting(a, b, sides, collinear, collinear_use_first);
 
         if (sides.same<0>() || sides.same<1>())
@@ -156,12 +172,11 @@
         }
 
         // Degenerate cases: segments of single point, lying on other segment, non disjoint
- coordinate_type const zero = 0;
- if (math::equals(dx_a, zero) && math::equals(dy_a, zero))
+ if (a_is_point)
         {
             return Policy::degenerate(a, true);
         }
- if (math::equals(dx_b, zero) && math::equals(dy_b, zero))
+ if (b_is_point)
         {
             return Policy::degenerate(b, false);
         }
@@ -281,10 +296,11 @@
 
     static inline void robustness_verify_collinear(
                 segment_type1 const& a, segment_type2 const& b,
+ bool a_is_point, bool b_is_point,
                 side_info& sides,
                 bool& collinear)
     {
- if ((sides.zero<0>() && ! sides.zero<1>()) || (sides.zero<1>() && ! sides.zero<0>()))
+ if ((sides.zero<0>() && ! b_is_point && ! sides.zero<1>()) || (sides.zero<1>() && ! a_is_point && ! sides.zero<0>()))
         {
             // If one of the segments is collinear, the other must be as well.
             // So handle it as collinear.

Modified: trunk/libs/geometry/test/algorithms/disjoint.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/disjoint.cpp (original)
+++ trunk/libs/geometry/test/algorithms/disjoint.cpp 2012-07-26 12:16:43 EDT (Thu, 26 Jul 2012)
@@ -113,6 +113,12 @@
     test_disjoint<segment, segment>("s/s 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
     test_disjoint<segment, segment>("s/s 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
 
+ // Test degenerate segments (patched by Karsten Ahnert on 2012-07-25)
+ test_disjoint<segment, segment>("s/s 3", "linestring(0 0,0 0)", "linestring(1 0,0 1)", true);
+ test_disjoint<segment, segment>("s/s 4", "linestring(0 0,0 0)", "linestring(0 0,0 0)", false);
+ test_disjoint<segment, segment>("s/s 5", "linestring(0 0,0 0)", "linestring(1 0,1 0)", true);
+ test_disjoint<segment, segment>("s/s 6", "linestring(0 0,0 0)", "linestring(0 1,0 1)", true);
+
     // Collinear opposite
     test_disjoint<ls, ls>("ls/ls co", "linestring(0 0,2 2)", "linestring(1 1,0 0)", false);
     // Collinear opposite and equal


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