/usr/include/boost/polygon
Edit: /usr/include/boost/polygon/rectangle_concept.hpp (50898B)
/*
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).
*/
#ifndef BOOST_POLYGON_RECTANGLE_CONCEPT_HPP
#define BOOST_POLYGON_RECTANGLE_CONCEPT_HPP
#include "isotropy.hpp"
//point
#include "point_data.hpp"
#include "point_traits.hpp"
#include "point_concept.hpp"
//interval
#include "interval_data.hpp"
#include "interval_traits.hpp"
#include "interval_concept.hpp"
#include "rectangle_data.hpp"
#include "rectangle_traits.hpp"
namespace boost { namespace polygon{
struct rectangle_concept {};
template
struct is_rectangle_concept { typedef gtl_no type; };
template <>
struct is_rectangle_concept { typedef gtl_yes type; };
template
struct is_mutable_rectangle_concept { typedef gtl_no type; };
template <>
struct is_mutable_rectangle_concept { typedef gtl_yes type; };
template <>
struct geometry_domain { typedef manhattan_domain type; };
template
struct rectangle_interval_type_by_concept { typedef void type; };
template
struct rectangle_interval_type_by_concept { typedef typename rectangle_traits::interval_type type; };
template
struct rectangle_interval_type {
typedef typename rectangle_interval_type_by_concept::type>::type>::type type;
};
template
struct rectangle_coordinate_type_by_concept { typedef void type; };
template
struct rectangle_coordinate_type_by_concept { typedef typename rectangle_traits::coordinate_type type; };
template
struct rectangle_coordinate_type {
typedef typename rectangle_coordinate_type_by_concept::type>::type>::type type;
};
template
struct rectangle_difference_type_by_concept { typedef void type; };
template
struct rectangle_difference_type_by_concept {
typedef typename coordinate_traits::coordinate_type>::coordinate_difference type; };
template
struct rectangle_difference_type {
typedef typename rectangle_difference_type_by_concept<
T, typename is_rectangle_concept::type>::type>::type type;
};
template
struct rectangle_distance_type_by_concept { typedef void type; };
template
struct rectangle_distance_type_by_concept {
typedef typename coordinate_traits::type>::coordinate_distance type; };
template
struct rectangle_distance_type {
typedef typename rectangle_distance_type_by_concept<
T, typename is_rectangle_concept::type>::type>::type type;
};
struct y_r_get_interval : gtl_yes {};
template
typename enable_if< typename gtl_and::type>::type>::type,
typename rectangle_interval_type::type>::type
get(const T& rectangle, orientation_2d orient) {
return rectangle_traits::get(rectangle, orient);
}
struct y_r_h : gtl_yes {};
template
typename enable_if< typename gtl_and::type>::type>::type,
typename rectangle_interval_type::type>::type
horizontal(const T& rectangle) {
return rectangle_traits::get(rectangle, HORIZONTAL);
}
struct y_r_v : gtl_yes {};
template
typename enable_if< typename gtl_and::type>::type>::type,
typename rectangle_interval_type::type>::type
vertical(const T& rectangle) {
return rectangle_traits::get(rectangle, VERTICAL);
}
struct y_r_set : gtl_yes {};
template
typename enable_if< typename gtl_and_3::type>::type,
typename is_interval_concept::type>::type>::type,
void>::type
set(T& rectangle, const T2& interval) {
rectangle_mutable_traits::set(rectangle, orient, interval);
}
struct y_r_set2 : gtl_yes {};
template
typename enable_if< typename gtl_and_3::type>::type,
typename is_interval_concept::type>::type>::type,
void>::type
set(T& rectangle, orientation_2d orient, const T2& interval) {
rectangle_mutable_traits::set(rectangle, orient, interval);
}
struct y_r_h2 : gtl_yes {};
template
typename enable_if< typename gtl_and_3::type>::type,
typename is_interval_concept::type>::type>::type,
void>::type
horizontal(T& rectangle, const T2& interval) {
rectangle_mutable_traits::set(rectangle, HORIZONTAL, interval);
}
struct y_r_v2 : gtl_yes {};
template
typename enable_if<
typename gtl_and_3::type>::type,
typename is_interval_concept::type>::type>::type, void>::type
vertical(T& rectangle, const T2& interval) {
rectangle_mutable_traits::set(rectangle, VERTICAL, interval);
}
struct y_r_construct : gtl_yes {};
template
typename enable_if< typename gtl_and::type>::type>::type,
T>::type
construct(const T2& interval_horizontal,
const T3& interval_vertical) {
return rectangle_mutable_traits::construct(interval_horizontal, interval_vertical); }
struct y_r_construct2 : gtl_yes {};
template
typename enable_if< typename gtl_and::type>::type>::type,
T>::type
construct(coord_type xl, coord_type yl, coord_type xh, coord_type yh) {
return rectangle_mutable_traits::construct(interval_data(xl, xh),
interval_data(yl, yh));
}
struct y_r_cconstruct : gtl_yes {};
template
typename enable_if<
typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
T>::type
copy_construct(const T2& rectangle) {
return construct (get(rectangle, HORIZONTAL), get(rectangle, VERTICAL));
}
struct y_r_assign : gtl_yes {};
template
typename enable_if<
typename gtl_and_3< y_r_assign,
typename is_mutable_rectangle_concept::type>::type,
typename is_rectangle_concept::type>::type>::type,
rectangle_type_1>::type &
assign(rectangle_type_1& lvalue, const rectangle_type_2& rvalue) {
set(lvalue, HORIZONTAL, get(rvalue, HORIZONTAL));
set(lvalue, VERTICAL, get(rvalue, VERTICAL));
return lvalue;
}
struct y_r_equiv : gtl_yes {};
template
typename enable_if<
typename gtl_and_3< y_r_equiv,
typename is_rectangle_concept::type>::type,
typename is_rectangle_concept::type>::type>::type,
bool>::type
equivalence(const T& rect1, const T2& rect2) {
return equivalence(get(rect1, HORIZONTAL), get(rect2, HORIZONTAL)) &&
equivalence(get(rect1, VERTICAL), get(rect2, VERTICAL));
}
struct y_r_get : gtl_yes {};
template
typename enable_if< typename gtl_and::type>::type>::type,
typename rectangle_coordinate_type::type>::type
get(const rectangle_type& rectangle, orientation_2d orient, direction_1d dir) {
return get(rectangle_traits::get(rectangle, orient), dir);
}
struct y_r_set3 : gtl_yes {};
template
typename enable_if::type>::type>::type, void>::type
set(rectangle_type& rectangle, orientation_2d orient, direction_1d dir,
typename rectangle_coordinate_type::type value) {
typename rectangle_interval_type::type ivl = get(rectangle, orient);
set(ivl, dir, value);
set(rectangle, orient, ivl);
}
struct y_r_xl : gtl_yes {};
template
typename enable_if< typename gtl_and::type>::type>::type,
typename rectangle_coordinate_type::type>::type
xl(const rectangle_type& rectangle) {
return get(rectangle, HORIZONTAL, LOW);
}
struct y_r_xl2 : gtl_yes {};
template
typename enable_if::type>::type>::type, void>::type
xl(rectangle_type& rectangle, typename rectangle_coordinate_type::type value) {
return set(rectangle, HORIZONTAL, LOW, value);
}
struct y_r_xh : gtl_yes {};
template
typename enable_if< typename gtl_and::type>::type>::type,
typename rectangle_coordinate_type::type>::type
xh(const rectangle_type& rectangle) {
return get(rectangle, HORIZONTAL, HIGH);
}
struct y_r_xh2 : gtl_yes {};
template
typename enable_if::type>::type>::type, void>::type
xh(rectangle_type& rectangle, typename rectangle_coordinate_type::type value) {
return set(rectangle, HORIZONTAL, HIGH, value);
}
struct y_r_yl : gtl_yes {};
template
typename enable_if< typename gtl_and::type>::type>::type,
typename rectangle_coordinate_type::type>::type
yl(const rectangle_type& rectangle) {
return get(rectangle, VERTICAL, LOW);
}
struct y_r_yl2 : gtl_yes {};
template
typename enable_if::type>::type>::type, void>::type
yl(rectangle_type& rectangle, typename rectangle_coordinate_type::type value) {
return set(rectangle, VERTICAL, LOW, value);
}
struct y_r_yh : gtl_yes {};
template
typename enable_if< typename gtl_and::type>::type>::type,
typename rectangle_coordinate_type::type>::type
yh(const rectangle_type& rectangle) {
return get(rectangle, VERTICAL, HIGH);
}
struct y_r_yh2 : gtl_yes {};
template
typename enable_if::type>::type>::type, void>::type
yh(rectangle_type& rectangle, typename rectangle_coordinate_type::type value) {
return set(rectangle, VERTICAL, HIGH, value);
}
struct y_r_ll : gtl_yes {};
template
typename enable_if::type>::type>::type,
point_data::type> >::type
ll(const rectangle_type& rectangle) {
return point_data::type> (xl(rectangle), yl(rectangle));
}
struct y_r_lr : gtl_yes {};
template
typename enable_if::type>::type>::type,
point_data::type> >::type
lr(const rectangle_type& rectangle) {
return point_data::type> (xh(rectangle), yl(rectangle));
}
struct y_r_ul : gtl_yes {};
template
typename enable_if::type>::type>::type,
point_data::type> >::type
ul(const rectangle_type& rectangle) {
return point_data::type> (xl(rectangle), yh(rectangle));
}
struct y_r_ur : gtl_yes {};
template
typename enable_if::type>::type>::type,
point_data::type> >::type
ur(const rectangle_type& rectangle) {
return point_data::type> (xh(rectangle), yh(rectangle));
}
struct y_r_contains : gtl_yes {};
template
typename enable_if< typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
bool>::type
contains(const rectangle_type& rectangle, const rectangle_type_2 rectangle_contained,
bool consider_touch = true) {
return contains(horizontal(rectangle), horizontal(rectangle_contained), consider_touch) &&
contains(vertical(rectangle), vertical(rectangle_contained), consider_touch);
}
struct y_r_contains2 : gtl_yes {};
template
typename enable_if< typename gtl_and_3::type>::type,
typename is_point_concept::type>::type>::type, bool>::type
contains(const rectangle_type& rectangle, const point_type point_contained,
bool consider_touch = true) {
return contains(horizontal(rectangle), x(point_contained), consider_touch) &&
contains(vertical(rectangle), y(point_contained), consider_touch);
}
struct y_r_set_points : gtl_yes {};
// set all four coordinates based upon two points
template
typename enable_if< typename gtl_and_4< y_r_set_points,
typename is_mutable_rectangle_concept::type>::type,
typename is_point_concept::type>::type,
typename is_point_concept::type>::type>::type,
rectangle_type>::type &
set_points(rectangle_type& rectangle, const point_type_1& p1,
const point_type_2& p2) {
typedef typename rectangle_coordinate_type::type Unit;
Unit x1(x(p1));
Unit x2(x(p2));
Unit y1(y(p1));
Unit y2(y(p2));
horizontal(rectangle, construct::type>(x1, x2));
vertical(rectangle, construct::type>(y1, y2));
return rectangle;
}
struct y_r_move : gtl_yes {};
// move rectangle by delta in orient
template
typename enable_if< typename gtl_and::type>::type>::type,
rectangle_type>::type &
move(rectangle_type& rectangle, orientation_2d orient,
typename coordinate_traits::type>::coordinate_difference delta) {
typename rectangle_interval_type::type ivl = get(rectangle, orient);
move(ivl, delta);
set(rectangle, orient, ivl);
return rectangle;
}
struct y_r_convolve : gtl_yes {};
// convolve this with b
template
typename enable_if<
typename gtl_and_3< y_r_convolve,
typename is_mutable_rectangle_concept::type>::type,
typename is_rectangle_concept::type>::type>::type,
rectangle_type_1>::type &
convolve(rectangle_type_1& rectangle,
const rectangle_type_2& convolution_rectangle) {
typename rectangle_interval_type::type ivl = horizontal(rectangle);
horizontal(rectangle, convolve(ivl, horizontal(convolution_rectangle)));
ivl = vertical(rectangle);
vertical(rectangle, convolve(ivl, vertical(convolution_rectangle)));
return rectangle;
}
struct y_r_deconvolve : gtl_yes {};
// deconvolve this with b
template
typename enable_if< typename gtl_and_3< y_r_deconvolve,
typename is_mutable_rectangle_concept::type>::type,
typename is_rectangle_concept::type>::type>::type,
rectangle_type_1>::type &
deconvolve(rectangle_type_1& rectangle, const rectangle_type_2& convolution_rectangle) {
typename rectangle_interval_type::type ivl = horizontal(rectangle);
horizontal(rectangle, deconvolve(ivl, horizontal(convolution_rectangle)));
ivl = vertical(rectangle);
vertical(rectangle, deconvolve(ivl, vertical(convolution_rectangle)));
return rectangle;
}
struct y_r_reconvolve : gtl_yes {};
// reflectedConvolve this with b
template
typename enable_if<
typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
rectangle_type_1>::type &
reflected_convolve(rectangle_type_1& rectangle, const rectangle_type_2& convolution_rectangle) {
typename rectangle_interval_type::type ivl = horizontal(rectangle);
horizontal(rectangle, reflected_convolve(ivl, horizontal(convolution_rectangle)));
ivl = vertical(rectangle);
vertical(rectangle, reflected_convolve(ivl, vertical(convolution_rectangle)));
return rectangle;
}
struct y_r_redeconvolve : gtl_yes {};
// reflectedDeconvolve this with b
// deconvolve this with b
template
typename enable_if<
typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
rectangle_type_1>::type &
reflected_deconvolve(rectangle_type_1& rectangle, const rectangle_type_2& convolution_rectangle) {
typename rectangle_interval_type::type ivl = horizontal(rectangle);
horizontal(rectangle, reflected_deconvolve(ivl, horizontal(convolution_rectangle)));
ivl = vertical(rectangle);
vertical(rectangle, reflected_deconvolve(ivl, vertical(convolution_rectangle)));
return rectangle;
}
struct y_r_convolve2 : gtl_yes {};
// convolve with point
template
typename enable_if< typename gtl_and_3::type>::type,
typename is_point_concept::type>::type>::type,
rectangle_type>::type &
convolve(rectangle_type& rectangle, const point_type& convolution_point) {
typename rectangle_interval_type::type ivl = horizontal(rectangle);
horizontal(rectangle, convolve(ivl, x(convolution_point)));
ivl = vertical(rectangle);
vertical(rectangle, convolve(ivl, y(convolution_point)));
return rectangle;
}
struct y_r_deconvolve2 : gtl_yes {};
// deconvolve with point
template
typename enable_if<
typename gtl_and_3::type>::type,
typename is_point_concept::type>::type>::type, rectangle_type>::type &
deconvolve(rectangle_type& rectangle, const point_type& convolution_point) {
typename rectangle_interval_type::type ivl = horizontal(rectangle);
horizontal(rectangle, deconvolve(ivl, x(convolution_point)));
ivl = vertical(rectangle);
vertical(rectangle, deconvolve(ivl, y(convolution_point)));
return rectangle;
}
struct y_r_delta : gtl_yes {};
// get the magnitude of the interval range depending on orient
template
typename enable_if< typename gtl_and::type>::type>::type,
typename rectangle_difference_type::type>::type
delta(const rectangle_type& rectangle, orientation_2d orient) {
return delta(get(rectangle, orient));
}
struct y_r_area : gtl_yes {};
// get the area of the rectangle
template
typename enable_if< typename gtl_and::type>::type>::type,
typename coordinate_traits::type>::manhattan_area_type>::type
area(const rectangle_type& rectangle) {
typedef typename coordinate_traits::type>::manhattan_area_type area_type;
return (area_type)delta(rectangle, HORIZONTAL) * (area_type)delta(rectangle, VERTICAL);
}
struct y_r_go : gtl_yes {};
// returns the orientation of the longest side
template
typename enable_if::type>::type>::type,
orientation_2d>::type
guess_orientation(const rectangle_type& rectangle) {
return delta(rectangle, HORIZONTAL) >= delta(rectangle, VERTICAL) ?
HORIZONTAL : VERTICAL;
}
struct y_r_half_p : gtl_yes {};
// get the half perimeter of the rectangle
template
typename enable_if< typename gtl_and::type>::type>::type,
typename rectangle_difference_type::type>::type
half_perimeter(const rectangle_type& rectangle) {
return delta(rectangle, HORIZONTAL) + delta(rectangle, VERTICAL);
}
struct y_r_perimeter : gtl_yes {};
// get the perimeter of the rectangle
template
typename enable_if< typename gtl_and::type>::type>::type,
typename rectangle_difference_type::type>::type
perimeter(const rectangle_type& rectangle) {
return 2 * half_perimeter(rectangle);
}
struct y_r_intersects : gtl_yes {};
// check if Rectangle b intersects `this` Rectangle
// [in] b Rectangle that will be checked
// [in] considerTouch If true, return true even if b touches the boundary
// [ret] . true if `t` intersects b
template
typename enable_if<
typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
bool>::type
intersects(const rectangle_type_1& rectangle, const rectangle_type_2& b, bool consider_touch = true) {
return intersects(horizontal(rectangle), horizontal(b), consider_touch) &&
intersects(vertical(rectangle), vertical(b), consider_touch);
}
struct y_r_b_intersect : gtl_yes {};
// Check if boundaries of Rectangle b and `this` Rectangle intersect
// [in] b Rectangle that will be checked
// [in] considerTouch If true, return true even if p is on the foundary
// [ret] . true if `t` contains p
template
typename enable_if<
typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
bool>::type
boundaries_intersect(const rectangle_type_1& rectangle, const rectangle_type_2& b,
bool consider_touch = true) {
return (intersects(rectangle, b, consider_touch) &&
!(contains(rectangle, b, !consider_touch)) &&
!(contains(b, rectangle, !consider_touch)));
}
struct y_r_b_abuts : gtl_yes {};
// check if b is touching 'this' on the end specified by dir
template
typename enable_if< typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
bool>::type
abuts(const rectangle_type_1& rectangle, const rectangle_type_2& b,
direction_2d dir) {
return
abuts(get(rectangle, orientation_2d(dir)),
get(b, orientation_2d(dir)),
direction_1d(dir)) &&
intersects(get(rectangle, orientation_2d(dir).get_perpendicular()),
get(b, orientation_2d(dir).get_perpendicular()), true);
}
struct y_r_b_abuts2 : gtl_yes {};
// check if they are touching in the given orientation
template
typename enable_if< typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
bool>::type
abuts(const rectangle_type_1& rectangle, const rectangle_type_2& b,
orientation_2d orient) {
return
abuts(get(rectangle, orient), get(b, orient)) &&
intersects(get(rectangle, orient.get_perpendicular()),
get(b, orient.get_perpendicular()), true);
}
struct y_r_b_abuts3 : gtl_yes {};
// check if they are touching but not overlapping
template
typename enable_if< typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
bool>::type
abuts(const rectangle_type_1& rectangle, const rectangle_type_2& b) {
return abuts(rectangle, b, HORIZONTAL) || abuts(rectangle, b, VERTICAL);
}
struct y_r_b_intersect2 : gtl_yes {};
// intersect rectangle with interval on orient
template
typename enable_if<
typename gtl_and_3::type>::type,
typename is_interval_concept::type>::type>::type,
bool>::type
intersect(rectangle_type& rectangle, const interval_type& b,
orientation_2d orient, bool consider_touch = true) {
typename rectangle_interval_type::type ivl = get(rectangle, orient);
if(intersect(ivl, b, consider_touch)) {
set(rectangle, orient, ivl);
return true;
}
return false;
}
struct y_r_b_intersect3 : gtl_yes {};
// clip rectangle to b
template
typename enable_if< typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
bool>::type
intersect(rectangle_type_1& rectangle, const rectangle_type_2& b, bool consider_touch = true) {
if(intersects(rectangle, b)) {
intersect(rectangle, horizontal(b), HORIZONTAL, consider_touch);
intersect(rectangle, vertical(b), VERTICAL, consider_touch);
return true;
}
return false;
}
struct y_r_g_intersect : gtl_yes {};
// Sets this to the generalized intersection of this and the given rectangle
template
typename enable_if< typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
rectangle_type_1>::type &
generalized_intersect(rectangle_type_1& rectangle, const rectangle_type_2& b) {
typename rectangle_interval_type::type ivl = get(rectangle, HORIZONTAL);
generalized_intersect(ivl, horizontal(b));
horizontal(rectangle, ivl);
ivl = vertical(rectangle);
generalized_intersect(ivl, vertical(b));
vertical(rectangle, ivl);
return rectangle;
}
struct y_r_bloat : gtl_yes {};
// bloat the interval specified by orient by bloating
template
typename enable_if::type>::type>::type,
rectangle_type>::type &
bloat(rectangle_type& rectangle, orientation_2d orient,
typename rectangle_coordinate_type::type bloating) {
typename rectangle_interval_type::type ivl = get(rectangle, orient);
bloat(ivl, bloating);
set(rectangle, orient, ivl);
return rectangle;
}
struct y_r_bloat2 : gtl_yes {};
// bloat the Rectangle by bloating
template
typename enable_if::type>::type>::type,
rectangle_type>::type &
bloat(rectangle_type& rectangle,
typename rectangle_coordinate_type::type bloating) {
bloat(rectangle, HORIZONTAL, bloating);
return bloat(rectangle, VERTICAL, bloating);
}
struct y_r_bloat3 : gtl_yes {};
// bloat the interval cooresponding to orient by bloating in dir direction
template
typename enable_if::type>::type>::type,
rectangle_type>::type &
bloat(rectangle_type& rectangle, direction_2d dir,
typename rectangle_coordinate_type::type bloating) {
typename rectangle_interval_type::type ivl = get(rectangle, orientation_2d(dir));
bloat(ivl, direction_1d(dir), bloating);
set(rectangle, orientation_2d(dir), ivl);
return rectangle;
}
struct y_r_shrink : gtl_yes {};
// shrink the interval specified by orient by bloating
template
typename enable_if::type>::type>::type,
rectangle_type>::type &
shrink(rectangle_type& rectangle, orientation_2d orient,
typename rectangle_coordinate_type::type shrinking) {
return bloat(rectangle, orient, -shrinking);
}
struct y_r_shrink2 : gtl_yes {};
// shrink the Rectangle by bloating
template
typename enable_if::type>::type>::type,
rectangle_type>::type &
shrink(rectangle_type& rectangle,
typename rectangle_coordinate_type::type shrinking) {
return bloat(rectangle, -shrinking);
}
struct y_r_shrink3 : gtl_yes {};
// shrink the interval cooresponding to orient by bloating in dir direction
template
typename enable_if::type>::type>::type,
rectangle_type>::type &
shrink(rectangle_type& rectangle, direction_2d dir,
typename rectangle_coordinate_type::type shrinking) {
return bloat(rectangle, dir, -shrinking);
}
struct y_r_encompass : gtl_yes {};
// encompass interval on orient
template
typename enable_if::type>::type,
typename is_interval_concept::type>::type>::type,
bool>::type
encompass(rectangle_type& rectangle, const interval_type& b, orientation_2d orient) {
typename rectangle_interval_type::type ivl = get(rectangle, orient);
if(encompass(ivl, b)) {
set(rectangle, orient, ivl);
return true;
}
return false;
}
struct y_r_encompass2 : gtl_yes {};
// enlarge rectangle to encompass the Rectangle b
template
typename enable_if< typename gtl_and_3<
y_r_encompass2,
typename is_mutable_rectangle_concept::type>::type,
typename is_rectangle_concept::type>::type >::type,
bool>::type
encompass(rectangle_type_1& rectangle, const rectangle_type_2& b) {
//note that operator | is intentional because both should be called regardless
return encompass(rectangle, horizontal(b), HORIZONTAL) |
encompass(rectangle, vertical(b), VERTICAL);
}
struct y_r_encompass3 : gtl_yes {};
// enlarge rectangle to encompass the point b
template
typename enable_if::type>::type,
typename is_point_concept::type>::type>::type,
bool>::type
encompass(rectangle_type_1& rectangle, const point_type& b) {
typename rectangle_interval_type::type hivl, vivl;
hivl = horizontal(rectangle);
vivl = vertical(rectangle);
//note that operator | is intentional because both should be called regardless
bool retval = encompass(hivl, x(b)) | encompass(vivl, y(b));
if(retval) {
horizontal(rectangle, hivl);
vertical(rectangle, vivl);
}
return retval;
}
struct y_r_center : gtl_yes {};
// returns the center of the rectangle
template
typename enable_if<
typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
bool>::type
center(point_type& center_point, const rectangle_type& rectangle) {
center_point = construct(center(horizontal(rectangle)),
center(vertical(rectangle)));
return true;
}
struct y_r_get_corner : gtl_yes {};
template
typename enable_if<
typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
bool>::type
get_corner(point_type& corner_point, const rectangle_type& rectangle, direction_2d direction_facing, direction_1d direction_turning) {
typedef typename rectangle_coordinate_type::type Unit;
Unit u1 = get(rectangle, direction_facing);
Unit u2 = get(rectangle, direction_facing.turn(direction_turning));
if(orientation_2d(direction_facing).to_int()) std::swap(u1, u2);
corner_point = construct(u1, u2);
return true;
}
struct y_r_get_half : gtl_yes {};
template
typename enable_if::type>::type>::type,
rectangle_type>::type
get_half(const rectangle_type& rectangle, direction_2d dir) {
rectangle_type retval(rectangle);
set(retval, orientation_2d(dir), get_half(get(rectangle, orientation_2d(dir)), direction_1d(dir)));
return retval;
}
struct y_r_join_with : gtl_yes {};
template
typename enable_if< typename gtl_and_3::type>::type,
typename is_rectangle_concept::type>::type>::type,
bool>::type
join_with(rectangle_type_1& rectangle, const rectangle_type_2& b) {
typedef typename rectangle_interval_type::type Interval1;
typedef typename rectangle_interval_type::type Interval2;
Interval1 hi1 = get(rectangle, HORIZONTAL);
Interval1 vi1 = get(rectangle, VERTICAL);
Interval2 hi2 = get(b, HORIZONTAL), vi2 = get(b, VERTICAL);
Interval1 temp;
if (equivalence(hi1, hi2) && join_with(vi1, vi2)) {
vertical(rectangle, vi1);
return true;
}
if (equivalence(vi1, vi2) && join_with(hi1, hi2)) {
horizontal(rectangle, hi1);
return true;
}
return false;
}
struct y_r_eda2 : gtl_yes {};
template
typename enable_if< typename gtl_and_3