Rectangle Concept

The rectangle concept tag is rectangle_concept

To register a user defined type as a model of rectangle concept, specialize the geometry concept meta-function for that type.  In the example below CRectangle is registered as a model of rectangle  concept.

template <>
struct geometry_concept<CRectangle> { typedef rectangle_concept type; };

The semantic of a rectangle is that it has an x and a y interval and these intervals conform to the semantic of an interval including its invariant.  This invariant on the intervals of a rectangle is enforced by the generic library functions that operate on rectangles, and is not expected of the data type itself or the concept mapping of that data type to the rectangle concept through its traits.  In this way a boost::tuple<int, int, int, int> or boost::array<int, 4> could be made models of rectangle by simply providing indirect access to their elements through traits.

Below is shown the default rectangle traits.  Specialization of these traits is required for types that don't conform to the default behavior.  The interested reader will note SFINAE is used on the traits to allow only an object that provides a member type definition of interval_type to work with the default read only traits.  This becomes necessary when refinements of concepts are used and it is undesirable to attempt to match default traits to non-rectangle types at compile time.  Specializing rectangle_traits can be done easily by simply providing gtl_yes as the enable parameter.

template <typename T, typename enable = gtl_yes>
struct rectangle_traits {};

template <typename T>
struct rectangle_traits<T, gtl_no> {};

template <typename T>
struct rectangle_traits<T, typename gtl_same_type<typename T::interval_type, typename T::interval_type>::type> {
     typedef typename T::coordinate_type coordinate_type;
     typedef typename T::interval_type interval_type;
     static inline interval_type get(const T& rectangle, orientation_2d orient) {
          return rectangle.get(orient); }
};

template <typename T>
struct rectangle_mutable_traits {
     template <typename T2>
     static inline void set(T& rectangle, orientation_2d orient, const T2& interval) {
          rectangle.set(orient, interval); }
     template <typename T2, typename T3>
     static inline T construct(const T2& interval_horizontal, const T3& interval_vertical) {
          return T(interval_horizontal, interval_vertical); }
};

Functions

template <typename T>
interval_type get(const T& rectangle, orientation_2d)
Expects a model of rectangle.  Returns the x interval or y interval of the rectangle, depending on the orientation_2d value.
 
template <typename T, typename coordinate_type>
void set(T& rectangle, orientation_2d, coordinate_type)
Expects a model of rectangle.   Sets the x interval or y interval of the rectangle to the coordinate, depending on the orientation_2d value.
template <typename T>
interval_type get(const T& rectangle, orientation_2d,
                  direction_1d)
Expects a model of rectangle.  Returns the coordinate specificed by the direction_1d value of the x interval or y interval of the rectangle, depending on the orientation_2d value.
 
template <typename T, typename coordinate_type>
void set(T& rectangle, orientation_2d, direction_1d,
         coordinate_type)
Expects a model of rectangle.   Sets the coordinate specified by the direction_1d value of the x interval or y interval of the rectangle to the coordinate, depending on the orientation_2d value.
template <typename T, typename T2>
T construct(const T2& h, const T2& v)
Construct an object that is a model of rectangle given x interval and y intervals.
template <typename T, typename T2>
T construct(coordinate_type xl, coordinate_type yl,
            coordinate_type xh, coordinate_type yh)
Construct an object that is a model of rectangle given four coordinate values.
template <typename T1, typename T2>
T1& assign(T1& left, const T2& right)
Copies data from right object that models rectangle into left object that models rectangle.
template <typename T, typename T2>
bool equivalence(const T& rectangle1,

                 const T2& rectangle2)
Given two objects that model rectangle, compares and returns true if their x and y intervals are respectively equivalent.
template <typename T, typename point_type>
bool contains(const T&, const point_type& point,
              bool consider_touch=true)
Given an object that models rectangle and an object that models point, returns true if the rectangle contains the point.  If the consider_touch flag is true will return true if the point lies along the boundary of the rectangle.
template <typename T1, typename T2>
bool contains(const T1& a, const T2& b,
              bool consider_touch = true)
