Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78346 - in trunk: boost/polygon libs/polygon/test
From: sydorchuk.andriy_at_[hidden]
Date: 2012-05-06 08:25:01


Author: asydorchuk
Date: 2012-05-06 08:24:59 EDT (Sun, 06 May 2012)
New Revision: 78346
URL: http://svn.boost.org/trac/boost/changeset/78346

Log:
Polygon: Fixed segment concept intersects method. Updating tests. Fixing test targets failing on trunk.

Text files modified:
   trunk/boost/polygon/polygon.hpp | 2
   trunk/boost/polygon/polygon_90_set_data.hpp | 84 ++++++++++++++++++++--------------------
   trunk/boost/polygon/polygon_90_set_traits.hpp | 2
   trunk/boost/polygon/segment_concept.hpp | 79 +++++++++++++++++++------------------
   trunk/libs/polygon/test/polygon_segment_test.cpp | 64 ++++++++++++++++++++++-------
   5 files changed, 133 insertions(+), 98 deletions(-)

Modified: trunk/boost/polygon/polygon.hpp
==============================================================================
--- trunk/boost/polygon/polygon.hpp (original)
+++ trunk/boost/polygon/polygon.hpp 2012-05-06 08:24:59 EDT (Sun, 06 May 2012)
@@ -1,6 +1,6 @@
 /*
   Copyright 2008 Intel Corporation
-
+
   Use, modification and distribution are subject to the Boost Software License,
   Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
   http://www.boost.org/LICENSE_1_0.txt).

Modified: trunk/boost/polygon/polygon_90_set_data.hpp
==============================================================================
--- trunk/boost/polygon/polygon_90_set_data.hpp (original)
+++ trunk/boost/polygon/polygon_90_set_data.hpp 2012-05-06 08:24:59 EDT (Sun, 06 May 2012)
@@ -1,6 +1,6 @@
 /*
   Copyright 2008 Intel Corporation
-
+
   Use, modification and distribution are subject to the Boost Software License,
   Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
   http://www.boost.org/LICENSE_1_0.txt).
@@ -13,6 +13,7 @@
 #include "transform.hpp"
 #include "interval_concept.hpp"
 #include "rectangle_concept.hpp"
+#include "segment_concept.hpp"
 #include "detail/iterator_points_to_compact.hpp"
 #include "detail/iterator_compact_to_points.hpp"
 #include "polygon_traits.hpp"
@@ -46,7 +47,7 @@
 
     // constructor from an iterator pair over vertex data
     template <typename iT>
- inline polygon_90_set_data(orientation_2d orient, iT input_begin, iT input_end) :
+ inline polygon_90_set_data(orientation_2d orient, iT input_begin, iT input_end) :
       orient_(HORIZONTAL), data_(), dirty_(false), unsorted_(false) {
       dirty_ = true;
       unsorted_ = true;
@@ -54,14 +55,14 @@
     }
 
     // copy constructor
- inline polygon_90_set_data(const polygon_90_set_data& that) :
+ inline polygon_90_set_data(const polygon_90_set_data& that) :
       orient_(that.orient_), data_(that.data_), dirty_(that.dirty_), unsorted_(that.unsorted_) {}
 
     template <typename ltype, typename rtype, typename op_type>
     inline polygon_90_set_data(const polygon_90_set_view<ltype, rtype, op_type>& that);
 
     // copy with orientation change constructor
- inline polygon_90_set_data(orientation_2d orient, const polygon_90_set_data& that) :
+ inline polygon_90_set_data(orientation_2d orient, const polygon_90_set_data& that) :
       orient_(orient), data_(), dirty_(false), unsorted_(false) {
       insert(that, false, that.orient_);
     }
@@ -138,7 +139,7 @@
       insert(begin_input, end_input, orient_);
     }
 
- inline void insert(const std::pair<coordinate_type, std::pair<coordinate_type, int> >& vertex, bool is_hole = false,
+ inline void insert(const std::pair<coordinate_type, std::pair<coordinate_type, int> >& vertex, bool is_hole = false,
                        orientation_2d orient = HORIZONTAL) {
       data_.push_back(vertex);
       if(orient != orient_) std::swap(data_.back().first, data_.back().second.first);
@@ -190,7 +191,7 @@
       }
     }
 
- // equivalence operator
+ // equivalence operator
     inline bool operator==(const polygon_90_set_data& p) const {
       if(orient_ == p.orient()) {
         clean();
@@ -201,7 +202,7 @@
       }
     }
 
- // inequivalence operator
+ // inequivalence operator
     inline bool operator!=(const polygon_90_set_data& p) const {
       return !((*this) == p);
     }
@@ -260,7 +261,7 @@
     // value_type data;
     // std::swap(data, data_);
     // applyBooleanBinaryOp(data.begin(), data.end(),
- // that.begin(), that.end(), boolean_op::BinaryCount<boolean_op::BinaryNot>());
+ // that.begin(), that.end(), boolean_op::BinaryCount<boolean_op::BinaryNot>());
     // return *this;
     // }
     // polygon_90_set_data<coordinate_type>& operator^=(const polygon_90_set_data& that) {
@@ -269,7 +270,7 @@
     // value_type data;
     // std::swap(data, data_);
     // applyBooleanBinaryOp(data.begin(), data.end(),
- // that.begin(), that.end(), boolean_op::BinaryCount<boolean_op::BinaryXor>());
+ // that.begin(), that.end(), boolean_op::BinaryCount<boolean_op::BinaryXor>());
     // return *this;
     // }
     // polygon_90_set_data<coordinate_type>& operator&=(const polygon_90_set_data& that) {
@@ -278,7 +279,7 @@
     // value_type data;
     // std::swap(data, data_);
     // applyBooleanBinaryOp(data.begin(), data.end(),
- // that.begin(), that.end(), boolean_op::BinaryCount<boolean_op::BinaryAnd>());
+ // that.begin(), that.end(), boolean_op::BinaryCount<boolean_op::BinaryAnd>());
     // return *this;
     // }
     // polygon_90_set_data<coordinate_type>& operator|=(const polygon_90_set_data& that) {
@@ -312,7 +313,7 @@
     }
 
     void set(const value_type& value, orientation_2d orient) {
- data_ = value;
+ data_ = value;
       orient_ = orient;
       dirty_ = true;
       unsorted_ = true;
@@ -346,11 +347,11 @@
           typename coordinate_traits<coordinate_type>::unsigned_area_type north_bloating) {
       std::vector<rectangle_data<coordinate_type> > rects;
       clean();
- rects.reserve(data_.size() / 2);
+ rects.reserve(data_.size() / 2);
       get(rects);
- rectangle_data<coordinate_type> convolutionRectangle(interval_data<coordinate_type>(-((coordinate_type)west_bloating),
+ rectangle_data<coordinate_type> convolutionRectangle(interval_data<coordinate_type>(-((coordinate_type)west_bloating),
                                                                                           (coordinate_type)east_bloating),
- interval_data<coordinate_type>(-((coordinate_type)south_bloating),
+ interval_data<coordinate_type>(-((coordinate_type)south_bloating),
                                                                                           (coordinate_type)north_bloating));
       for(typename std::vector<rectangle_data<coordinate_type> >::iterator itr = rects.begin();
           itr != rects.end(); ++itr) {
@@ -393,7 +394,7 @@
       if(nyg)
         pt.x(current_pt.x() + east_bloating);
     }
- static void resize_poly_up(std::vector<point_data<coordinate_type> >& poly,
+ static void resize_poly_up(std::vector<point_data<coordinate_type> >& poly,
                                coordinate_type west_bloating,
                                coordinate_type east_bloating,
                                coordinate_type south_bloating,
@@ -416,7 +417,7 @@
       modify_pt(poly[0], prev_pt, current_pt, next_pt, west_bloating, east_bloating, south_bloating, north_bloating);
       remove_colinear_pts(poly);
     }
- static bool resize_poly_down(std::vector<point_data<coordinate_type> >& poly,
+ static bool resize_poly_down(std::vector<point_data<coordinate_type> >& poly,
                                  coordinate_type west_shrinking,
                                  coordinate_type east_shrinking,
                                  coordinate_type south_shrinking,
@@ -452,7 +453,7 @@
       bool found_colinear = true;
       while(found_colinear && poly.size() >= 4) {
         found_colinear = false;
- typename std::vector<point_data<coordinate_type> >::iterator itr = poly.begin();
+ typename std::vector<point_data<coordinate_type> >::iterator itr = poly.begin();
         itr += poly.size() - 1; //get last element position
         typename std::vector<point_data<coordinate_type> >::iterator itr2 = poly.begin();
         typename std::vector<point_data<coordinate_type> >::iterator itr3 = itr2;
@@ -478,7 +479,7 @@
         poly.erase(poly.end() - count, poly.end());
       }
       return poly.size() >= 4;
- }
+ }
 
     polygon_90_set_data&
     bloat(typename coordinate_traits<coordinate_type>::unsigned_area_type west_bloating,
@@ -496,7 +497,7 @@
         //psref.extents(prerect);
         resize_poly_up((*itr).self_.coords_, west_bloating, east_bloating, south_bloating, north_bloating);
         iterator_geometry_to_set<polygon_90_concept, view_of<polygon_90_concept, polygon_45_data<coordinate_type> > >
- begin_input(view_as<polygon_90_concept>((*itr).self_), LOW, orient_, false, true, COUNTERCLOCKWISE),
+ begin_input(view_as<polygon_90_concept>((*itr).self_), LOW, orient_, false, true, COUNTERCLOCKWISE),
           end_input(view_as<polygon_90_concept>((*itr).self_), HIGH, orient_, false, true, COUNTERCLOCKWISE);
         insert(begin_input, end_input, orient_);
         //polygon_90_set_data<coordinate_type> pstest;
@@ -515,13 +516,13 @@
           //polygon_45_data<coordinate_type> testpoly(*itrh);
           if(resize_poly_down((*itrh).coords_, west_bloating, east_bloating, south_bloating, north_bloating)) {
             iterator_geometry_to_set<polygon_90_concept, view_of<polygon_90_concept, polygon_45_data<coordinate_type> > >
- begin_input2(view_as<polygon_90_concept>(*itrh), LOW, orient_, true, true),
+ begin_input2(view_as<polygon_90_concept>(*itrh), LOW, orient_, true, true),
               end_input2(view_as<polygon_90_concept>(*itrh), HIGH, orient_, true, true);
             insert(begin_input2, end_input2, orient_);
             //polygon_90_set_data<coordinate_type> pstesthole;
             //pstesthole.insert(rect);
             //iterator_geometry_to_set<polygon_90_concept, view_of<polygon_90_concept, polygon_45_data<coordinate_type> > >
- // begin_input2(view_as<polygon_90_concept>(*itrh), LOW, orient_, true, true);
+ // begin_input2(view_as<polygon_90_concept>(*itrh), LOW, orient_, true, true);
             //pstesthole.insert(begin_input2, end_input, orient_);
             //psrefhole.bloat2(west_bloating, east_bloating, south_bloating, north_bloating);
             //if(!equivalence(psrefhole, pstesthole)) {
@@ -559,11 +560,11 @@
         //polygon_45_data<coordinate_type> testpoly((*itr).self_);
         if(resize_poly_down((*itr).self_.coords_, -west_shrinking, -east_shrinking, -south_shrinking, -north_shrinking)) {
           iterator_geometry_to_set<polygon_90_concept, view_of<polygon_90_concept, polygon_45_data<coordinate_type> > >
- begin_input(view_as<polygon_90_concept>((*itr).self_), LOW, orient_, false, true, COUNTERCLOCKWISE),
+ begin_input(view_as<polygon_90_concept>((*itr).self_), LOW, orient_, false, true, COUNTERCLOCKWISE),
             end_input(view_as<polygon_90_concept>((*itr).self_), HIGH, orient_, false, true, COUNTERCLOCKWISE);
           insert(begin_input, end_input, orient_);
           //iterator_geometry_to_set<polygon_90_concept, view_of<polygon_90_concept, polygon_45_data<coordinate_type> > >
- // begin_input2(view_as<polygon_90_concept>((*itr).self_), LOW, orient_, false, true, COUNTERCLOCKWISE);
+ // begin_input2(view_as<polygon_90_concept>((*itr).self_), LOW, orient_, false, true, COUNTERCLOCKWISE);
           //polygon_90_set_data<coordinate_type> pstest;
           //pstest.insert(begin_input2, end_input, orient_);
           //psref.shrink2(west_shrinking, east_shrinking, south_shrinking, north_shrinking);
@@ -580,13 +581,13 @@
             //polygon_45_data<coordinate_type> testpoly(*itrh);
             resize_poly_up((*itrh).coords_, -west_shrinking, -east_shrinking, -south_shrinking, -north_shrinking);
             iterator_geometry_to_set<polygon_90_concept, view_of<polygon_90_concept, polygon_45_data<coordinate_type> > >
- begin_input2(view_as<polygon_90_concept>(*itrh), LOW, orient_, true, true),
+ begin_input2(view_as<polygon_90_concept>(*itrh), LOW, orient_, true, true),
               end_input2(view_as<polygon_90_concept>(*itrh), HIGH, orient_, true, true);
             insert(begin_input2, end_input2, orient_);
             //polygon_90_set_data<coordinate_type> pstesthole;
             //pstesthole.insert(rect);
             //iterator_geometry_to_set<polygon_90_concept, view_of<polygon_90_concept, polygon_45_data<coordinate_type> > >
- // begin_input2(view_as<polygon_90_concept>(*itrh), LOW, orient_, true, true);
+ // begin_input2(view_as<polygon_90_concept>(*itrh), LOW, orient_, true, true);
             //pstesthole.insert(begin_input2, end_input, orient_);
             //psrefhole.shrink2(west_shrinking, east_shrinking, south_shrinking, north_shrinking);
             //if(!equivalence(psrefhole, pstesthole)) {
@@ -619,13 +620,13 @@
       insert(externalBoundary, true); //note that the set is in a dirty state now
       sort(); //does not apply implicit OR operation
       std::vector<rectangle_data<coordinate_type> > rects;
- rects.reserve(data_.size() / 2);
+ rects.reserve(data_.size() / 2);
       //begin does not apply implicit or operation, this is a dirty range
       form_rectangles(rects, data_.begin(), data_.end(), orient_, rectangle_concept());
       clear();
- rectangle_data<coordinate_type> convolutionRectangle(interval_data<coordinate_type>(-((coordinate_type)east_shrinking),
+ rectangle_data<coordinate_type> convolutionRectangle(interval_data<coordinate_type>(-((coordinate_type)east_shrinking),
                                                                                           (coordinate_type)west_shrinking),
- interval_data<coordinate_type>(-((coordinate_type)north_shrinking),
+ interval_data<coordinate_type>(-((coordinate_type)north_shrinking),
                                                                                           (coordinate_type)south_shrinking));
       for(typename std::vector<rectangle_data<coordinate_type> >::iterator itr = rects.begin();
           itr != rects.end(); ++itr) {
@@ -664,10 +665,10 @@
     }
 
     polygon_90_set_data&
- resize(coordinate_type west, coordinate_type east, coordinate_type south, coordinate_type north);
+ resize(coordinate_type west, coordinate_type east, coordinate_type south, coordinate_type north);
 
     polygon_90_set_data& move(coordinate_type x_delta, coordinate_type y_delta) {
- for(typename std::vector<std::pair<coordinate_type, std::pair<coordinate_type, int> > >::iterator
+ for(typename std::vector<std::pair<coordinate_type, std::pair<coordinate_type, int> > >::iterator
             itr = data_.begin(); itr != data_.end(); ++itr) {
         if(orient_ == orientation_2d(VERTICAL)) {
           (*itr).first += x_delta;
@@ -702,7 +703,7 @@
 
     // scale set
     polygon_90_set_data& scale_up(typename coordinate_traits<coordinate_type>::unsigned_area_type factor) {
- for(typename std::vector<std::pair<coordinate_type, std::pair<coordinate_type, int> > >::iterator
+ for(typename std::vector<std::pair<coordinate_type, std::pair<coordinate_type, int> > >::iterator
             itr = data_.begin(); itr != data_.end(); ++itr) {
         (*itr).first *= (coordinate_type)factor;
         (*itr).second.first *= (coordinate_type)factor;
@@ -711,7 +712,7 @@
     }
     polygon_90_set_data& scale_down(typename coordinate_traits<coordinate_type>::unsigned_area_type factor) {
       typedef typename coordinate_traits<coordinate_type>::coordinate_distance dt;
- for(typename std::vector<std::pair<coordinate_type, std::pair<coordinate_type, int> > >::iterator
+ for(typename std::vector<std::pair<coordinate_type, std::pair<coordinate_type, int> > >::iterator
             itr = data_.begin(); itr != data_.end(); ++itr) {
         (*itr).first = scaling_policy<coordinate_type>::round((dt)((*itr).first) / (dt)factor);
         (*itr).second.first = scaling_policy<coordinate_type>::round((dt)((*itr).second.first) / (dt)factor);
@@ -721,7 +722,7 @@
     }
     template <typename scaling_type>
     polygon_90_set_data& scale(const anisotropic_scale_factor<scaling_type>& scaling) {
- for(typename std::vector<std::pair<coordinate_type, std::pair<coordinate_type, int> > >::iterator
+ for(typename std::vector<std::pair<coordinate_type, std::pair<coordinate_type, int> > >::iterator
             itr = data_.begin(); itr != data_.end(); ++itr) {
         if(orient_ == orientation_2d(VERTICAL)) {
           scaling.scale((*itr).first, (*itr).second.first);
@@ -734,7 +735,7 @@
     }
     template <typename scaling_type>
     polygon_90_set_data& scale_with(const scaling_type& scaling) {
- for(typename std::vector<std::pair<coordinate_type, std::pair<coordinate_type, int> > >::iterator
+ for(typename std::vector<std::pair<coordinate_type, std::pair<coordinate_type, int> > >::iterator
             itr = data_.begin(); itr != data_.end(); ++itr) {
         if(orient_ == orientation_2d(VERTICAL)) {
           scaling.scale((*itr).first, (*itr).second.first);
@@ -747,7 +748,7 @@
     }
     polygon_90_set_data& scale(double factor) {
       typedef typename coordinate_traits<coordinate_type>::coordinate_distance dt;
- for(typename std::vector<std::pair<coordinate_type, std::pair<coordinate_type, int> > >::iterator
+ for(typename std::vector<std::pair<coordinate_type, std::pair<coordinate_type, int> > >::iterator
             itr = data_.begin(); itr != data_.end(); ++itr) {
         (*itr).first = scaling_policy<coordinate_type>::round((dt)((*itr).first) * (dt)factor);
         (*itr).second.first = scaling_policy<coordinate_type>::round((dt)((*itr).second.first) * (dt)factor);
@@ -883,7 +884,7 @@
       return bloat(0, e_total, 0, n_total);
     }
   }
-
+
   template <typename coordinate_type, typename property_type>
   class property_merge_90 {
   private:
@@ -906,7 +907,7 @@
     //with unique sets of merged properties to polygons sets in a map keyed by sets of properties
     // T = std::map<std::set<property_type>, polygon_90_set_data<coordiante_type> > or
     // T = std::map<std::vector<property_type>, polygon_90_set_data<coordiante_type> >
- template <typename ResultType>
+ template <typename ResultType>
     inline void merge(ResultType& result) {
       merge_scanline<coordinate_type, property_type, polygon_90_set_data<coordinate_type>, typename ResultType::key_type> ms;
       ms.perform_merge(result, pmd_);
@@ -925,12 +926,12 @@
     inline connectivity_extraction_90() : tsd_(), nodeCount_(0) {}
     inline connectivity_extraction_90(const connectivity_extraction_90& that) : tsd_(that.tsd_),
                                                                           nodeCount_(that.nodeCount_) {}
- inline connectivity_extraction_90& operator=(const connectivity_extraction_90& that) {
- tsd_ = that.tsd_;
+ inline connectivity_extraction_90& operator=(const connectivity_extraction_90& that) {
+ tsd_ = that.tsd_;
       nodeCount_ = that.nodeCount_; {}
       return *this;
     }
-
+
     //insert a polygon set graph node, the value returned is the id of the graph node
     inline unsigned int insert(const polygon_90_set_data<coordinate_type>& ps) {
       ps.clean();
@@ -943,7 +944,7 @@
       ps.insert(geoObj);
       return insert(ps);
     }
-
+
     //extract connectivity and store the edges in the graph
     //graph must be indexable by graph node id and the indexed value must be a std::set of
     //graph node id
@@ -955,4 +956,3 @@
 }
 }
 #endif
-

Modified: trunk/boost/polygon/polygon_90_set_traits.hpp
==============================================================================
--- trunk/boost/polygon/polygon_90_set_traits.hpp (original)
+++ trunk/boost/polygon/polygon_90_set_traits.hpp 2012-05-06 08:24:59 EDT (Sun, 06 May 2012)
@@ -24,7 +24,7 @@
   template <typename T>
   struct traits_by_concept<T, rectangle_concept> { typedef rectangle_traits<T> type; };
   template <typename T>
- struct traits_by_concept<T, segment_concept> { typedef segment_concept<T> type; };
+ struct traits_by_concept<T, segment_concept> { typedef segment_traits<T> type; };
   template <typename T>
   struct traits_by_concept<T, polygon_90_concept> { typedef polygon_traits<T> type; };
   template <typename T>

Modified: trunk/boost/polygon/segment_concept.hpp
==============================================================================
--- trunk/boost/polygon/segment_concept.hpp (original)
+++ trunk/boost/polygon/segment_concept.hpp 2012-05-06 08:24:59 EDT (Sun, 06 May 2012)
@@ -174,12 +174,12 @@
   typename enable_if<
     typename gtl_and_3<
       y_s_assign,
- typename is_mutable_segment_concept<
- typename geometry_concept<Segment1>::type
- >::type,
- typename is_segment_concept<
- typename geometry_concept<Segment2>::type
- >::type
+ typename is_mutable_segment_concept<
+ typename geometry_concept<Segment1>::type
+ >::type,
+ typename is_segment_concept<
+ typename geometry_concept<Segment2>::type
+ >::type
>::type,
     Segment1
>::type &
@@ -338,20 +338,17 @@
     bool
>::type
   contains(const Segment& segment, const Point& point, bool consider_touch = true ) {
- if (!on_above_or_below(segment, point)) {
- rectangle_data<typename segment_coordinate_type<Segment>::type> rect;
- set_points(rect, low(segment), high(segment));
- if (area(rect) == 0.0) {
- if (!consider_touch) {
- return !equivalence(point, low(segment)) &&
- !equivalence(point, high(segment));
- }
- }
- return contains(rect, point, consider_touch);
- }
- return false;
+ if (on_above_or_below(segment, point))
+ return false;
+ rectangle_data<typename segment_coordinate_type<Segment>::type> rect;
+ set_points(rect, low(segment), high(segment));
+ if (!contains(rect, point, true))
+ return false;
+ if (!consider_touch && (equivalence(low(segment), point) || equivalence(high(segment), point)))
+ return false;
+ return true;
   }
-
+
   struct y_s_contains2 : gtl_yes {};
 
   template <typename Segment1, typename Segment2>
@@ -590,21 +587,26 @@
>::type
   intersects(const Segment1& segment1, const Segment2& segment2,
              bool consider_touch = true) {
- if (consider_touch) {
- if (low(segment1) == low(segment2) || low(segment1) == high(segment2) ||
- high(segment1) == low(segment2) || high(segment1) == high(segment2))
- return true;
- }
- typedef polygon_arbitrary_formation<
- typename segment_coordinate_type<Segment1>::type
- > paf;
- typename paf::Point l1, h1, l2, h2;
- assign(l1, low(segment1));
- assign(h1, high(segment1));
- assign(l2, low(segment2));
- assign(h2, high(segment2));
- return paf::intersects(typename paf::half_edge(l1, h1),
- typename paf::half_edge(l2, h2));
+ rectangle_data<typename segment_coordinate_type<Segment1>::type> rect1, rect2;
+ set_points(rect1, low(segment1), high(segment1));
+ set_points(rect2, low(segment2), high(segment2));
+ // Check if axis-parallel rectangles containing segments intersect.
+ if (!intersects(rect1, rect2, true))
+ return false;
+ int or1_1 = on_above_or_below(segment1, low(segment2));
+ int or1_2 = on_above_or_below(segment1, high(segment2));
+ if (or1_1 * or1_2 > 0)
+ return false;
+ int or2_1 = on_above_or_below(segment2, low(segment1));
+ int or2_2 = on_above_or_below(segment2, high(segment1));
+ if (or2_1 * or2_2 > 0)
+ return false;
+ if (consider_touch || or1_1 && or1_2 || or2_1 && or2_2)
+ return true;
+ if (or1_1 || or1_2 || or2_1 || or2_2)
+ return false;
+ return intersects(vertical(rect1), vertical(rect2), false) ||
+ intersects(horizontal(rect1), horizontal(rect2), false);
   }
 
   struct y_s_intersect : gtl_yes {};
@@ -713,10 +715,11 @@
         result2 = euclidean_distance(segment1, high(segment2)),
         result3 = euclidean_distance(segment2, low(segment1)),
         result4 = euclidean_distance(segment2, high(segment1));
- typename segment_distance_type<Segment1>::type
- subres1 = (result1 < result2) ? result1 : result2,
- subres2 = (result3 < result4) ? result3 : result4;
- return (subres1 < subres2) ? subres1 : subres2;
+ if (result2 < result1)
+ result1 = result2;
+ if (result4 < result3)
+ result3 = result4;
+ return (result1 < result3) ? result1 : result3;
   }
 
   template <class T>

Modified: trunk/libs/polygon/test/polygon_segment_test.cpp
==============================================================================
--- trunk/libs/polygon/test/polygon_segment_test.cpp (original)
+++ trunk/libs/polygon/test/polygon_segment_test.cpp 2012-05-06 08:24:59 EDT (Sun, 06 May 2012)
@@ -34,7 +34,7 @@
   BOOST_CHECK(!(segment1 > segment1));
   BOOST_CHECK(segment1 <= segment2);
   BOOST_CHECK(segment1 >= segment2);
-
+
   segment1.low(point2);
   segment1.high(point1);
   BOOST_CHECK(segment1.low() == point2);
@@ -80,7 +80,7 @@
   struct segment_traits< Segment<T> > {
     typedef T coordinate_type;
     typedef point_data<T> point_type;
-
+
     static point_type get(const Segment<T>& segment, direction_1d dir) {
       return dir.to_int() ? segment.p1 : segment.p0;
     }
@@ -150,7 +150,7 @@
 BOOST_AUTO_TEST_CASE_TEMPLATE(segment_concept_test2, T, test_types) {
   typedef point_data<T> point_type;
   typedef Segment<T> segment_type;
-
+
   point_type point1(1, 2);
   point_type point2(2, 4);
   point_type point3(0, 0);
@@ -260,7 +260,7 @@
 
   scale_up(segment1, 3);
   BOOST_CHECK(low(segment1) == point_type(3, 6));
- BOOST_CHECK(high(segment1) == point_type(12, 18));
+ BOOST_CHECK(high(segment1) == point_type(12, 18));
 
   scale_down(segment1, 3);
   BOOST_CHECK(low(segment1) == point1);
@@ -321,18 +321,57 @@
   typedef point_data<T> point_type;
   typedef Segment<T> segment_type;
 
- point_type point;
   segment_type segment1 = construct<segment_type>(point_type(0, 0), point_type(2, 2));
   segment_type segment2 = construct<segment_type>(point_type(1, 1), point_type(3, 3));
-
- BOOST_CHECK(!intersection(point, segment1, segment2));
- BOOST_CHECK(intersects(segment1, segment2));
+ segment_type segment3 = construct<segment_type>(point_type(2, 2), point_type(-1, -1));
+ segment_type segment4 = construct<segment_type>(point_type(1, 3), point_type(3, 1));
+ segment_type segment5 = construct<segment_type>(point_type(2, 2), point_type(1, 3));
+
+ BOOST_CHECK(intersects(segment1, segment2, false));
+ BOOST_CHECK(intersects(segment1, segment2, true));
+ BOOST_CHECK(intersects(segment1, segment3, false));
+ BOOST_CHECK(intersects(segment1, segment3, true));
+ BOOST_CHECK(intersects(segment2, segment3, false));
+ BOOST_CHECK(intersects(segment2, segment3, true));
+ BOOST_CHECK(intersects(segment4, segment3, false));
+ BOOST_CHECK(intersects(segment4, segment3, true));
+ BOOST_CHECK(intersects(segment4, segment2, false));
+ BOOST_CHECK(intersects(segment4, segment2, true));
+ BOOST_CHECK(!intersects(segment3, segment5, false));
+ BOOST_CHECK(intersects(segment3, segment5, true));
 }
 
 BOOST_AUTO_TEST_CASE_TEMPLATE(segment_concept_test9, T, test_types) {
   typedef point_data<T> point_type;
   typedef Segment<T> segment_type;
 
+ segment_type segment1 = construct<segment_type>(point_type(0, 0), point_type(0, 2));
+ segment_type segment2 = construct<segment_type>(point_type(0, 1), point_type(0, 3));
+ segment_type segment3 = construct<segment_type>(point_type(0, 1), point_type(0, 2));
+ segment_type segment4 = construct<segment_type>(point_type(0, 2), point_type(0, 3));
+ segment_type segment5 = construct<segment_type>(point_type(0, 2), point_type(2, 2));
+ segment_type segment6 = construct<segment_type>(point_type(0, 1), point_type(1, 1));
+
+ BOOST_CHECK(intersects(segment1, segment1, false));
+ BOOST_CHECK(intersects(segment1, segment1, true));
+ BOOST_CHECK(intersects(segment1, segment2, false));
+ BOOST_CHECK(intersects(segment1, segment2, true));
+ BOOST_CHECK(intersects(segment1, segment3, false));
+ BOOST_CHECK(intersects(segment1, segment3, true));
+ BOOST_CHECK(intersects(segment2, segment3, false));
+ BOOST_CHECK(intersects(segment2, segment3, true));
+ BOOST_CHECK(!intersects(segment1, segment4, false));
+ BOOST_CHECK(intersects(segment1, segment4, true));
+ BOOST_CHECK(!intersects(segment1, segment5, false));
+ BOOST_CHECK(intersects(segment1, segment5, true));
+ BOOST_CHECK(intersects(segment1, segment6, false));
+ BOOST_CHECK(intersects(segment1, segment6, true));
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(segment_concept_test10, T, test_types) {
+ typedef point_data<T> point_type;
+ typedef Segment<T> segment_type;
+
   point_type point1(1, 2);
   point_type point2(7, 10);
   segment_type segment1 = construct<segment_type>(point1, point2);
@@ -345,7 +384,7 @@
   BOOST_CHECK(euclidean_distance(segment1, point_type(8, 3)) == 5.0);
 }
 
-BOOST_AUTO_TEST_CASE_TEMPLATE(segment_concept_test10, T, test_types) {
+BOOST_AUTO_TEST_CASE_TEMPLATE(segment_concept_test11, T, test_types) {
   typedef point_data<T> point_type;
   typedef Segment<T> segment_type;
 
@@ -353,15 +392,8 @@
   segment_type segment2 = construct<segment_type>(point_type(2, 0), point_type(0, 2));
   segment_type segment3 = construct<segment_type>(point_type(1, -7), point_type(10, 5));
   segment_type segment4 = construct<segment_type>(point_type(7, 7), point_type(10, 11));
- segment_type segment5 = construct<segment_type>(point_type(1, 1), point_type(-1, 3));
- segment_type segment6 = construct<segment_type>(point_type(0, 0), point_type(1, 1));
 
- BOOST_CHECK(intersects(segment1, segment2, false));
   BOOST_CHECK(euclidean_distance(segment1, segment2) == 0.0);
- BOOST_CHECK(!intersects(segment1, segment3, true));
   BOOST_CHECK(euclidean_distance(segment1, segment3) == 5.0);
- BOOST_CHECK(!intersects(segment1, segment4, true));
   BOOST_CHECK(euclidean_distance(segment1, segment4) == 5.0);
- BOOST_CHECK(intersects(segment2, segment5, false));
- BOOST_CHECK(intersects(segment2, segment6, false));
 }


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