BoundingBox Class Reference

This file describes the BoundingBox class. This class provides the methods needed to manage a rectangle containing a shape.
. More...

#include <boundingbox.h>

List of all members.

Public Member Functions

 BoundingBox ()
 Default constructor.
 BoundingBox (int x, int y, int w, int h)
 Constructor from a point coordinates, a width and a height.
 ~BoundingBox ()
 Destrutor of the BoundingBox.
int GetOriginX () const
 Return the abscissa of the origin.
int GetOriginY () const
 Return the ordinate of the origin.
int GetEndX () const
 Return the abscissa of the end point.
int GetEndY () const
 Return the ordinate of the end point.
int GetWidth () const
 Return the width of the box.
int GetHeight () const
 Return the height of the box.
void SetOriginX (int pos)
 Set the abscissa of the origin.
void SetOriginY (int pos)
 Set the ordinate of the origin.
void SetEndX (int pos)
 Set the abscissa of the end point.
void SetEndY (int pos)
 Set the ordinate of the end point.
void MakeSquare ()
 Forces the height and the width to be equal to the smallest of the two (so the box is square).
void Display () const
 Display the coordinates of the BoundingBox.
void SetCoord (int x1, int y1, int x2, int y2)
 Initialize the BoundingBox from its 2 corners.
void SetBoundingBox (int x1, int y1, int w, int h)
 Initialize the BoundingBox from a corner and its size.
bool IsInside (int x, int y, bool border=true) const
 Test if a given point falls within the BoundingBox.
bool IsInside (const BoundingBox &bb) const
 Test if another BoundingBox bb is inside the BoundingBox.
void Move (int dx, int dy)
 Move the boundingBox.
bool IsEmpty () const
 Test if the BoundingBox is empty, i.e. if its width or its height are non zero.
void Validate ()
 Reorder the parameters of the BoundingBox if it has a negative width and/or a negative height.
BoundingBox operator| (const BoundingBox &bb) const
 Overload for the operator | .
.
BoundingBoxoperator|= (const BoundingBox &bb)
 Overload for the operator |= .
Modify in-place our BoundingBox.
bool operator== (const BoundingBox &bb)
 Overload for the operator == : test if 2 BoundingBoxes are identical.
BoundingBoxoperator= (const BoundingBox &bb)
 Assignment operator.

Protected Attributes

int m_x1
 abscissa of the origin (top left)
int m_y1
 ordinate of the origin (top left)
int m_x2
 abscissa of the end point (bottom right)
int m_y2
 ordinate of the end point (bottom right)


Detailed Description

This file describes the BoundingBox class. This class provides the methods needed to manage a rectangle containing a shape.
.

It is used in the Shape class to store the smallest rectangle able to contain a given shape. A BoundingBox can be characterized by its 2 opposite corners:

Definition at line 24 of file boundingbox.h.


Constructor & Destructor Documentation

BoundingBox::BoundingBox (  ) 

Default constructor.

Definition at line 13 of file boundingbox.cpp.

References m_x1, m_x2, m_y1, and m_y2.

BoundingBox::BoundingBox ( int  x,
int  y,
int  w,
int  h 
)

Constructor from a point coordinates, a width and a height.

Parameters:
x,: abscissa of the origin
y,: ordinate of the origin
w,: width of the box
h,: height of the box

Definition at line 21 of file boundingbox.cpp.

References SetBoundingBox().

Here is the call graph for this function:

BoundingBox::~BoundingBox (  ) 

Destrutor of the BoundingBox.

Definition at line 26 of file boundingbox.cpp.


Member Function Documentation

int BoundingBox::GetOriginX (  )  const

Return the abscissa of the origin.

Returns:
abscissa of the origin

Definition at line 198 of file boundingbox.cpp.

References m_x1.

Referenced by Rectangle::Draw(), Shape::GetCenterX(), and Rectangle::SumValues().

Here is the caller graph for this function:

int BoundingBox::GetOriginY (  )  const

