Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81866 - in trunk: boost/polygon libs/polygon/test
From: sydorchuk.andriy_at_[hidden]
Date: 2012-12-11 17:29:13


Author: asydorchuk
Date: 2012-12-11 17:29:10 EST (Tue, 11 Dec 2012)
New Revision: 81866
URL: http://svn.boost.org/trac/boost/changeset/81866

Log:
Polygon: finished interval concept refactoring; completed interval unit tests coverage.

Text files modified:
   trunk/boost/polygon/interval_concept.hpp | 714 +++++++++++++++++++++++++--------------
   trunk/boost/polygon/interval_data.hpp | 5
   trunk/libs/polygon/test/polygon_interval_test.cpp | 147 +++++++-
   3 files changed, 590 insertions(+), 276 deletions(-)

Modified: trunk/boost/polygon/interval_concept.hpp
==============================================================================
--- trunk/boost/polygon/interval_concept.hpp (original)
+++ trunk/boost/polygon/interval_concept.hpp 2012-12-11 17:29:10 EST (Tue, 11 Dec 2012)
@@ -123,7 +123,8 @@
       typename geometry_concept<IntervalType>::type
>::type
>::type,
-IntervalType>::type construct(
+ IntervalType
+>::type construct(
     typename interval_mutable_traits<IntervalType>::coordinate_type low,
     typename interval_mutable_traits<IntervalType>::coordinate_type high) {
   if (low > high) {
@@ -145,7 +146,8 @@
       typename geometry_concept<IntervalType2>::type
>::type
>::type,
-IntervalType1>::type copy_construct(const IntervalType2& interval) {
+ IntervalType1
+>::type copy_construct(const IntervalType2& interval) {
   return construct<IntervalType1>(get(interval, LOW), get(interval, HIGH));
 }
 
@@ -162,7 +164,8 @@
       typename geometry_concept<IntervalType2>::type
>::type
>::type,
-IntervalType1>::type& assign(IntervalType1& lvalue, const IntervalType2& rvalue) {
+ IntervalType1
+>::type& assign(IntervalType1& lvalue, const IntervalType2& rvalue) {
   set(lvalue, LOW, get(rvalue, LOW));
   set(lvalue, HIGH, get(rvalue, HIGH));
   return lvalue;
@@ -208,7 +211,8 @@
       typename geometry_concept<IntervalType>::type
>::type
>::type,
-void>::type low(IntervalType& interval,
+ void
+>::type low(IntervalType& interval,
     typename interval_mutable_traits<IntervalType>::coordinate_type value) {
   set(interval, LOW, value);
 }
@@ -223,7 +227,8 @@
       typename geometry_concept<IntervalType>::type
>::type
>::type,
-void>::type high(IntervalType& interval,
+ void
+>::type high(IntervalType& interval,
     typename interval_mutable_traits<IntervalType>::coordinate_type value) {
   set(interval, HIGH, value);
 }
@@ -241,20 +246,30 @@
       typename geometry_concept<IntervalType2>::type
>::type
>::type,
-bool>::type equivalence(
- const IntervalType1& interval1, const IntervalType2& interval2) {
+ bool
+>::type equivalence(
+ const IntervalType1& interval1,
+ const IntervalType2& interval2) {
   return (get(interval1, LOW) == get(interval2, LOW)) &&
          (get(interval1, HIGH) == get(interval2, HIGH));
 }
 
 struct y_i_contains : gtl_yes {};
 
-template <typename interval_type>
-typename enable_if< typename gtl_and< y_i_contains, typename is_interval_concept<typename geometry_concept<interval_type>::type>::type >::type, bool>::type
-contains(const interval_type& interval,
- typename interval_coordinate_type<interval_type>::type value,
- bool consider_touch = true ) {
- if(consider_touch) {
+template <typename IntervalType>
+typename enable_if<
+ typename gtl_and<
+ y_i_contains,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType>::type
+ >::type
+ >::type,
+ bool
+>::type contains(
+ const IntervalType& interval,
+ typename interval_coordinate_type<IntervalType>::type value,
+ bool consider_touch = true ) {
+ if (consider_touch) {
     return value <= high(interval) && value >= low(interval);
   } else {
     return value < high(interval) && value > low(interval);
@@ -263,17 +278,24 @@
 
 struct y_i_contains2 : gtl_yes {};
 
-template <typename interval_type, typename interval_type_2>
-typename enable_if< typename gtl_and_3<
- y_i_contains2,
- typename is_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- bool>::type
-contains(const interval_type& interval,
- const interval_type_2& value,
- bool consider_touch = true) {
- return contains(interval, get(value, LOW), consider_touch) &&
- contains(interval, get(value, HIGH), consider_touch);
+template <typename IntervalType1, typename IntervalType2>
+typename enable_if<
+ typename gtl_and_3<
+ y_i_contains2,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ bool
+>::type contains(
+ const IntervalType1& interval1,
+ const IntervalType2& interval2,
+ bool consider_touch = true) {
+ return contains(interval1, get(interval2, LOW), consider_touch) &&
+ contains(interval1, get(interval2, HIGH), consider_touch);
 }
 
 struct y_i_center : gtl_yes {};
@@ -318,8 +340,9 @@
       typename geometry_concept<IntervalType>::type
>::type
>::type,
-IntervalType>::type& flip(IntervalType& interval,
- typename interval_coordinate_type<IntervalType>::type axis = 0) {
+IntervalType>::type& flip(
+ IntervalType& interval,
+ typename interval_coordinate_type<IntervalType>::type axis = 0) {
   typename interval_coordinate_type<IntervalType>::type newLow, newHigh;
   newLow = 2 * axis - high(interval);
   newHigh = 2 * axis - low(interval);
@@ -338,7 +361,9 @@
       typename geometry_concept<IntervalType>::type
>::type
>::type,
-IntervalType>::type& scale_up(IntervalType& interval,
+ IntervalType
+>::type& scale_up(
+ IntervalType& interval,
     typename interval_coordinate_type<IntervalType>::type factor) {
   typename interval_coordinate_type<IntervalType>::type newHigh =
       high(interval) * factor;
@@ -357,7 +382,9 @@
       typename geometry_concept<IntervalType>::type
>::type
>::type,
-IntervalType>::type& scale_down(IntervalType& interval,
+ IntervalType
+>::type& scale_down(
+ IntervalType& interval,
     typename interval_coordinate_type<IntervalType>::type factor) {
   typedef typename interval_coordinate_type<IntervalType>::type Unit;
   typename interval_coordinate_type<IntervalType>::type newHigh =
@@ -370,12 +397,21 @@
 // TODO(asydorchuk): Deprecated.
 struct y_i_scale : gtl_yes {};
 
-template <typename interval_type>
-typename enable_if<typename gtl_and<y_i_scale, typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type>::type, interval_type>::type &
-scale(interval_type& interval, double factor) {
- typedef typename interval_coordinate_type<interval_type>::type Unit;
- Unit newHigh = scaling_policy<Unit>::round((double)(high(interval)) * factor);
- low(interval, scaling_policy<Unit>::round((double)low(interval)* factor));
+template <typename IntervalType>
+typename enable_if<
+ typename gtl_and<
+ y_i_scale,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType>::type
+ >::type
+ >::type,
+ IntervalType
+>::type& scale(IntervalType& interval, double factor) {
+ typedef typename interval_coordinate_type<IntervalType>::type Unit;
+ Unit newHigh = scaling_policy<Unit>::round(
+ static_cast<double>(high(interval)) * factor);
+ low(interval, scaling_policy<Unit>::round(
+ static_cast<double>(low(interval)) * factor));
   high(interval, (newHigh));
   return interval;
 }
@@ -390,25 +426,36 @@
       typename geometry_concept<IntervalType>::type
>::type
>::type,
-IntervalType>::type& move(IntervalType& interval,
+ IntervalType
+>::type& move(
+ IntervalType& interval,
     typename interval_difference_type<IntervalType>::type displacement) {
   typedef typename interval_coordinate_type<IntervalType>::type ctype;
   typedef typename coordinate_traits<ctype>::coordinate_difference Unit;
- low(interval, static_cast<ctype>(static_cast<Unit>(low(interval)) + displacement));
- high(interval, static_cast<ctype>(static_cast<Unit>(high(interval)) + displacement));
+ low(interval, static_cast<ctype>(
+ static_cast<Unit>(low(interval)) + displacement));
+ high(interval, static_cast<ctype>(
+ static_cast<Unit>(high(interval)) + displacement));
   return interval;
 }
 
 struct y_i_convolve : gtl_yes {};
 
-// convolve this with b
-template <typename interval_type>
-typename enable_if<typename gtl_and<y_i_convolve, typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type>::type, interval_type>::type &
-convolve(interval_type& interval,
- typename interval_coordinate_type<interval_type>::type b) {
- typedef typename interval_coordinate_type<interval_type>::type Unit;
- Unit newLow = low(interval) + b;
- Unit newHigh = high(interval) + b;
+template <typename IntervalType>
+typename enable_if<
+ typename gtl_and<
+ y_i_convolve,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType>::type
+ >::type
+ >::type,
+ IntervalType
+>::type& convolve(
+ IntervalType& interval,
+ typename interval_coordinate_type<IntervalType>::type value) {
+ typedef typename interval_coordinate_type<IntervalType>::type Unit;
+ Unit newLow = low(interval) + value;
+ Unit newHigh = high(interval) + value;
   low(interval, newLow);
   high(interval, newHigh);
   return interval;
@@ -416,14 +463,21 @@
 
 struct y_i_deconvolve : gtl_yes {};
 
-// deconvolve this with b
-template <typename interval_type>
-typename enable_if<typename gtl_and<y_i_deconvolve, typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type>::type, interval_type>::type &
-deconvolve(interval_type& interval,
- typename interval_coordinate_type<interval_type>::type b) {
- typedef typename interval_coordinate_type<interval_type>::type Unit;
- Unit newLow = low(interval) - b;
- Unit newHigh = high(interval) - b;
+template <typename IntervalType>
+typename enable_if<
+ typename gtl_and<
+ y_i_deconvolve,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType>::type
+ >::type
+ >::type,
+ IntervalType
+>::type& deconvolve(
+ IntervalType& interval,
+ typename interval_coordinate_type<IntervalType>::type value) {
+ typedef typename interval_coordinate_type<IntervalType>::type Unit;
+ Unit newLow = low(interval) - value;
+ Unit newHigh = high(interval) - value;
   low(interval, newLow);
   high(interval, newHigh);
   return interval;
@@ -431,301 +485,451 @@
 
 struct y_i_convolve2 : gtl_yes {};
 
-// convolve this with b
-template <typename interval_type, typename interval_type_2>
+template <typename IntervalType1, typename IntervalType2>
 typename enable_if<
- typename gtl_and_3<y_i_convolve2,
- typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- interval_type>::type &
-convolve(interval_type& interval,
- const interval_type_2& b) {
- typedef typename interval_coordinate_type<interval_type>::type Unit;
- Unit newLow = low(interval) + low(b);
- Unit newHigh = high(interval) + high(b);
- low(interval, newLow);
- high(interval, newHigh);
- return interval;
+ typename gtl_and_3<
+ y_i_convolve2,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ IntervalType1
+>::type& convolve(IntervalType1& lvalue, const IntervalType2& rvalue) {
+ typedef typename interval_coordinate_type<IntervalType1>::type Unit;
+ Unit newLow = low(lvalue) + low(rvalue);
+ Unit newHigh = high(lvalue) + high(rvalue);
+ low(lvalue, newLow);
+ high(lvalue, newHigh);
+ return lvalue;
 }
 
 struct y_i_deconvolve2 : gtl_yes {};
 
-// deconvolve this with b
-template <typename interval_type, typename interval_type_2>
+template <typename IntervalType1, typename IntervalType2>
 typename enable_if<
- typename gtl_and_3< y_i_deconvolve2,
- typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- interval_type>::type &
-deconvolve(interval_type& interval,
- const interval_type_2& b) {
- typedef typename interval_coordinate_type<interval_type>::type Unit;
- Unit newLow = low(interval) - low(b);
- Unit newHigh = high(interval) - high(b);
- low(interval, newLow);
- high(interval, newHigh);
- return interval;
+ typename gtl_and_3<
+ y_i_deconvolve2,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ IntervalType1
+>::type& deconvolve(IntervalType1& lvalue, const IntervalType2& rvalue) {
+ typedef typename interval_coordinate_type<IntervalType1>::type Unit;
+ Unit newLow = low(lvalue) - low(rvalue);
+ Unit newHigh = high(lvalue) - high(rvalue);
+ low(lvalue, newLow);
+ high(lvalue, newHigh);
+ return lvalue;
 }
 
 struct y_i_reconvolve : gtl_yes {};
 
-// reflected convolve this with b
-template <typename interval_type, typename interval_type_2>
+template <typename IntervalType1, typename IntervalType2>
 typename enable_if<
- typename gtl_and_3<y_i_reconvolve,
- typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- interval_type>::type &
-reflected_convolve(interval_type& interval,
- const interval_type_2& b) {
- typedef typename interval_coordinate_type<interval_type>::type Unit;
- Unit newLow = low(interval) - high(b);
- Unit newHigh = high(interval) - low(b);
- low(interval, newLow);
- high(interval, newHigh);
- return interval;
+ typename gtl_and_3<
+ y_i_reconvolve,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ IntervalType1
+>::type& reflected_convolve(
+ IntervalType1& lvalue,
+ const IntervalType2& rvalue) {
+ typedef typename interval_coordinate_type<IntervalType1>::type Unit;
+ Unit newLow = low(lvalue) - high(rvalue);
+ Unit newHigh = high(lvalue) - low(rvalue);
+ low(lvalue, newLow);
+ high(lvalue, newHigh);
+ return lvalue;
 }
 
 struct y_i_redeconvolve : gtl_yes {};
 
-// reflected deconvolve this with b
-template <typename interval_type, typename interval_type_2>
+template <typename IntervalType1, typename IntervalType2>
 typename enable_if<
- typename gtl_and_3< y_i_redeconvolve,
- typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- interval_type>::type &
-reflected_deconvolve(interval_type& interval,
- const interval_type_2& b) {
- typedef typename interval_coordinate_type<interval_type>::type Unit;
- Unit newLow = low(interval) + high(b);
- Unit newHigh = high(interval) + low(b);
- low(interval, newLow);
- high(interval, newHigh);
- return interval;
+ typename gtl_and_3<
+ y_i_redeconvolve,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ IntervalType1
+>::type& reflected_deconvolve(
+ IntervalType1& lvalue,
+ const IntervalType2& rvalue) {
+ typedef typename interval_coordinate_type<IntervalType1>::type Unit;
+ Unit newLow = low(lvalue) + high(rvalue);
+ Unit newHigh = high(lvalue) + low(rvalue);
+ low(lvalue, newLow);
+ high(lvalue, newHigh);
+ return lvalue;
 }
 
 struct y_i_e_dist1 : gtl_yes {};
 
-// distance from a coordinate to an interval
-template <typename interval_type>
-typename enable_if< typename gtl_and<y_i_e_dist1, typename is_interval_concept<typename geometry_concept<interval_type>::type>::type>::type,
- typename interval_difference_type<interval_type>::type>::type
-euclidean_distance(const interval_type& interval,
- typename interval_coordinate_type<interval_type>::type position) {
- typedef typename coordinate_traits<typename interval_difference_type<interval_type>::type>::coordinate_difference Unit;
- Unit dist[3] = {0, (Unit)low(interval) - (Unit)position, (Unit)position - (Unit)high(interval)};
- return dist[ (dist[1] > 0) + ((dist[2] > 0) << 1) ];
+template <typename IntervalType>
+typename enable_if<
+ typename gtl_and<y_i_e_dist1,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType>::type
+ >::type
+ >::type,
+ typename interval_difference_type<IntervalType>::type
+>::type euclidean_distance(
+ const IntervalType& interval,
+ typename interval_coordinate_type<IntervalType>::type position) {
+ typedef typename interval_difference_type<IntervalType>::type Unit;
+ Unit dist[3] = {
+ 0,
+ (Unit)low(interval) - (Unit)position,
+ (Unit)position - (Unit)high(interval)
+ };
+ return dist[(dist[1] > 0) + ((dist[2] > 0) << 1)];
 }
 
 struct y_i_e_dist2 : gtl_yes {};
 
-// distance between two intervals
-template <typename interval_type, typename interval_type_2>
+template <typename IntervalType1, typename IntervalType2>
 typename enable_if<
- typename gtl_and_3<y_i_e_dist2, typename is_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- typename interval_difference_type<interval_type>::type>::type
-euclidean_distance(const interval_type& interval,
- const interval_type_2& b) {
- typedef typename coordinate_traits<typename interval_difference_type<interval_type>::type>::coordinate_difference Unit;
- Unit dist[3] = {0, (Unit)low(interval) - (Unit)high(b), (Unit)low(b) - (Unit)high(interval)};
- return dist[ (dist[1] > 0) + ((dist[2] > 0) << 1) ];
+ typename gtl_and_3<
+ y_i_e_dist2,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ typename interval_difference_type<IntervalType1>::type
+>::type euclidean_distance(
+ const IntervalType1& interval1,
+ const IntervalType2& interval2) {
+ typedef typename interval_difference_type<IntervalType1>::type Unit;
+ Unit dist[3] = {
+ 0,
+ (Unit)low(interval1) - (Unit)high(interval2),
+ (Unit)low(interval2) - (Unit)high(interval1)
+ };
+ return dist[(dist[1] > 0) + ((dist[2] > 0) << 1)];
 }
 
 struct y_i_e_intersects : gtl_yes {};
 
-// check if Interval b intersects `this` Interval
-template <typename interval_type, typename interval_type_2>
+template <typename IntervalType1, typename IntervalType2>
 typename enable_if<
- typename gtl_and_3<y_i_e_intersects, typename is_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- bool>::type
- intersects(const interval_type& interval, const interval_type_2& b,
- bool consider_touch = true) {
- return consider_touch ?
- (low(interval) <= high(b)) & (high(interval) >= low(b)) :
- (low(interval) < high(b)) & (high(interval) > low(b));
+ typename gtl_and_3<
+ y_i_e_intersects,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ bool
+>::type intersects(
+ const IntervalType1& interval1,
+ const IntervalType2& interval2,
+ bool consider_touch = true) {
+ return consider_touch ?
+ (low(interval1) <= high(interval2)) &&
+ (high(interval1) >= low(interval2)) :
+ (low(interval1) < high(interval2)) &&
+ (high(interval1) > low(interval2));
 }
 
 struct y_i_e_bintersect : gtl_yes {};
 
-// check if Interval b partially overlaps `this` Interval
-template <typename interval_type, typename interval_type_2>
+template <typename IntervalType1, typename IntervalType2>
 typename enable_if<
- typename gtl_and_3<y_i_e_bintersect, typename is_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- bool>::type
-boundaries_intersect(const interval_type& interval, const interval_type_2& b,
- bool consider_touch = true) {
- return (contains(interval, low(b), consider_touch) ||
- contains(interval, high(b), consider_touch)) &&
- (contains(b, low(interval), consider_touch) ||
- contains(b, high(interval), consider_touch));
+ typename gtl_and_3<
+ y_i_e_bintersect,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ bool
+>::type boundaries_intersect(
+ const IntervalType1& interval1,
+ const IntervalType2& interval2,
+ bool consider_touch = true) {
+ return (contains(interval1, low(interval2), consider_touch) ||
+ contains(interval1, high(interval2), consider_touch)) &&
+ (contains(interval2, low(interval1), consider_touch) ||
+ contains(interval2, high(interval1), consider_touch));
 }
 
-struct y_i_abuts1 : gtl_yes {};
+struct y_i_intersect : gtl_yes {};
 
-// check if they are end to end
-template <typename interval_type, typename interval_type_2>
-typename enable_if< typename gtl_and_3<y_i_abuts1, typename is_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- bool>::type
-abuts(const interval_type& interval, const interval_type_2& b, direction_1d dir) {
- return dir.to_int() ? low(b) == high(interval) : low(interval) == high(b);
+template <typename IntervalType1, typename IntervalType2>
+typename enable_if<
+ typename gtl_and_3<
+ y_i_intersect,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ bool
+>::type intersect(
+ IntervalType1& lvalue,
+ const IntervalType2& rvalue,
+ bool consider_touch = true) {
+ typedef typename interval_coordinate_type<IntervalType1>::type Unit;
+ Unit lowVal = (std::max)(low(lvalue), low(rvalue));
+ Unit highVal = (std::min)(high(lvalue), high(rvalue));
+ bool valid = consider_touch ? lowVal <= highVal : lowVal < highVal;
+ if (valid) {
+ low(lvalue, lowVal);
+ high(lvalue, highVal);
+ }
+ return valid;
 }
 
-struct y_i_abuts2 : gtl_yes {};
+struct y_i_g_intersect : gtl_yes {};
 
-// check if they are end to end
-template <typename interval_type, typename interval_type_2>
+// TODO(asydorchuk): Deprecated.
+template <typename IntervalType1, typename IntervalType2>
 typename enable_if<
- typename gtl_and_3<y_i_abuts2, typename is_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- bool>::type
-abuts(const interval_type& interval, const interval_type_2& b) {
- return abuts(interval, b, HIGH) || abuts(interval, b, LOW);
+ typename gtl_and_3<
+ y_i_g_intersect,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ IntervalType1
+>::type& generalized_intersect(
+ IntervalType1& lvalue,
+ const IntervalType2& rvalue) {
+ typedef typename interval_coordinate_type<IntervalType1>::type Unit;
+ Unit coords[4] = {low(lvalue), high(lvalue), low(rvalue), high(rvalue)};
+ // TODO(asydorchuk): consider implementing faster sorting of small
+ // fixed length range.
+ polygon_sort(coords, coords+4);
+ low(lvalue, coords[1]);
+ high(lvalue, coords[2]);
+ return lvalue;
 }
 
-struct y_i_intersect : gtl_yes {};
+struct y_i_abuts1 : gtl_yes {};
 
-// set 'this' interval to the intersection of 'this' and b
-template <typename interval_type, typename interval_type_2>
-typename enable_if< typename gtl_and_3<y_i_intersect, typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- bool>::type
-intersect(interval_type& interval, const interval_type_2& b, bool consider_touch = true) {
- typedef typename interval_coordinate_type<interval_type>::type Unit;
- Unit lowVal = (std::max)(low(interval), low(b));
- Unit highVal = (std::min)(high(interval), high(b));
- bool valid = consider_touch ?
- lowVal <= highVal :
- lowVal < highVal;
- if(valid) {
- low(interval, lowVal);
- high(interval, highVal);
- }
- return valid;
+template <typename IntervalType1, typename IntervalType2>
+typename enable_if<
+ typename gtl_and_3<
+ y_i_abuts1,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ bool
+>::type abuts(
+ const IntervalType1& interval1,
+ const IntervalType2& interval2,
+ direction_1d dir) {
+ return dir.to_int() ? low(interval2) == high(interval1) :
+ low(interval1) == high(interval2);
 }
 
-struct y_i_g_intersect : gtl_yes {};
+struct y_i_abuts2 : gtl_yes {};
 
-// set 'this' interval to the generalized intersection of 'this' and b
-template <typename interval_type, typename interval_type_2>
+template <typename IntervalType1, typename IntervalType2>
 typename enable_if<
- typename gtl_and_3<y_i_g_intersect, typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- interval_type>::type &
-generalized_intersect(interval_type& interval, const interval_type_2& b) {
- typedef typename interval_coordinate_type<interval_type>::type Unit;
- Unit coords[4] = {low(interval), high(interval), low(b), high(b)};
- //consider implementing faster sorting of small fixed length range
- polygon_sort(coords, coords+4);
- low(interval, coords[1]);
- high(interval, coords[2]);
- return interval;
+ typename gtl_and_3<
+ y_i_abuts2,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ bool
+>::type abuts(
+ const IntervalType1& interval1,
+ const IntervalType2& interval2) {
+ return abuts(interval1, interval2, HIGH) ||
+ abuts(interval1, interval2, LOW);
 }
 
 struct y_i_bloat : gtl_yes {};
 
-// bloat the Interval
-template <typename interval_type>
-typename enable_if< typename gtl_and<y_i_bloat, typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type>::type,
- interval_type>::type &
-bloat(interval_type& interval, typename interval_coordinate_type<interval_type>::type bloating) {
- low(interval, low(interval)-bloating);
- high(interval, high(interval)+bloating);
+template <typename IntervalType>
+typename enable_if<
+ typename gtl_and<
+ y_i_bloat,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType>::type
+ >::type
+ >::type,
+ IntervalType
+>::type& bloat(
+ IntervalType& interval,
+ typename interval_coordinate_type<IntervalType>::type bloating) {
+ low(interval, low(interval) - bloating);
+ high(interval, high(interval) + bloating);
   return interval;
 }
 
 struct y_i_bloat2 : gtl_yes {};
 
-// bloat the specified side of `this` Interval
-template <typename interval_type>
-typename enable_if< typename gtl_and<y_i_bloat2, typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type>::type,
- interval_type>::type &
-bloat(interval_type& interval, direction_1d dir, typename interval_coordinate_type<interval_type>::type bloating) {
+template <typename IntervalType>
+typename enable_if<
+ typename gtl_and<
+ y_i_bloat2,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType>::type
+ >::type
+ >::type,
+ IntervalType
+>::type& bloat(
+ IntervalType& interval,
+ direction_1d dir,
+ typename interval_coordinate_type<IntervalType>::type bloating) {
   set(interval, dir, get(interval, dir) + dir.get_sign() * bloating);
   return interval;
 }
 
 struct y_i_shrink : gtl_yes {};
 
-// shrink the Interval
-template <typename interval_type>
-typename enable_if< typename gtl_and<y_i_shrink, typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type>::type,
- interval_type>::type &
-shrink(interval_type& interval, typename interval_coordinate_type<interval_type>::type shrinking) {
+template <typename IntervalType>
+typename enable_if<
+ typename gtl_and<
+ y_i_shrink,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType>::type
+ >::type
+ >::type,
+ IntervalType
+>::type& shrink(
+ IntervalType& interval,
+ typename interval_coordinate_type<IntervalType>::type shrinking) {
   return bloat(interval, -shrinking);
 }
 
 struct y_i_shrink2 : gtl_yes {};
 
-// shrink the specified side of `this` Interval
-template <typename interval_type>
-typename enable_if< typename gtl_and<y_i_shrink2, typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type>::type,
- interval_type>::type &
-shrink(interval_type& interval, direction_1d dir, typename interval_coordinate_type<interval_type>::type shrinking) {
+template <typename IntervalType>
+typename enable_if<
+ typename gtl_and<
+ y_i_shrink2,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType>::type
+ >::type
+ >::type,
+ IntervalType
+>::type& shrink(
+ IntervalType& interval,
+ direction_1d dir,
+ typename interval_coordinate_type<IntervalType>::type shrinking) {
   return bloat(interval, dir, -shrinking);
 }
 
 struct y_i_encompass : gtl_yes {};
 
-// Enlarge `this` Interval to encompass the specified Interval
-template <typename interval_type, typename interval_type_2>
-typename enable_if< typename gtl_and_3<
- y_i_encompass,
- typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- bool>::type
-encompass(interval_type& interval, const interval_type_2& b) {
- bool retval = !contains(interval, b, true);
- low(interval, (std::min)(low(interval), low(b)));
- high(interval, (std::max)(high(interval), high(b)));
+template <typename IntervalType1, typename IntervalType2>
+typename enable_if<
+ typename gtl_and_3<
+ y_i_encompass,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type
+ >::type,
+ bool
+>::type encompass(IntervalType1& interval1, const IntervalType2& interval2) {
+ bool retval = !contains(interval1, interval2, true);
+ low(interval1, (std::min)(low(interval1), low(interval2)));
+ high(interval1, (std::max)(high(interval1), high(interval2)));
   return retval;
 }
 
 struct y_i_encompass2 : gtl_yes {};
 
-// Enlarge `this` Interval to encompass the specified Interval
-template <typename interval_type>
-typename enable_if< typename gtl_and<y_i_encompass2, typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type>::type,
- bool>::type
-encompass(interval_type& interval, typename interval_coordinate_type<interval_type>::type b) {
- bool retval = !contains(interval, b, true);
- low(interval, (std::min)(low(interval), b));
- high(interval, (std::max)(high(interval), b));
+template <typename IntervalType>
+typename enable_if<
+ typename gtl_and<
+ y_i_encompass2,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType>::type
+ >::type
+ >::type,
+ bool
+>::type encompass(
+ IntervalType& interval,
+ typename interval_coordinate_type<IntervalType>::type value) {
+ bool retval = !contains(interval, value, true);
+ low(interval, (std::min)(low(interval), value));
+ high(interval, (std::max)(high(interval), value));
   return retval;
 }
 
 struct y_i_get_half : gtl_yes {};
 
-// gets the half of the interval as an interval
-template <typename interval_type>
-typename enable_if<typename gtl_and<y_i_get_half, typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type>::type, interval_type>::type
-get_half(const interval_type& interval, direction_1d d1d) {
- typedef typename interval_coordinate_type<interval_type>::type Unit;
+template <typename IntervalType>
+typename enable_if<
+ typename gtl_and<
+ y_i_get_half,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType>::type
+ >::type
+ >::type,
+ IntervalType
+>::type get_half(const IntervalType& interval, direction_1d dir) {
+ typedef typename interval_coordinate_type<IntervalType>::type Unit;
   Unit c = (get(interval, LOW) + get(interval, HIGH)) / 2;
- return construct<interval_type>((d1d == LOW) ? get(interval, LOW) : c,
- (d1d == LOW) ? c : get(interval, HIGH));
+ return construct<IntervalType>(
+ (dir == LOW) ? get(interval, LOW) : c,
+ (dir == LOW) ? c : get(interval, HIGH));
 }
 
 struct y_i_join_with : gtl_yes {};
 
-// returns true if the 2 intervals exactly touch at one value, like in l1 <= h1 == l2 <= h2
-// sets the argument to the joined interval
-template <typename interval_type, typename interval_type_2>
-typename enable_if<
- typename gtl_and_3<y_i_join_with, typename is_mutable_interval_concept<typename geometry_concept<interval_type>::type>::type,
- typename is_interval_concept<typename geometry_concept<interval_type_2>::type>::type>::type,
- bool>::type
-join_with(interval_type& interval, const interval_type_2& b) {
- if(abuts(interval, b)) {
- encompass(interval, b);
+template <typename IntervalType1, typename IntervalType2>
+typename enable_if<
+ typename gtl_and_3<
+ y_i_join_with,
+ typename is_mutable_interval_concept<
+ typename geometry_concept<IntervalType1>::type
+ >::type,
+ typename is_interval_concept<
+ typename geometry_concept<IntervalType2>::type
+ >::type>::type,
+ bool
+>::type join_with(IntervalType1& interval1, const IntervalType2& interval2) {
+ if (abuts(interval1, interval2)) {
+ encompass(interval1, interval2);
     return true;
   }
   return false;
 }
 } // polygon
 } // boost
+
 #endif // BOOST_POLYGON_INTERVAL_CONCEPT_HPP

Modified: trunk/boost/polygon/interval_data.hpp
==============================================================================
--- trunk/boost/polygon/interval_data.hpp (original)
+++ trunk/boost/polygon/interval_data.hpp 2012-12-11 17:29:10 EST (Tue, 11 Dec 2012)
@@ -27,14 +27,15 @@
 #ifndef BOOST_POLYGON_MSVC
     : coords_()
 #endif
- {}
+ {}
 
   interval_data(coordinate_type low, coordinate_type high)
 #ifndef BOOST_POLYGON_MSVC
     : coords_()
 #endif
   {
- coords_[LOW] = low; coords_[HIGH] = high;
+ coords_[LOW] = low;
+ coords_[HIGH] = high;
   }
 
   interval_data(const interval_data& that)

Modified: trunk/libs/polygon/test/polygon_interval_test.cpp
==============================================================================
--- trunk/libs/polygon/test/polygon_interval_test.cpp (original)
+++ trunk/libs/polygon/test/polygon_interval_test.cpp 2012-12-11 17:29:10 EST (Tue, 11 Dec 2012)
@@ -127,23 +127,132 @@
 BOOST_AUTO_TEST_CASE_TEMPLATE(interval_concept_test2, T, test_types) {
   typedef Interval<T> interval_type;
 
- interval_type interval = construct<interval_type>(1, 3);
- BOOST_CHECK_EQUAL(center(interval), 2);
- BOOST_CHECK_EQUAL(delta(interval), 2);
-
- flip(interval, -1);
- BOOST_CHECK_EQUAL(low(interval), -5);
- BOOST_CHECK_EQUAL(high(interval), -3);
-
- scale_up(interval, 2);
- BOOST_CHECK_EQUAL(low(interval), -10);
- BOOST_CHECK_EQUAL(high(interval), -6);
-
- scale_down(interval, 2);
- BOOST_CHECK_EQUAL(low(interval), -5);
- BOOST_CHECK_EQUAL(high(interval), -3);
-
- move(interval, 5);
- BOOST_CHECK_EQUAL(low(interval), 0);
- BOOST_CHECK_EQUAL(high(interval), 2);
+ interval_type interval1 = construct<interval_type>(1, 3);
+ BOOST_CHECK_EQUAL(center(interval1), 2);
+ BOOST_CHECK_EQUAL(delta(interval1), 2);
+
+ flip(interval1, -1);
+ BOOST_CHECK_EQUAL(low(interval1), -5);
+ BOOST_CHECK_EQUAL(high(interval1), -3);
+
+ scale_up(interval1, 2);
+ BOOST_CHECK_EQUAL(low(interval1), -10);
+ BOOST_CHECK_EQUAL(high(interval1), -6);
+
+ scale_down(interval1, 2);
+ BOOST_CHECK_EQUAL(low(interval1), -5);
+ BOOST_CHECK_EQUAL(high(interval1), -3);
+
+ move(interval1, 5);
+ BOOST_CHECK_EQUAL(low(interval1), 0);
+ BOOST_CHECK_EQUAL(high(interval1), 2);
+
+ convolve(interval1, 1);
+ BOOST_CHECK_EQUAL(low(interval1), 1);
+ BOOST_CHECK_EQUAL(high(interval1), 3);
+
+ deconvolve(interval1, 2);
+ BOOST_CHECK_EQUAL(low(interval1), -1);
+ BOOST_CHECK_EQUAL(high(interval1), 1);
+
+ interval_type interval2 = construct<interval_type>(-1, 2);
+ convolve(interval1, interval2);
+ BOOST_CHECK_EQUAL(low(interval1), -2);
+ BOOST_CHECK_EQUAL(high(interval1), 3);
+
+ deconvolve(interval1, interval2);
+ BOOST_CHECK_EQUAL(low(interval1), -1);
+ BOOST_CHECK_EQUAL(high(interval1), 1);
+
+ reflected_convolve(interval1, interval2);
+ BOOST_CHECK_EQUAL(low(interval1), -3);
+ BOOST_CHECK_EQUAL(high(interval1), 2);
+
+ reflected_deconvolve(interval1, interval2);
+ BOOST_CHECK_EQUAL(low(interval1), -1);
+ BOOST_CHECK_EQUAL(high(interval1), 1);
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(interval_concept_test3, T, test_types) {
+ typedef Interval<T> interval_type;
+
+ interval_type interval1 = construct<interval_type>(1, 3);
+ BOOST_CHECK_EQUAL(euclidean_distance(interval1, -2), 3);
+ BOOST_CHECK_EQUAL(euclidean_distance(interval1, 2), 0);
+ BOOST_CHECK_EQUAL(euclidean_distance(interval1, 4), 1);
+
+ interval_type interval2 = construct<interval_type>(-1, 0);
+ BOOST_CHECK_EQUAL(euclidean_distance(interval1, interval2), 1);
+ BOOST_CHECK(!intersects(interval1, interval2));
+ BOOST_CHECK(!boundaries_intersect(interval1, interval2));
+ BOOST_CHECK(!intersect(interval2, interval1));
+ BOOST_CHECK_EQUAL(low(interval2), -1);
+ BOOST_CHECK_EQUAL(high(interval2), 0);
+
+ interval_type interval3 = construct<interval_type>(-1, 6);
+ BOOST_CHECK_EQUAL(euclidean_distance(interval1, interval3), 0);
+ BOOST_CHECK(intersects(interval1, interval3));
+ BOOST_CHECK(!boundaries_intersect(interval1, interval3));
+ BOOST_CHECK(intersect(interval3, interval1));
+ BOOST_CHECK_EQUAL(low(interval3), 1);
+ BOOST_CHECK_EQUAL(high(interval3), 3);
+
+ interval_type interval4 = construct<interval_type>(5, 6);
+ BOOST_CHECK_EQUAL(euclidean_distance(interval1, interval4), 2);
+ BOOST_CHECK(!intersects(interval1, interval4));
+ BOOST_CHECK(!boundaries_intersect(interval1, interval4));
+ BOOST_CHECK(!intersect(interval4, interval1));
+ BOOST_CHECK_EQUAL(low(interval4), 5);
+ BOOST_CHECK_EQUAL(high(interval4), 6);
+
+ interval_type interval5 = construct<interval_type>(3, 5);
+ BOOST_CHECK_EQUAL(euclidean_distance(interval1, interval5), 0);
+ BOOST_CHECK(!intersects(interval1, interval5, false));
+ BOOST_CHECK(boundaries_intersect(interval1, interval5));
+ BOOST_CHECK(intersect(interval5, interval1));
+ BOOST_CHECK_EQUAL(low(interval5), 3);
+ BOOST_CHECK_EQUAL(high(interval5), 3);
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(interval_concept_test4, T, test_types) {
+ typedef Interval<T> interval_type;
+
+ interval_type interval1 = construct<interval_type>(1, 3);
+ interval_type interval2 = construct<interval_type>(3, 5);
+ BOOST_CHECK(!abuts(interval1, interval2, LOW));
+ BOOST_CHECK(abuts(interval1, interval2, HIGH));
+ BOOST_CHECK(abuts(interval1, interval2));
+
+ bloat(interval1, 1);
+ BOOST_CHECK_EQUAL(low(interval1), 0);
+ BOOST_CHECK_EQUAL(high(interval1), 4);
+ BOOST_CHECK(!abuts(interval1, interval2));
+
+ bloat(interval1, LOW, 1);
+ BOOST_CHECK_EQUAL(low(interval1), -1);
+ BOOST_CHECK_EQUAL(high(interval1), 4);
+
+ shrink(interval1, LOW, 1);
+ BOOST_CHECK_EQUAL(low(interval1), 0);
+ BOOST_CHECK_EQUAL(high(interval1), 4);
+
+ shrink(interval1, 1);
+ BOOST_CHECK_EQUAL(low(interval1), 1);
+ BOOST_CHECK_EQUAL(high(interval1), 3);
+
+ BOOST_CHECK(encompass(interval1, 4));
+ BOOST_CHECK_EQUAL(low(interval1), 1);
+ BOOST_CHECK_EQUAL(high(interval1), 4);
+
+ BOOST_CHECK(encompass(interval1, interval2));
+ BOOST_CHECK_EQUAL(low(interval1), 1);
+ BOOST_CHECK_EQUAL(high(interval1), 5);
+
+ interval1 = get_half(interval1, LOW);
+ BOOST_CHECK_EQUAL(low(interval1), 1);
+ BOOST_CHECK_EQUAL(high(interval1), 3);
+
+ BOOST_CHECK(join_with(interval1, interval2));
+ BOOST_CHECK_EQUAL(low(interval1), 1);
+ BOOST_CHECK_EQUAL(high(interval1), 5);
 }


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