Returns true if model of rectangle a contains both intervals of model of rectangle b.  If the consider_touch flag is true will consider rectangle b contained even if it touches the boundary of a.
template <typename T>
interval_type horizontal(const T& rectangle)
Returns the x interval of an object that models rectangle.
template <typename T>
interval_type vertical(const T& rectangle)
Returns the y interval of an object that models rectangle.
template <typename T>
coordinate_type xl(const T& rectangle)
Returns the west coordinate of an object that models rectangle.
template <typename T>
coordinate_type xh(const T& rectangle)
Returns the east coordinate of an object that models rectangle.
template <typename T>
coordinate_type yl(const T& rectangle)
Returns the south coordinate of an object that models rectangle.
template <typename T>
coordinate_type yh(const T& rectangle)
Returns the north coordinate of an object that models rectangle.
template <typename T>
point_type ll(const T& rectangle)
Returns the lower left corner point of an object that models rectangle.
template <typename T>
point_type lr(const T& rectangle)
Returns the lower right corner point of an object that models rectangle.
template <typename T>
point_type ul(const T& rectangle)
Returns the upper left corner point of an object that models rectangle.
template <typename T>
point_type ur(const T& rectangle)
Returns the upper right corner point of an object that models rectangle.
// get the center coordinate
template <typename T, typename point_type>
void center(point_type& p, const T& rectangle)
Sets object that models point to the center point of an object that models rectangle.
template <typename T, typename interval_type>
void horizontal(T& rectangle, const interval_type& i)
Sets the x interval of the object that models rectangle to be equal to the value of an object that models interval.
template <typename T, typename interval_type>
void vertical(T& rectangle, const interval_type& i )
Sets the y interval of the object that models rectangle to be equal to the value of an object that models interval.
template <typename rectangle_type>
void xl(rectangle_type& rectangle, coordinate_type )
Sets the west coordinate of the object that models rectangle to be equal to the coordinate value.
template <typename rectangle_type>
void xh(rectangle_type& rectangle, coordinate_type )
Sets the east coordinate of the object that models rectangle to be equal to the coordinate value.
template <typename rectangle_type>
void yl(rectangle_type& rectangle, coordinate_type )
Sets the south coordinate of the object that models rectangle to be equal to the coordinate value.
template <typename rectangle_type>
void yh(rectangle_type& rectangle, coordinate_type )
Sets the north coordinate of the object that models rectangle to be equal to the coordinate value.
template <typename T, typename T1, typename T2>
T& set_points(T& rectangle, const T1& p1, const T2& p2)
Sets the rectangle to the rectangle fully described by the points p1 and p2.
template <typename T>
coordinate_difference delta(const T& rectangle,
                            orientation_2d)
Returns the delta of the interval specified by orientation_2d of an object that models rectangle.
template <typename T>
manhattan_area_type area(const T& rectangle)
Returns the area of an object that models rectangle.
template <typename T>
coordinate_difference half_perimeter(const T& rectangle)
Returns the length plus width of an object that models rectangle.
template <typename T>
coordinate_difference perimeter(const T& rectangle)
Returns the perimeter length of an object that models rectangle.
template <typename T>
orientation_2d quess_orientation(const T& rectangle)
Returns the orientation in which the rectangle has a longer delta.  Returns HORIZONTAL if the rectangle is a square.
template <typename rectangle_type>
rectangle_type& transform(rectangle_type& rectangle,
                          coordinate_type axis = 0)
Applies transform() on the two points that fully describe the rectangle and sets the rectangle to that described by the result of transforming those points.
template <typename rectangle_type>
rectangle_type& scale_up(rectangle_type& rectangle,
                         unsigned_area_type factor)
Scales up x interval and y interval  of an object that models rectangle by unsigned factor.
template <typename rectangle_type>
rectangle_type& scale_down(rectangle_type& rectangle,
                           unsigned_area_type factor)
Scales down x interval and y interval  of an object that models rectangle by unsigned factor.
template <typename rectangle_type, scaling_type>
rectangle_type& scale(rectangle_type& rectangle,
                      const scaling_type& scaling)
Applies scale() on the two points that fully describe the rectangle and sets the rectangle to that described by the result of transforming those points.
template <typename T>
T& move(T& rectangle, orientation_2d,
        coordinate_difference displacement)