Return the ordinate of the origin.

Returns:
ordinate of the origin

Definition at line 202 of file boundingbox.cpp.

References m_y1.

Referenced by Rectangle::Draw(), Shape::GetCenterY(), and Rectangle::SumValues().

Here is the caller graph for this function:

int BoundingBox::GetEndX (  )  const

Return the abscissa of the end point.

Returns:
abscissa of the end point

Definition at line 206 of file boundingbox.cpp.

References m_x2.

Referenced by Rectangle::SumValues().

Here is the caller graph for this function:

int BoundingBox::GetEndY (  )  const

Return the ordinate of the end point.

Returns:
ordinate of the end point

Definition at line 210 of file boundingbox.cpp.

References m_y2.

Referenced by Rectangle::SumValues().

Here is the caller graph for this function:

int BoundingBox::GetWidth (  )  const

Return the width of the box.

Returns:
width of the box

Definition at line 50 of file boundingbox.cpp.

References m_x1, and m_x2.

Referenced by Rectangle::Draw(), Shape::GetCenterX(), Shape::GetWidth(), and MakeSquare().

Here is the caller graph for this function:

int BoundingBox::GetHeight (  )  const

Return the height of the box.

Returns:
height of the box

Definition at line 59 of file boundingbox.cpp.

References m_y1, and m_y2.

Referenced by Rectangle::Draw(), Shape::GetCenterY(), Shape::GetHeight(), and MakeSquare().

Here is the caller graph for this function:

void BoundingBox::SetOriginX ( int  pos  ) 

Set the abscissa of the origin.

Definition at line 214 of file boundingbox.cpp.

References m_x1.

void BoundingBox::SetOriginY ( int  pos  ) 

Set the ordinate of the origin.

Definition at line 218 of file boundingbox.cpp.

References m_y1.

void BoundingBox::SetEndX ( int  pos  ) 

Set the abscissa of the end point.

Definition at line 222 of file boundingbox.cpp.

References m_x2.

Referenced by Shape::ModifyEndShape().

Here is the caller graph for this function:

void BoundingBox::SetEndY ( int  pos  ) 

Set the ordinate of the end point.

Definition at line 226 of file boundingbox.cpp.

References m_y2.

Referenced by Shape::ModifyEndShape().

Here is the caller graph for this function:

void BoundingBox::MakeSquare (  ) 

Forces the height and the width to be equal to the smallest of the two (so the box is square).

Definition at line 94 of file boundingbox.cpp.

References GetHeight(), GetWidth(), m_x1, m_x2, m_y1, and m_y2.

Here is the call graph for this function:

void BoundingBox::Display (  )  const

Display the coordinates of the BoundingBox.

Definition at line 30 of file boundingbox.cpp.

References m_x1, m_x2, m_y1, and m_y2.

void BoundingBox::SetCoord ( int  x1,
int  y1,
int  x2,
int  y2 
)

Initialize the BoundingBox from its 2 corners.

Parameters:
x1,y1 : Coordinates of the first corner
x2,y2 : Coordinates of the second corner

Definition at line 86 of file boundingbox.cpp.

References m_x1, m_x2, m_y1, and m_y2.

Referenced by Shape::Init().

Here is the caller graph for this function:

void BoundingBox::SetBoundingBox ( int  x1,
int  y1,
int  w,
int  h 
)

Initialize the BoundingBox from a corner and its size.

Parameters:
x1 : Abscissa of the 1st corner
y1 : Ordinate of the 1st corner
w : width of the BoundingBox
h : height of the BoundingBox

Definition at line 42 of file boundingbox.cpp.

References m_x1, m_x2, m_y1, and m_y2.

Referenced by BoundingBox().

Here is the caller graph for this function:

bool BoundingBox::IsInside ( int  x,
int  y,
bool  border = true 
) const

Test if a given point falls within the BoundingBox.

Parameters:
x,y : coordinates of the point to test
border : if border is true, also include the border as part of the BoundingBox definition
Returns:
true if the point is inside the BoundingBox, false otherwise

