Claw  1.7.3
Public Types | Public Member Functions | Public Attributes | List of all members
claw::math::box_2d< T > Class Template Reference

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

#include <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.
void set (const value_type &x1, const value_type &y1, const value_type &x2, const value_type &y2)
 Set the coordinates of the two points.
template<typename U >
box_2d< U > cast_value_type_to () const
 Get a copy of the box by converting its members to a given type.
value_type area () const
 Calculate the box's area.
bool includes (const coordinate_2d< value_type > &p) const
 Tell if a point is in a box.
bool includes (const self_type &r) const
 Tell if a box_2d is in a box_2d.
bool intersects (const self_type &r) const
 Tell if there is an intersection of two boxes.
self_type intersection (const self_type &r) const
 Intersection of two box_2ds.
self_type join (const self_type &r) const
 Join two box_2ds.
bool empty () const
 Tell if the box has a dimension equal to zero.
value_type top () const
 Get the y-coordinate of the top edge.
value_type bottom () const
 Get the y-coordinate of the bottom edge.
value_type left () const
 Get the x-coordinate of the left edge.
value_type right () const
 Get the x-coordinate of the right edge.
point_type top_left () const
 Get the coordinate of the top-left corner.
point_type top_right () const
 Get the coordinate of the top-right corner.
point_type bottom_left () const
 Get the coordinate of the bottom-left corner.
point_type bottom_right () const
 Get the coordinate of the bottom-right corner.
void top (const value_type &p)
 Move the top edge at a given position.
void bottom (const value_type &p)
 Move the bottom edge at a given position.
void left (const value_type &p)
 Move the left edge at a given position.
void right (const value_type &p)
 Move the right edge at a given position.
void top_left (const coordinate_2d< value_type > &p)
 Move the top-left corner at a given position.
void top_right (const coordinate_2d< value_type > &p)
 Move the top-right corner at a given position.
void bottom_left (const coordinate_2d< value_type > &p)
 Move the bottom-left corner at a given position.
void bottom_right (const coordinate_2d< value_type > &p)
 Move the bottom-right corner at a given position.
void shift_x (const value_type &d)
 Shift the position of the box on the x-axis.
void shift_y (const value_type &d)
 Shift the position of the box on the y-axis.
value_type width () const
 Return box' width.
value_type height () const
 Return box' height.
coordinate_2d< value_typesize () const
 Get the size of the box_2d.
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.

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.

Constructor & Destructor Documentation

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

Copy constructor.

Parameters
thatBox to copy from.

Definition at line 49 of file box_2d.tpp.

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

Constructor from a rectangle.

Parameters
thatRectangle to copy from.

Definition at line 61 of file box_2d.tpp.

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

Constructor from two points.

Parameters
p1The first point.
p2The second point.

Definition at line 75 of file box_2d.tpp.

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 
)

Constructor with initialization.

Parameters
x1X-coordinate of the first point.
y1Y-coordinate of the first point.
x2X-coordinate of the second point.
y2Y-coordinate of the second point.

Definition at line 90 of file box_2d.tpp.

Member Function Documentation

template<class T >
void claw::math::box_2d< T >::bottom ( const value_type p)

Move the bottom edge at a given position.

Parameters
pThe position.

Definition at line 336 of file box_2d.tpp.

template<class T >
void claw::math::box_2d< T >::bottom_left ( const coordinate_2d< value_type > &  p)

Move the bottom-left corner at a given position.

Parameters
pThe position.

Definition at line 396 of file box_2d.tpp.

References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

template<class T >
void claw::math::box_2d< T >::bottom_right ( const coordinate_2d< value_type > &  p)

Move the bottom-right corner at a given position.

Parameters
pThe position.

Definition at line 409 of file box_2d.tpp.

References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

template<class T >
template<typename U >
claw::math::box_2d< U > claw::math::box_2d< T >::cast_value_type_to ( ) const

Get a copy of the box by converting its members to a given type.

Consider the following code:

box_2d<float> a;

...

box_2d<int> b(a);

The copy constructor will be called, and your compiler should print some warnings in your console. These warnings have a meaning, so we don't wan't to make them disapear by adding explicit type conversion inside the box_2d class nor adding a cast operator that will be used silently by the compiler.

If you really want to convert the type, this method will explicitly cast the member variables.

Definition at line 136 of file box_2d.tpp.

