Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75151 - in sandbox/gtl: boost/polygon boost/polygon/detail libs/polygon/test
From: sydorchuk.andriy_at_[hidden]
Date: 2011-10-27 19:04:28


Author: asydorchuk
Date: 2011-10-27 19:04:27 EDT (Thu, 27 Oct 2011)
New Revision: 75151
URL: http://svn.boost.org/trac/boost/changeset/75151

Log:
Removing event equality predicate.
Moving site event set up logic from the voronoi_structures to the voronoi_builder.
Moving point comparison from the voronoi_structures to the voronoi_calc_kernel.
Updating tests.
Text files modified:
   sandbox/gtl/boost/polygon/detail/voronoi_calc_kernel.hpp | 30 ++++++++++++------------------
   sandbox/gtl/boost/polygon/detail/voronoi_structures.hpp | 40 +++++++++++++++-------------------------
   sandbox/gtl/boost/polygon/voronoi_builder.hpp | 28 +++++++++++++++++-----------
   sandbox/gtl/libs/polygon/test/voronoi_calc_kernel_test.cpp | 14 ++++++--------
   4 files changed, 50 insertions(+), 62 deletions(-)

Modified: sandbox/gtl/boost/polygon/detail/voronoi_calc_kernel.hpp
==============================================================================
--- sandbox/gtl/boost/polygon/detail/voronoi_calc_kernel.hpp (original)
+++ sandbox/gtl/boost/polygon/detail/voronoi_calc_kernel.hpp 2011-10-27 19:04:27 EDT (Thu, 27 Oct 2011)
@@ -120,10 +120,18 @@
         return is_vertical(site.point0(), site.point1());
     }
 
- template <typename Site>
- static bool is_segment(const Site &site) {
- return site.point0() != site.point1();
- }
+ template <typename Point>
+ class point_comparison_predicate {
+ public:
+ typedef Point point_type;
+
+ bool operator()(const point_type &lhs, const point_type &rhs) const {
+ if (lhs.x() == rhs.x()) {
+ return lhs.y() < rhs.y();
+ }
+ return lhs.x() < rhs.x();
+ }
+ };
 
     template <typename Site, typename Circle>
     class event_comparison_predicate {
@@ -201,20 +209,6 @@
         }
     };
 
- template <typename Site, typename Circle>
- class event_equality_predicate {
- public:
- typedef Site site_type;
- typedef Circle circle_type;
-
- template <typename T1, typename T2>
- bool operator()(const T1 &lhs, const T2 &rhs) {
- return !comparison_predicate_(lhs, rhs) && !comparison_predicate_(rhs, lhs);
- }
- private:
- event_comparison_predicate<Site, Circle> comparison_predicate_;
- };
-
     template <typename Site>
     class distance_predicate {
     public:

Modified: sandbox/gtl/boost/polygon/detail/voronoi_structures.hpp
==============================================================================
--- sandbox/gtl/boost/polygon/detail/voronoi_structures.hpp (original)
+++ sandbox/gtl/boost/polygon/detail/voronoi_structures.hpp 2011-10-27 19:04:27 EDT (Thu, 27 Oct 2011)
@@ -37,24 +37,6 @@
             return (this->x_ != that.x()) || (this->y_ != that.y());
         }
 
- bool operator<(const point_2d &that) const {
- if (this->x_ != that.x_)
- return this->x_ < that.x_;
- return this->y_ < that.y_;
- }
-
- bool operator<=(const point_2d &that) const {
- return !(that < (*this));
- }
-
- bool operator>(const point_2d &that) const {
- return that < (*this);
- }
-
- bool operator>=(const point_2d &that) const {
- return !((*this) < that);
- }
-
         coordinate_type x() const {
             return x_;
         }
@@ -122,19 +104,27 @@
             point0_(x1, y1),
             point1_(x2, y2),
             site_index_(index),
