Chris@16: // Boost.Polygon library interval_concept.hpp header file Chris@16: Chris@16: // Copyright (c) Intel Corporation 2008. Chris@16: // Copyright (c) 2008-2012 Simonson Lucanus. Chris@16: // Copyright (c) 2012-2012 Andrii Sydorchuk. Chris@16: Chris@16: // See http://www.boost.org for updates, documentation, and revision history. Chris@16: // Use, modification and distribution is subject to the Boost Software License, Chris@16: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_POLYGON_INTERVAL_CONCEPT_HPP Chris@16: #define BOOST_POLYGON_INTERVAL_CONCEPT_HPP Chris@16: Chris@16: #include "isotropy.hpp" Chris@16: #include "interval_traits.hpp" Chris@16: Chris@16: namespace boost { Chris@16: namespace polygon { Chris@16: Chris@16: struct interval_concept {}; Chris@16: Chris@16: template Chris@16: struct is_interval_concept { Chris@16: typedef gtl_no type; Chris@16: }; Chris@16: Chris@16: template <> Chris@16: struct is_interval_concept { Chris@16: typedef gtl_yes type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_mutable_interval_concept { Chris@16: typedef gtl_no type; Chris@16: }; Chris@16: Chris@16: template <> Chris@16: struct is_mutable_interval_concept { Chris@16: typedef gtl_yes type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct interval_coordinate_type_by_concept { Chris@16: typedef void type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct interval_coordinate_type_by_concept { Chris@16: typedef typename interval_traits::coordinate_type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct interval_coordinate_type { Chris@16: typedef typename interval_coordinate_type_by_concept< Chris@16: GeometryType, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct interval_difference_type_by_concept { Chris@16: typedef void type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct interval_difference_type_by_concept { Chris@16: typedef typename coordinate_traits< Chris@16: typename interval_traits::coordinate_type Chris@16: >::coordinate_difference type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct interval_difference_type { Chris@16: typedef typename interval_difference_type_by_concept< Chris@16: GeometryType, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: struct y_i_get : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_get, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: typename interval_coordinate_type::type Chris@16: >::type get(const IntervalType& interval, direction_1d dir) { Chris@16: return interval_traits::get(interval, dir); Chris@16: } Chris@16: Chris@16: struct y_i_set : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_set, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: void Chris@16: >::type set(IntervalType& interval, direction_1d dir, Chris@16: typename interval_mutable_traits::coordinate_type value) { Chris@16: interval_mutable_traits::set(interval, dir, value); Chris@16: } Chris@16: Chris@16: struct y_i_construct : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_construct, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType Chris@16: >::type construct( Chris@16: typename interval_mutable_traits::coordinate_type low, Chris@16: typename interval_mutable_traits::coordinate_type high) { Chris@16: if (low > high) { Chris@16: (std::swap)(low, high); Chris@16: } Chris@16: return interval_mutable_traits::construct(low, high); Chris@16: } Chris@16: Chris@16: struct y_i_copy_construct : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_copy_construct, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType1 Chris@16: >::type copy_construct(const IntervalType2& interval) { Chris@16: return construct(get(interval, LOW), get(interval, HIGH)); Chris@16: } Chris@16: Chris@16: struct y_i_assign : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_assign, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType1 Chris@16: >::type& assign(IntervalType1& lvalue, const IntervalType2& rvalue) { Chris@16: set(lvalue, LOW, get(rvalue, LOW)); Chris@16: set(lvalue, HIGH, get(rvalue, HIGH)); Chris@16: return lvalue; Chris@16: } Chris@16: Chris@16: struct y_i_low : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_low, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: typename interval_coordinate_type::type Chris@16: >::type low(const IntervalType& interval) { Chris@16: return get(interval, LOW); Chris@16: } Chris@16: Chris@16: struct y_i_high : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_high, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: typename interval_coordinate_type::type Chris@16: >::type high(const IntervalType& interval) { Chris@16: return get(interval, HIGH); Chris@16: } Chris@16: Chris@16: struct y_i_low2 : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_low2, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: void Chris@16: >::type low(IntervalType& interval, Chris@16: typename interval_mutable_traits::coordinate_type value) { Chris@16: set(interval, LOW, value); Chris@16: } Chris@16: Chris@16: struct y_i_high2 : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_high2, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: void Chris@16: >::type high(IntervalType& interval, Chris@16: typename interval_mutable_traits::coordinate_type value) { Chris@16: set(interval, HIGH, value); Chris@16: } Chris@16: Chris@16: struct y_i_equivalence : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_equivalence, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: bool Chris@16: >::type equivalence( Chris@16: const IntervalType1& interval1, Chris@16: const IntervalType2& interval2) { Chris@16: return (get(interval1, LOW) == get(interval2, LOW)) && Chris@16: (get(interval1, HIGH) == get(interval2, HIGH)); Chris@16: } Chris@16: Chris@16: struct y_i_contains : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_contains, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: bool Chris@16: >::type contains( Chris@16: const IntervalType& interval, Chris@16: typename interval_coordinate_type::type value, Chris@16: bool consider_touch = true ) { Chris@16: if (consider_touch) { Chris@16: return value <= high(interval) && value >= low(interval); Chris@16: } else { Chris@16: return value < high(interval) && value > low(interval); Chris@16: } Chris@16: } Chris@16: Chris@16: struct y_i_contains2 : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_contains2, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: bool Chris@16: >::type contains( Chris@16: const IntervalType1& interval1, Chris@16: const IntervalType2& interval2, Chris@16: bool consider_touch = true) { Chris@16: return contains(interval1, get(interval2, LOW), consider_touch) && Chris@16: contains(interval1, get(interval2, HIGH), consider_touch); Chris@16: } Chris@16: Chris@16: struct y_i_center : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_center, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: typename interval_coordinate_type::type Chris@16: >::type center(const IntervalType& interval) { Chris@16: return (high(interval) + low(interval)) / 2; Chris@16: } Chris@16: Chris@16: struct y_i_delta : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_delta, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: typename interval_difference_type::type Chris@16: >::type delta(const IntervalType& interval) { Chris@16: typedef typename interval_difference_type::type diff_type; Chris@16: return static_cast(high(interval)) - Chris@16: static_cast(low(interval)); Chris@16: } Chris@16: Chris@16: struct y_i_flip : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_flip, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType>::type& flip( Chris@16: IntervalType& interval, Chris@16: typename interval_coordinate_type::type axis = 0) { Chris@16: typename interval_coordinate_type::type newLow, newHigh; Chris@16: newLow = 2 * axis - high(interval); Chris@16: newHigh = 2 * axis - low(interval); Chris@16: low(interval, newLow); Chris@16: high(interval, newHigh); Chris@16: return interval; Chris@16: } Chris@16: Chris@16: struct y_i_scale_up : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_scale_up, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType Chris@16: >::type& scale_up( Chris@16: IntervalType& interval, Chris@16: typename interval_coordinate_type::type factor) { Chris@16: typename interval_coordinate_type::type newHigh = Chris@16: high(interval) * factor; Chris@16: low(interval, low(interval) * factor); Chris@16: high(interval, (newHigh)); Chris@16: return interval; Chris@16: } Chris@16: Chris@16: struct y_i_scale_down : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_scale_down, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType Chris@16: >::type& scale_down( Chris@16: IntervalType& interval, Chris@16: typename interval_coordinate_type::type factor) { Chris@16: typename interval_coordinate_type::type newHigh = Chris@16: high(interval) / factor; Chris@16: low(interval, low(interval) / factor); Chris@16: high(interval, (newHigh)); Chris@16: return interval; Chris@16: } Chris@16: Chris@16: // TODO(asydorchuk): Deprecated. Chris@16: struct y_i_scale : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_scale, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType Chris@16: >::type& scale(IntervalType& interval, double factor) { Chris@16: typedef typename interval_coordinate_type::type Unit; Chris@16: Unit newHigh = scaling_policy::round( Chris@16: static_cast(high(interval)) * factor); Chris@16: low(interval, scaling_policy::round( Chris@16: static_cast(low(interval)) * factor)); Chris@16: high(interval, (newHigh)); Chris@16: return interval; Chris@16: } Chris@16: Chris@16: struct y_i_move : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_move, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType Chris@16: >::type& move( Chris@16: IntervalType& interval, Chris@16: typename interval_difference_type::type displacement) { Chris@16: typedef typename interval_coordinate_type::type ctype; Chris@16: typedef typename coordinate_traits::coordinate_difference Unit; Chris@16: low(interval, static_cast( Chris@16: static_cast(low(interval)) + displacement)); Chris@16: high(interval, static_cast( Chris@16: static_cast(high(interval)) + displacement)); Chris@16: return interval; Chris@16: } Chris@16: Chris@16: struct y_i_convolve : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_convolve, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType Chris@16: >::type& convolve( Chris@16: IntervalType& interval, Chris@16: typename interval_coordinate_type::type value) { Chris@16: typedef typename interval_coordinate_type::type Unit; Chris@16: Unit newLow = low(interval) + value; Chris@16: Unit newHigh = high(interval) + value; Chris@16: low(interval, newLow); Chris@16: high(interval, newHigh); Chris@16: return interval; Chris@16: } Chris@16: Chris@16: struct y_i_deconvolve : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_deconvolve, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType Chris@16: >::type& deconvolve( Chris@16: IntervalType& interval, Chris@16: typename interval_coordinate_type::type value) { Chris@16: typedef typename interval_coordinate_type::type Unit; Chris@16: Unit newLow = low(interval) - value; Chris@16: Unit newHigh = high(interval) - value; Chris@16: low(interval, newLow); Chris@16: high(interval, newHigh); Chris@16: return interval; Chris@16: } Chris@16: Chris@16: struct y_i_convolve2 : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_convolve2, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType1 Chris@16: >::type& convolve(IntervalType1& lvalue, const IntervalType2& rvalue) { Chris@16: typedef typename interval_coordinate_type::type Unit; Chris@16: Unit newLow = low(lvalue) + low(rvalue); Chris@16: Unit newHigh = high(lvalue) + high(rvalue); Chris@16: low(lvalue, newLow); Chris@16: high(lvalue, newHigh); Chris@16: return lvalue; Chris@16: } Chris@16: Chris@16: struct y_i_deconvolve2 : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_deconvolve2, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType1 Chris@16: >::type& deconvolve(IntervalType1& lvalue, const IntervalType2& rvalue) { Chris@16: typedef typename interval_coordinate_type::type Unit; Chris@16: Unit newLow = low(lvalue) - low(rvalue); Chris@16: Unit newHigh = high(lvalue) - high(rvalue); Chris@16: low(lvalue, newLow); Chris@16: high(lvalue, newHigh); Chris@16: return lvalue; Chris@16: } Chris@16: Chris@16: struct y_i_reconvolve : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_reconvolve, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType1 Chris@16: >::type& reflected_convolve( Chris@16: IntervalType1& lvalue, Chris@16: const IntervalType2& rvalue) { Chris@16: typedef typename interval_coordinate_type::type Unit; Chris@16: Unit newLow = low(lvalue) - high(rvalue); Chris@16: Unit newHigh = high(lvalue) - low(rvalue); Chris@16: low(lvalue, newLow); Chris@16: high(lvalue, newHigh); Chris@16: return lvalue; Chris@16: } Chris@16: Chris@16: struct y_i_redeconvolve : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_redeconvolve, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType1 Chris@16: >::type& reflected_deconvolve( Chris@16: IntervalType1& lvalue, Chris@16: const IntervalType2& rvalue) { Chris@16: typedef typename interval_coordinate_type::type Unit; Chris@16: Unit newLow = low(lvalue) + high(rvalue); Chris@16: Unit newHigh = high(lvalue) + low(rvalue); Chris@16: low(lvalue, newLow); Chris@16: high(lvalue, newHigh); Chris@16: return lvalue; Chris@16: } Chris@16: Chris@16: struct y_i_e_dist1 : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and::type Chris@16: >::type Chris@16: >::type, Chris@16: typename interval_difference_type::type Chris@16: >::type euclidean_distance( Chris@16: const IntervalType& interval, Chris@16: typename interval_coordinate_type::type position) { Chris@16: typedef typename interval_difference_type::type Unit; Chris@16: Unit dist[3] = { Chris@16: 0, Chris@16: (Unit)low(interval) - (Unit)position, Chris@16: (Unit)position - (Unit)high(interval) Chris@16: }; Chris@16: return dist[(dist[1] > 0) + ((dist[2] > 0) << 1)]; Chris@16: } Chris@16: Chris@16: struct y_i_e_dist2 : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_e_dist2, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: typename interval_difference_type::type Chris@16: >::type euclidean_distance( Chris@16: const IntervalType1& interval1, Chris@16: const IntervalType2& interval2) { Chris@16: typedef typename interval_difference_type::type Unit; Chris@16: Unit dist[3] = { Chris@16: 0, Chris@16: (Unit)low(interval1) - (Unit)high(interval2), Chris@16: (Unit)low(interval2) - (Unit)high(interval1) Chris@16: }; Chris@16: return dist[(dist[1] > 0) + ((dist[2] > 0) << 1)]; Chris@16: } Chris@16: Chris@16: struct y_i_e_intersects : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_e_intersects, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: bool Chris@16: >::type intersects( Chris@16: const IntervalType1& interval1, Chris@16: const IntervalType2& interval2, Chris@16: bool consider_touch = true) { Chris@16: return consider_touch ? Chris@16: (low(interval1) <= high(interval2)) && Chris@16: (high(interval1) >= low(interval2)) : Chris@16: (low(interval1) < high(interval2)) && Chris@16: (high(interval1) > low(interval2)); Chris@16: } Chris@16: Chris@16: struct y_i_e_bintersect : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_e_bintersect, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: bool Chris@16: >::type boundaries_intersect( Chris@16: const IntervalType1& interval1, Chris@16: const IntervalType2& interval2, Chris@16: bool consider_touch = true) { Chris@16: return (contains(interval1, low(interval2), consider_touch) || Chris@16: contains(interval1, high(interval2), consider_touch)) && Chris@16: (contains(interval2, low(interval1), consider_touch) || Chris@16: contains(interval2, high(interval1), consider_touch)); Chris@16: } Chris@16: Chris@16: struct y_i_intersect : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_intersect, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: bool Chris@16: >::type intersect( Chris@16: IntervalType1& lvalue, Chris@16: const IntervalType2& rvalue, Chris@16: bool consider_touch = true) { Chris@16: typedef typename interval_coordinate_type::type Unit; Chris@16: Unit lowVal = (std::max)(low(lvalue), low(rvalue)); Chris@16: Unit highVal = (std::min)(high(lvalue), high(rvalue)); Chris@16: bool valid = consider_touch ? lowVal <= highVal : lowVal < highVal; Chris@16: if (valid) { Chris@16: low(lvalue, lowVal); Chris@16: high(lvalue, highVal); Chris@16: } Chris@16: return valid; Chris@16: } Chris@16: Chris@16: struct y_i_g_intersect : gtl_yes {}; Chris@16: Chris@16: // TODO(asydorchuk): Deprecated. Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_g_intersect, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType1 Chris@16: >::type& generalized_intersect( Chris@16: IntervalType1& lvalue, Chris@16: const IntervalType2& rvalue) { Chris@16: typedef typename interval_coordinate_type::type Unit; Chris@16: Unit coords[4] = {low(lvalue), high(lvalue), low(rvalue), high(rvalue)}; Chris@16: // TODO(asydorchuk): consider implementing faster sorting of small Chris@16: // fixed length range. Chris@16: polygon_sort(coords, coords+4); Chris@16: low(lvalue, coords[1]); Chris@16: high(lvalue, coords[2]); Chris@16: return lvalue; Chris@16: } Chris@16: Chris@16: struct y_i_abuts1 : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_abuts1, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: bool Chris@16: >::type abuts( Chris@16: const IntervalType1& interval1, Chris@16: const IntervalType2& interval2, Chris@16: direction_1d dir) { Chris@16: return dir.to_int() ? low(interval2) == high(interval1) : Chris@16: low(interval1) == high(interval2); Chris@16: } Chris@16: Chris@16: struct y_i_abuts2 : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_abuts2, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: bool Chris@16: >::type abuts( Chris@16: const IntervalType1& interval1, Chris@16: const IntervalType2& interval2) { Chris@16: return abuts(interval1, interval2, HIGH) || Chris@16: abuts(interval1, interval2, LOW); Chris@16: } Chris@16: Chris@16: struct y_i_bloat : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_bloat, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType Chris@16: >::type& bloat( Chris@16: IntervalType& interval, Chris@16: typename interval_coordinate_type::type bloating) { Chris@16: low(interval, low(interval) - bloating); Chris@16: high(interval, high(interval) + bloating); Chris@16: return interval; Chris@16: } Chris@16: Chris@16: struct y_i_bloat2 : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_bloat2, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType Chris@16: >::type& bloat( Chris@16: IntervalType& interval, Chris@16: direction_1d dir, Chris@16: typename interval_coordinate_type::type bloating) { Chris@16: set(interval, dir, get(interval, dir) + dir.get_sign() * bloating); Chris@16: return interval; Chris@16: } Chris@16: Chris@16: struct y_i_shrink : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_shrink, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType Chris@16: >::type& shrink( Chris@16: IntervalType& interval, Chris@16: typename interval_coordinate_type::type shrinking) { Chris@16: return bloat(interval, -shrinking); Chris@16: } Chris@16: Chris@16: struct y_i_shrink2 : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_shrink2, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType Chris@16: >::type& shrink( Chris@16: IntervalType& interval, Chris@16: direction_1d dir, Chris@16: typename interval_coordinate_type::type shrinking) { Chris@16: return bloat(interval, dir, -shrinking); Chris@16: } Chris@16: Chris@16: struct y_i_encompass : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_encompass, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: bool Chris@16: >::type encompass(IntervalType1& interval1, const IntervalType2& interval2) { Chris@16: bool retval = !contains(interval1, interval2, true); Chris@16: low(interval1, (std::min)(low(interval1), low(interval2))); Chris@16: high(interval1, (std::max)(high(interval1), high(interval2))); Chris@16: return retval; Chris@16: } Chris@16: Chris@16: struct y_i_encompass2 : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_encompass2, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: bool Chris@16: >::type encompass( Chris@16: IntervalType& interval, Chris@16: typename interval_coordinate_type::type value) { Chris@16: bool retval = !contains(interval, value, true); Chris@16: low(interval, (std::min)(low(interval), value)); Chris@16: high(interval, (std::max)(high(interval), value)); Chris@16: return retval; Chris@16: } Chris@16: Chris@16: struct y_i_get_half : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and< Chris@16: y_i_get_half, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type Chris@16: >::type, Chris@16: IntervalType Chris@16: >::type get_half(const IntervalType& interval, direction_1d dir) { Chris@16: typedef typename interval_coordinate_type::type Unit; Chris@16: Unit c = (get(interval, LOW) + get(interval, HIGH)) / 2; Chris@16: return construct( Chris@16: (dir == LOW) ? get(interval, LOW) : c, Chris@16: (dir == LOW) ? c : get(interval, HIGH)); Chris@16: } Chris@16: Chris@16: struct y_i_join_with : gtl_yes {}; Chris@16: Chris@16: template Chris@16: typename enable_if< Chris@16: typename gtl_and_3< Chris@16: y_i_join_with, Chris@16: typename is_mutable_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type, Chris@16: typename is_interval_concept< Chris@16: typename geometry_concept::type Chris@16: >::type>::type, Chris@16: bool Chris@16: >::type join_with(IntervalType1& interval1, const IntervalType2& interval2) { Chris@16: if (abuts(interval1, interval2)) { Chris@16: encompass(interval1, interval2); Chris@16: return true; Chris@16: } Chris@16: return false; Chris@16: } Chris@16: } // polygon Chris@16: } // boost Chris@16: Chris@16: #endif // BOOST_POLYGON_INTERVAL_CONCEPT_HPP