Adds displacement value to interval indicated by orientation_2d of an object that models rectangle.
template <typename rectangle_type, typename point_type>
rectangle_type& convolve(rectangle_type& rectangle,
                         const point_type& point)
Convolves coordinate values of point with x interval and y interval  of an object that models rectangle.
template <typename rectangle_type, typename point_type>
rectangle_type& deconvolve(rectangle_type& rectangle,
                           const point_type& point)
Deconvolves coordinate values of point withx interval and y interval  of an object that models rectangle.
template <typename T1, typename T2>
T1& convolve(T1& a, const T2& b)
Convolves x interval  of b with x interval  of a and convolves y interval  of b with y interval  of a.
template <typename T1, typename T2>
T1& deconvolve(T1& a, const T2& b)
Deconvolves x interval  of b with x interval  of a and deconvolves y interval  of b with y interval  of a.
template <typename T1, typename T2>
T1& reflected_convolve(T1& a, const T2& b)
Reflected convolves y interval  of b with x interval  of a and reflected convolves x interval  of b with y interval  of a.
template <typename T1, typename T2>
T1& reflected_deconvolve(T1& a, const T2& b)
Reflected deconvolves y interval  of b with x interval  of a and reflected deconvolves x interval  of b with y interval  of a.
template <typename T, typename point_type>
coordinate_difference euclidean_distance(const T&,
       const point_type& point, orienation_2d)
Returns the distance from an object that models rectangle to an object that models point along the given orientation.  Returns zero if the point is contained within the rectangle along that orientation.
template <typename T1, typename T2>
coordinate_difference euclidean_distance(const T1& a,
       const T2& b, orienation_2d)
Returns the distance from an object that models rectangle to an object that models rectangle along the given orientation.  Returns zero if the intervals of the rectangles overlap along that orientation.
template <typename T, typename point_type>
coordinate_difference square_euclidean_distance(const T&,
       const point_type& point)
Returns the square of the Euclidean distance between a point and a rectangle.  Returns zero if the point is contained within the rectangle.
template <typename T1, typename T2>
coordinate_difference square_euclidean_distance
       (const T1& a, const T2& b)
Returns the square of the Euclidean distance between rectangles a and b.  Returns zero if the rectangles intersect.
template <typename T, typename point_type>
coordinate_difference manhattan_distance(const T&,
       const point_type& point)
Returns the Manhattan distance between a point and a rectangle.  Returns zero if the point is contained within the rectangle.
template <typename T1, typename T2>
coordinate_difference manhattan_distance(const T1& a,
                                         const T2& b)
Returns the Manhattan distance between rectangles a and b.  Returns zero if the rectangles intersect.
template <typename T, typename point_type>
coordinate_distance euclidean_distance(const T&,
       const point_type& point)
Returns the Euclidean distance between a point and a rectangle.  Returns zero if the point is contained within the rectangle.
template <typename T1, typename T2>
coordinate_distance euclidean_distance(const T1& a,
                                         const T2& b)
Returns the Euclidean distance between rectangles a and b.  Returns zero if the rectangles intersect.
template <typename T1, typename T2>
bool intersects(const T1& a, const T2& b,
                bool consider_touch = true)
Returns true if two objects that model rectangle overlap.  If the consider_touch flag is true touching at the sides or corners is considered overlap.
template <typename T1, typename T2>
bool boundaries_intersect(const T1& a, const T2& b,
                          bool consider_touch = true)
Returns true is two objects that model rectangle partially overlap such that one there is an intersection between the edges of the two rectangles  If the consider_touch flag is true a coordinate is considered contained even if the two rectangles touch only along a side or corner.
template <typename T1, typename T2>
bool abuts(const T1& a, const T2& b,
           direction_2d dir)
Returns true if rectangle b abuts but down not overlap rectangle a on the side of rectangle a specified by dir.
template <typename T1, typename T2>
bool abuts(const T1& a, const T2& b,
           orientation_2d)
