claw::math::box_2d< T > Class Template Reference

#include <box_2d.hpp>

List of all members.


Detailed Description

template<class T>
class claw::math::box_2d< T >

A rectangle represented by two points in a 2D space.

Author:
Julien Jorge

Definition at line 46 of file box_2d.hpp.


Public Types

typedef T value_type
 The type of the values we store.
typedef coordinate_2d< value_typepoint_type
 The type of the coordinates of the points representing the corners.
typedef box_2d< value_typeself_type
 The type of the current class.

Public Member Functions

 box_2d ()
 Constructor.
 box_2d (const self_type &that)
 Copy constructor.
 box_2d (const rectangle< value_type > &that)
 Constructor from a rectangle.
 box_2d (const point_type &p1, const point_type &p2)
 Constructor from two points.
 box_2d (const value_type &x1, const value_type &y1, const value_type &x2, const value_type &y2)
 Constructor with initialization.
value_type width () const
 Return box' width.
value_type height () const
 Return box' height.
bool operator== (const self_type &vect) const
 Equality operator.
bool operator!= (const self_type &vect) const
 Difference operator.
self_type operator+ (const point_type &vect) const
 Translation.
self_type operator- (const point_type &vect) const
 Translation.
self_typeoperator+= (const point_type &vect)
 Translation.
self_typeoperator-= (const point_type &vect)
 Translation.

Public Attributes

point_type first_point
 The first of the two points, representing one corner.
point_type second_point
 The second of the two points, representing an other corner.

Member Typedef Documentation

template<class T>
typedef T claw::math::box_2d< T >::value_type

The type of the values we store.

Definition at line 50 of file box_2d.hpp.

template<class T>
typedef coordinate_2d<value_type> claw::math::box_2d< T >::point_type

The type of the coordinates of the points representing the corners.

Definition at line 54 of file box_2d.hpp.

template<class T>
typedef box_2d<value_type> claw::math::box_2d< T >::self_type

The type of the current class.

Definition at line 57 of file box_2d.hpp.


Constructor & Destructor Documentation

template<class T>
claw::math::box_2d< T >::box_2d (  )  [inline]

Constructor.

Definition at line 37 of file box_2d.tpp.

00038 {
00039 
00040 } // box_2d::box_2d() [constructor]

template<class T>
claw::math::box_2d< T >::box_2d ( const self_type that  )  [inline]

Copy constructor.

Parameters:
that Box to copy from.

Definition at line 48 of file box_2d.tpp.

00049   : first_point(that.first_point), second_point(that.second_point)
00050 {
00051 
00052 } // box_2d::box_2d() [copy constructor]

template<class T>
claw::math::box_2d< T >::box_2d ( const rectangle< value_type > &  that  )  [inline]

Constructor from a rectangle.

Parameters:
that Rectangle to copy from.

Definition at line 60 of file box_2d.tpp.

00061   : first_point(that.position),
00062     second_point(that.right(), that.bottom())
00063 {
00064 
00065 } // box_2d::box_2d() [constructor from rectangle]

template<class T>
claw::math::box_2d< T >::box_2d ( const point_type p1,
const point_type p2 
) [inline]

Constructor from two points.

Parameters:
p1 The first point.
p2 The second point.

Definition at line 74 of file box_2d.tpp.

00075   : first_point(p1), second_point(p2)
00076 {
00077 
00078 } // box_2d::box_2d() [constructor from coordinates]

template<class T>
claw::math::box_2d< T >::box_2d ( const value_type x1,
const value_type y1,
const value_type x2,
const value_type y2 
) [inline]

Constructor with initialization.

Parameters:
x1 X-coordinate of the first point.
y1 Y-coordinate of the first point.
x2 X-coordinate of the second point.
y2 Y-coordinate of the second point.

Definition at line 89 of file box_2d.tpp.

00091   : first_point(x1, y1), second_point(x2, y2)
00092 {
00093 
00094 } // box_2d::box_2d() [constructor with values]