- is_inverse_(false) {
- if (point0_ > point1_)
- (std::swap)(point0_, point1_);
- }
+ is_inverse_(false) {}
 
         site_event(const point_type &point1,
                    const point_type &point2, int index) :
             point0_(point1),
             point1_(point2),
             site_index_(index),
- is_inverse_(false) {
- if (point0_ > point1_)
- (std::swap)(point0_, point1_);
+ is_inverse_(false) {}
+
+ bool operator==(const site_event &that) const {
+ return (this->point0_ == that.point0_) &&
+ (this->point1_ == that.point1_) &&
+ (this->site_index_ == that.site_index_) &&
+ (this->is_inverse_ == that.is_inverse_);
+ }
+
+ bool operator!=(const site_event &that) const {
+ return (this->point0_ != that.point0_) ||
+ (this->point1_ != that.point1_) ||
+ (this->site_index_ != that.site_index_) ||
+ (this->is_inverse_ != that.is_inverse_);
         }
 
         coordinate_type x(bool oriented = false) const {

Modified: sandbox/gtl/boost/polygon/voronoi_builder.hpp
==============================================================================
--- sandbox/gtl/boost/polygon/voronoi_builder.hpp (original)
+++ sandbox/gtl/boost/polygon/voronoi_builder.hpp 2011-10-27 19:04:27 EDT (Thu, 27 Oct 2011)
@@ -89,16 +89,20 @@
             // 1) the startpoint of the segment;
             // 2) the endpoint of the segment;
             // 3) the segment itself.
+ point_comparison_predicate point_comparison;
             for (SegmentIterator it = first_segment; it != last_segment; ++it) {
                 coordinate_type x1 = static_cast<coordinate_type>(it->low().x());
                 coordinate_type y1 = static_cast<coordinate_type>(it->low().y());
                 coordinate_type x2 = static_cast<coordinate_type>(it->high().x());
                 coordinate_type y2 = static_cast<coordinate_type>(it->high().y());
- site_events_.push_back(detail::site_event<coordinate_type>(x1, y1, 0));
- // Process degenerate segments correctly.
- if (x1 != x2 || y1 != y2) {
- site_events_.push_back(detail::site_event<coordinate_type>(x2, y2, 0));
- site_events_.push_back(detail::site_event<coordinate_type>(x1, y1, x2, y2, 0));
+ point_type p1(x1, y1);
+ point_type p2(x2, y2);
+ site_events_.push_back(detail::site_event<coordinate_type>(p1, 0));
+ site_events_.push_back(detail::site_event<coordinate_type>(p2, 0));
+ if (point_comparison(p1, p2)) {
+ site_events_.push_back(detail::site_event<coordinate_type>(p1, p2, 0));
+ } else {
+ site_events_.push_back(detail::site_event<coordinate_type>(p2, p1, 0));
                 }
             }
         }
@@ -159,10 +163,10 @@
         typedef typename std::vector<site_event_type>::const_iterator
             site_event_iterator_type;
         typedef detail::circle_event<coordinate_type> circle_event_type;
+ typedef typename CKT::point_comparison_predicate<point_type>
+ point_comparison_predicate;
         typedef typename CKT::event_comparison_predicate<site_event_type, circle_event_type>
             event_comparison_predicate;
- typedef typename CKT::event_equality_predicate<site_event_type, circle_event_type>
- event_equality_predicate;
         typedef typename CKT::circle_formation_predicate<site_event_type, circle_event_type>
             circle_formation_predicate_type;
         typedef typename output_type::voronoi_edge_type edge_type;
@@ -192,8 +196,7 @@
 
             // Remove duplicates.
             site_events_.erase(unique(site_events_.begin(),
- site_events_.end(),
- event_equality_predicate()), site_events_.end());
+ site_events_.end()), site_events_.end());
 
             // Index sites.
             for (size_t cur = 0; cur < site_events_.size(); ++cur)
@@ -505,10 +508,13 @@
             }
         }
     private:
- struct end_point_comparison {
+ class end_point_comparison {
+ public:
             bool operator() (const end_point_type &end1, const end_point_type &end2) const {
- return end1.first > end2.first;
+ return point_comparison(end2.first, end1.first);
             }
+ private:
+ point_comparison_predicate point_comparison;
         };
 
         std::vector<site_event_type> site_events_;

Modified: sandbox/gtl/libs/polygon/test/voronoi_calc_kernel_test.cpp
==============================================================================
--- sandbox/gtl/libs/polygon/test/voronoi_calc_kernel_test.cpp (original)
+++ sandbox/gtl/libs/polygon/test/voronoi_calc_kernel_test.cpp 2011-10-27 19:04:27 EDT (Thu, 27 Oct 2011)
@@ -21,7 +21,6 @@
 typedef site_event<int> site_type;
 typedef circle_event<double> circle_type;
 VCK::event_comparison_predicate<site_type, circle_type> event_comparison;
-VCK::event_equality_predicate<site_type, circle_type> event_equality;
 
 typedef beach_line_node_key<site_type> key_type;
 typedef VCK::distance_predicate<site_type> distance_predicate_type;
@@ -47,8 +46,7 @@
 
 #define CHECK_EVENT_COMPARISON(A, B, R1, R2) \
     BOOST_CHECK_EQUAL(event_comparison(A, B), R1); \
- BOOST_CHECK_EQUAL(event_comparison(B, A), R2); \
- BOOST_CHECK_EQUAL(event_equality(A, B), !R1 && !R2)
+ BOOST_CHECK_EQUAL(event_comparison(B, A), R2)
 
 #define CHECK_DISTANCE_PREDICATE(S1, S2, S3, RES) \
     BOOST_CHECK_EQUAL(distance_predicate(S1, S2, S3), RES)
@@ -96,7 +94,7 @@
 }
 
 BOOST_AUTO_TEST_CASE(event_comparison_test2) {
- site_type site(0, 2, 0, 0, 0);
+ site_type site(0, 0, 0, 2, 0);
     CHECK_EVENT_COMPARISON(site, site_type(0, 2, 1), true, false);
     CHECK_EVENT_COMPARISON(site, site_type(0, 0, 2), false, true);
     CHECK_EVENT_COMPARISON(site, site_type(0, -2, 0, -1, 3), false, true);
@@ -105,7 +103,7 @@
 }
 
 BOOST_AUTO_TEST_CASE(event_comparison_test3) {
- site_type site(10, 10, 0, 0, 0);
+ site_type site(0, 0, 10, 10, 0);
     CHECK_EVENT_COMPARISON(site, site_type(0, 0, 1), false, true);
     CHECK_EVENT_COMPARISON(site, site_type(0, -1, 2), false, true);
     CHECK_EVENT_COMPARISON(site, site_type(0, 1, 3), false, true);
@@ -430,13 +428,13 @@
 BOOST_AUTO_TEST_CASE(circle_formation_predicate_test9) {
     site_type site1(1, 0, 5, 0, 0);
     site1.inverse();
- site_type site2(8, 6, 0, 12, 1);
+ site_type site2(0, 12, 8, 6, 1);
     site_type site3(1, 0, 2);
     CHECK_CIRCLE_FORMATION_PREDICATE(site3, site2, site1, 1.0, 5.0, 6.0);
 }
 
 BOOST_AUTO_TEST_CASE(circle_formation_predicate_test10) {
- site_type site1(4, 0, 0, 0, 0);
+ site_type site1(0, 0, 4, 0, 0);
     site_type site2(0, 0, 0, 4, 1);
     site_type site3(0, 4, 4, 4, 2);
     site1.inverse();
@@ -444,7 +442,7 @@
 }
 
 BOOST_AUTO_TEST_CASE(circle_formation_predicate_test11) {
- site_type site1(41, 30, 1, 0, 0);
+ site_type site1(1, 0, 41, 30, 0);
     site_type site2(-39, 30, 1, 60, 1);
     site_type site3(1, 60, 41, 30, 2);
     site1.inverse();


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