Returns true if rectangle b abuts but down not overlap rectangle a on either side of rectangle a specified by the orientation_2d.
template <typename T1, typename T2>
bool abuts(const T1& a, const T2& b)
Returns true if rectangle b abuts but down not overlap rectangle a on any side.
template <typename T1, typename T2>
bool intersect(T1& a, const T2& b, orientation_2d
               bool consider_touch = true)
Sets rectangle a to the intersection of rectangle a and interval b along the orientation_2d and returns true.  If the does not intersect the interval, the rectangle is unchanged and the function returns false.  If the flag consider_touch is true intervals that abut are considered to intersect.
template <typename T1, typename T2>
bool intersect(T1& a, const T2& b,
               bool consider_touch = true)
Sets rectangle a to the intersection of rectangle a and rectangle b and return true.  If the two rectangles do not intersect rectangle a is unchanged and the function returns false.  If the flag consider_touch is true rectangles that abut are considered to intersect.
template <typename T1, typename T2>
T& generalized_intersect(T1& a, const T2& b)
Same as intersect, but if they do not intersect set a to the rectangle between a and b by applying generalized_intersect() on the intervals of the rectangles.
template <typename T>
T& bloat(T& rectangle, coordinate_type)
Bloats x and y intervals of rectangle by coordinate value.
template <typename T>
T& bloat(T& rectangle, direction_2d, coordinate_type)
Bloats side of rectangle specified by direction_2d by coordinate value.
template <typename T>
T& bloat(T& rectangle, orientation_2d, coordinate_type)
Bloats interval of rectangle specified by orientation_2d by coordinate value.
template <typename T>
T& shrink(T& rectangle, coordinate_type)
Shrinks x and y intervals of rectangle by coordinate value.
template <typename T>
T& shrink(T& rectangle, direction_2d, coordinate_type)
Shrinks side of rectangle specified by direction_2d by coordinate value.
template <typename T>
T& shrink(T& rectangle, orientation_2d, coordinate_type)
Shrinks interval of rectangle specified by orientation_2d by coordinate value.
template <typename T1, typename T2>
bool encompass(T1& a, const T2& b)
The x and y intervals of a are set to encompass the x and y intervals of b respectively.
template <typename T, typename point_type>
bool encompass(T& rectangle, const point_type& point)
The x and y intervals of rectangle are set to encompass the x and y coordinates of point respectively.
template <typename T, typename interval_type>
bool encompass(T& rectangle, const interval_type& i,
               orientation_2d)
The interval of rectangle specified by orientation_2d is set to encompass the interval i.
template <typename T, typename point_type>
bool get_corner(point_type& point, const T& rectangle, 
                direction_2d, direction_1d)
Sets point to the corner of the rectangle you reach if you look at its side specified by direction_2d from within the rectangle and turn in the direction_1d direction (low == left, high = right).  Always returns true.

Rectangle Data

The library provides a model of rectangle concept declared template<typename T> rectangle_data where T is the coordinate type.

This data type is used internally when a rectangle is needed and is available to the library user who finds it convenient to use a library rectangle data type instead of providing their own.  The data type is implemented to be convenient to use with the library traits.

Members

geometry_type rectangle_concept
coordinate_type T
interval_type interval_data<T>
rectangle_data(T xl, T yl, T xh, T yh) Constructs a rectangle with four coordinates.
template <typename T1, typename T2>
rectangle_data
(const T1& horizontal_interval,
               const T2& vertical_interval)
Constructs a rectangle with two objects that model interval.
rectangle_data(const rectangle_data& that) Copy construct
rectangle_data& operator=(const rectangle_data& that) Assignment operator.
template <typename T2>
rectangle_data& operator=(const T2& that) const
Assign from an object that is a model of rectangle.
template <typename T2>
bool operator==(const T2& that) const
Compare equality to an object that is a model of rectangle.
template <typename T2>
bool operator!=(const T2& that) const
Compare inequality to an object that is a model of rectangle.
interval_data<T> get(orientation_2d orient) const Get the interval in the given orientation.
template <typename T2>
void set(orientation_2d orient, const T2& value)
Sets the interval in the given orientation to the value of an object that models interval.
 
Copyright: Copyright © Intel Corporation 2008-2010.
License: Distributed under 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)