Definition at line 120 of file boundingbox.cpp.

References m_x1, m_x2, m_y1, and m_y2.

Referenced by Rectangle::IsInside().

Here is the caller graph for this function:

bool BoundingBox::IsInside ( const BoundingBox bb  )  const

Test if another BoundingBox bb is inside the BoundingBox.

Parameters:
bb : BoundingBox to be tested
Returns:
true if 'bb' is inside, false otherwise

Definition at line 138 of file boundingbox.cpp.

References m_x1, m_x2, m_y1, and m_y2.

void BoundingBox::Move ( int  dx,
int  dy 
)

Move the boundingBox.

Parameters:
dx : delta by which to move the box along X
dy : delta by which to move the box along Y

Definition at line 112 of file boundingbox.cpp.

References m_x1, m_x2, m_y1, and m_y2.

bool BoundingBox::IsEmpty (  )  const

Test if the BoundingBox is empty, i.e. if its width or its height are non zero.

Returns:
true if empty, false otherwise

Definition at line 36 of file boundingbox.cpp.

References m_x1, m_x2, m_y1, and m_y2.

Referenced by Shape::Validate().

Here is the caller graph for this function:

void BoundingBox::Validate (  ) 

Reorder the parameters of the BoundingBox if it has a negative width and/or a negative height.

Definition at line 68 of file boundingbox.cpp.

References m_x1, m_x2, m_y1, and m_y2.

Referenced by Shape::Validate().

Here is the caller graph for this function:

BoundingBox BoundingBox::operator| ( const BoundingBox bb  )  const

Overload for the operator | .
.

Parameters:
bb boundingBox to compare with
Returns:
a new BoundingBox with a size that of the smallest BoundingBox containing both of the input BoundingBoxes.

Definition at line 146 of file boundingbox.cpp.

References m_x1, m_x2, m_y1, and m_y2.

BoundingBox & BoundingBox::operator|= ( const BoundingBox bb  ) 

Overload for the operator |= .
Modify in-place our BoundingBox.

Parameters:
bb BoundingBox to compare
Returns:
a reference toward our BoundingBox which should now be of a size of the smallest BoundingBox containing both of the input BoundingBoxes

Definition at line 175 of file boundingbox.cpp.

bool BoundingBox::operator== ( const BoundingBox bb  ) 

Overload for the operator == : test if 2 BoundingBoxes are identical.

Parameters:
bb BoundingBox to compare
Returns:
true if both BoundingBoxes are equal, false otherwise

Definition at line 181 of file boundingbox.cpp.

References m_x1, m_y1, and m_y2.

BoundingBox & BoundingBox::operator= ( const BoundingBox bb  ) 

Assignment operator.

Parameters:
bb BoundingBox to copy from
Returns:
copied BoundingBox

Definition at line 189 of file boundingbox.cpp.

References m_x1, m_x2, m_y1, and m_y2.


Member Data Documentation

int BoundingBox::m_x1 [protected]

int BoundingBox::m_y1 [protected]

int BoundingBox::m_x2 [protected]

abscissa of the end point (bottom right)

Definition at line 59 of file boundingbox.h.

Referenced by BoundingBox(), Display(), GetEndX(), GetWidth(), IsEmpty(), IsInside(), MakeSquare(), Move(), operator=(), operator|(), SetBoundingBox(), SetCoord(), SetEndX(), and Validate().

int BoundingBox::m_y2 [protected]

ordinate of the end point (bottom right)

Definition at line 63 of file boundingbox.h.

Referenced by BoundingBox(), Display(), GetEndY(), GetHeight(), IsEmpty(), IsInside(), MakeSquare(), Move(), operator=(), operator==(), operator|(), SetBoundingBox(), SetCoord(), SetEndY(), and Validate().


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

Generated on Tue Sep 13 10:10:22 2011 for DrawQt by  doxygen 1.5.6