Member Function Documentation

template<class T>
claw::math::box_2d< T >::value_type claw::math::box_2d< T >::width (  )  const [inline]

Return box' width.

Definition at line 175 of file box_2d.tpp.

References claw::math::box_2d< T >::first_point, claw::math::box_2d< T >::second_point, and claw::math::coordinate_2d< T >::x.

00176 {
00177   if (first_point.x > second_point.x)
00178     return first_point.x - second_point.x + 1;
00179   else
00180     return second_point.x - first_point.x + 1;
00181 } // box_2d::width()

template<class T>
claw::math::box_2d< T >::value_type claw::math::box_2d< T >::height (  )  const [inline]

Return box' height.

Definition at line 189 of file box_2d.tpp.

References claw::math::box_2d< T >::first_point, claw::math::box_2d< T >::second_point, and claw::math::coordinate_2d< T >::y.

00190 {
00191   if (first_point.y > second_point.y)
00192     return first_point.y - second_point.y + 1;
00193   else
00194     return second_point.y - first_point.y + 1;
00195 } // box_2d::height()

template<class T>
bool claw::math::box_2d< T >::operator== ( const self_type that  )  const [inline]

Equality operator.

Parameters:
that Box to compare to.

Definition at line 102 of file box_2d.tpp.

References claw::math::box_2d< T >::first_point, and claw::math::box_2d< T >::second_point.

00103 {
00104   return (first_point == that.first_point)
00105     && (second_point == that.second_point);
00106 } // box_2d::operator==()

template<class T>
bool claw::math::box_2d< T >::operator!= ( const self_type that  )  const [inline]

Difference operator.

Parameters:
that Box to compare to.

Definition at line 114 of file box_2d.tpp.

00115 {
00116   return !( *this == that );
00117 } // box_2d::operator!=()

template<class T>
claw::math::box_2d< T > claw::math::box_2d< T >::operator+ ( const point_type vect  )  const [inline]

Translation.

Parameters:
vect The vector to add to points.

Definition at line 126 of file box_2d.tpp.

References claw::math::box_2d< T >::first_point, and claw::math::box_2d< T >::second_point.

00127 {
00128   return self_type( first_point + vect, second_point + vect );
00129 } // box_2d::operator+()

template<class T>
claw::math::box_2d< T > claw::math::box_2d< T >::operator- ( const point_type vect  )  const [inline]

Translation.

Parameters:
vect The vector to substract to points.

Definition at line 138 of file box_2d.tpp.

References claw::math::box_2d< T >::first_point, and claw::math::box_2d< T >::second_point.

00139 {
00140   return self_type( first_point - vect, second_point - vect );
00141 } // box_2d::operator-()

template<class T>
claw::math::box_2d< T > & claw::math::box_2d< T >::operator+= ( const point_type vect  )  [inline]

Translation.

Parameters:
vect The vector to add to points.

Definition at line 150 of file box_2d.tpp.

References claw::math::box_2d< T >::first_point, and claw::math::box_2d< T >::second_point.

00151 {
00152   first_point += vect;
00153   second_point += vect;
00154 } // box_2d::operator+=()

template<class T>
claw::math::box_2d< T > & claw::math::box_2d< T >::operator-= ( const point_type vect  )  [inline]

Translation.

Parameters:
vect The vector to substract to points.

Definition at line 163 of file box_2d.tpp.

References claw::math::box_2d< T >::first_point, and claw::math::box_2d< T >::second_point.

00164 {
00165   first_point -= vect;
00166   second_point -= vect;
00167 } // box_2d::operator-=()


Member Data Documentation

template<class T>
point_type claw::math::box_2d< T >::first_point

template<class T>
point_type claw::math::box_2d< T >::second_point


The documentation for this class was generated from the following files:

Generated on Thu Jun 26 09:35:07 2008 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.5.6