template<class T >
bool claw::math::box_2d< T >::includes ( const coordinate_2d< value_type > &  p) const

Tell if a point is in a box.

Parameters
pThe supposed included point.

Definition at line 160 of file box_2d.tpp.

References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

template<class T >
bool claw::math::box_2d< T >::includes ( const self_type r) const

Tell if a box_2d is in a box_2d.

Parameters
rThe supposed included box_2d.

Definition at line 172 of file box_2d.tpp.

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

template<class T >
claw::math::box_2d< T > claw::math::box_2d< T >::intersection ( const self_type r) const

Intersection of two box_2ds.

Parameters
rThe supposed intersecting box_2d.

Definition at line 196 of file box_2d.tpp.

References CLAW_PRECOND.

template<class T >
bool claw::math::box_2d< T >::intersects ( const self_type r) const

Tell if there is an intersection of two boxes.

Parameters
rThe supposed intersecting box.

Definition at line 183 of file box_2d.tpp.

References claw::math::box_2d< T >::bottom(), claw::math::box_2d< T >::left(), claw::math::box_2d< T >::right(), and claw::math::box_2d< T >::top().

template<class T >
claw::math::box_2d< T > claw::math::box_2d< T >::join ( const self_type r) const

Join two box_2ds.

Parameters
rThe box to join with.
Returns
a box containing *this and r.

Definition at line 218 of file box_2d.tpp.

References claw::math::box_2d< T >::bottom(), claw::math::box_2d< T >::left(), claw::math::box_2d< T >::right(), and claw::math::box_2d< T >::top().

template<class T >
void claw::math::box_2d< T >::left ( const value_type p)

Move the left edge at a given position.

Parameters
pThe position.

Definition at line 347 of file box_2d.tpp.

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

Difference operator.

Parameters
thatBox to compare to.

Definition at line 468 of file box_2d.tpp.

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

Translation.

Parameters
vectThe vector to add to points.

Definition at line 480 of file box_2d.tpp.

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

Translation.

Parameters
vectThe vector to add to points.

Definition at line 504 of file box_2d.tpp.

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

Translation.

Parameters
vectThe vector to substract to points.

Definition at line 492 of file box_2d.tpp.

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

Translation.

Parameters
vectThe vector to substract to points.

Definition at line 517 of file box_2d.tpp.

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

Equality operator.

Parameters
thatBox to compare to.

Definition at line 456 of file box_2d.tpp.

References claw::math::box_2d< T >::bottom(), claw::math::box_2d< T >::left(), claw::math::box_2d< T >::right(), and claw::math::box_2d< T >::top().

template<class T >
void claw::math::box_2d< T >::right ( const value_type p)

Move the right edge at a given position.

Parameters
pThe position.

Definition at line 358 of file box_2d.tpp.

template<class T >
void claw::math::box_2d< T >::set ( const value_type x1,
const value_type y1,
const value_type x2,
const value_type y2 
)

Set the coordinates of the two points.

Parameters
x1X-coordinate of the first point.
y1Y-coordinate of the first point.
x2X-coordinate of the second point.
y2Y-coordinate of the second point.

Definition at line 107 of file box_2d.tpp.

References claw::math::box_2d< T >::set().

Referenced by claw::math::box_2d< T >::set().

template<class T >
void claw::math::box_2d< T >::shift_x ( const value_type d)

Shift the position of the box on the x-axis.

Parameters
dThe movement length.

Definition at line 421 of file box_2d.tpp.

template<class T >
void claw::math::box_2d< T >::shift_y ( const value_type d)

Shift the position of the box on the y-axis.

Parameters
dThe movement length.

Definition at line 433 of file box_2d.tpp.

template<class T >
void claw::math::box_2d< T >::top ( const value_type p)

Move the top edge at a given position.

Parameters
pThe position.

Definition at line 325 of file box_2d.tpp.

template<class T >
void claw::math::box_2d< T >::top_left ( const coordinate_2d< value_type > &  p)

Move the top-left corner at a given position.

Parameters
pThe position.

Definition at line 370 of file box_2d.tpp.

References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

template<class T >
void claw::math::box_2d< T >::top_right ( const coordinate_2d< value_type > &  p)

Move the top-right corner at a given position.

Parameters
pThe position.

Definition at line 383 of file box_2d.tpp.

References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.


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