CrystalSpace

Public API Reference

csRect Class Reference
[Geometry utilities]

Rectangle class: simple class for manipulating 2D rectangles. More...

#include <csgeom/csrect.h>

List of all members.

Public Member Functions

void AddAdjacent (const csRect &rect)
 Adds an adjacent rectangle if resulting rectangle will have a larger area.
int Area () const
 Return area of this rectangle.
bool ClipLine (int &x1, int &y1, int &x2, int &y2)
 Clip a line to make it fit to this rectangle.
bool ClipLineGeneral (int &x1, int &y1, int &x2, int &y2)
 This function is the same as ClipLine() except that it doesn't check for two trivial cases (horizontal and vertical lines).
bool ClipLineSafe (int &x1, int &y1, int &x2, int &y2)
 Clip a line to make it fit to this rectangle.
bool Contains (int x, int y) const
 Return true if a point lies within rectangle bounds.
bool ContainsRel (int x, int y) const
 Return true if a relative point lies within rectangle bounds.
 csRect (const csRect &copy)
 Copy constructor.
 csRect (int ixmin, int iymin, int ixmax, int iymax)
 Create a new rectangle.
 csRect ()
 Create a empty rectangle.
bool Equal (const csRect &other) const
 Same but compare with another csRect.
bool Equal (int ixmin, int iymin, int ixmax, int iymax) const
 Return true if rectangle is the same.
void Exclude (const csRect &other)
 Same but works on a csRect argument.
void Exclude (int ixmin, int iymin, int ixmax, int iymax)
 Subtract rectangle: find the minimal rectangle which embeds all parts of this rectangle which are not covered by given rectangle.
void Extend (int x, int y)
 Extend rectangle so that it will include given point.
int Height () const
 Return the height of rectangle.
void Inset (int n)
 Contracts the whole rect by n units.
void Intersect (const csRect &other)
 Intersect with another rectangle.
void Intersect (int ixmin, int iymin, int ixmax, int iymax)
 Intersect with another rectangle.
bool Intersects (const csRect &target) const
 Return true if rectangle intersects with target.
bool IsEmpty () const
 Return true if rectangle is empty.
void Join (const csRect &rect)
 Joins two rects by their minimum and maximum bounds.
void MakeEmpty ()
 Make rectangle empty.
void Move (int dX, int dY)
 Move rectangle by deltaX, deltaY.
void Normalize ()
 Normalize a rectangle such that xmin <= xmax and ymin <= ymax.
bool operator!= (const csRect &rect) const
 Test inequality of two rectangles.
bool operator== (const csRect &rect) const
 Test equality of two rectangles.
void Outset (int n)
 Expands the whole rect by n units.
void Set (const csRect &target)
 Copy rectangle.
void Set (int ixmin, int iymin, int ixmax, int iymax)
 Set rectangle to given ixmin,iymin,ixmax,iymax position.
void SetPos (int x, int y)
 Set rectangle xmin,ymin position.
void SetSize (int w, int h)
 Set rectangle size.
void Subtract (const csRect &rect)
 Alternative subtraction: find maximal area of this rectangle that is not covered by argument.
void Union (const csRect &other)
 Add a rectangle: find minimal rectangle that embeds both given rectangles.
void Union (int ixmin, int iymin, int ixmax, int iymax)
 Add a rectangle: find minimal rectangle that embeds both given rectangles.
int Width () const
 Return the width of rectangle.
 ~csRect ()
 Destructor.

Public Attributes

int xmax
int xmin
 Rectangle bounds.
int ymax
int ymin


Detailed Description

Rectangle class: simple class for manipulating 2D rectangles.

This class is somewhat similar to Box, but uses integer coordinates.

Example of a rectangle (xmin = 0, ymin = 0, xmax = 3, ymax = 2):

     0  1  2  3  4 ...
     |  |  |  |  |  |
 0 --@@@@@--+--+--
     @//|//|//@  |  |
 1 --@--+--+--@--+--+--
     @//|//|//@  |  |
 2 --@@@@@--+--+--
     |  |  |  |  |  |
 3 --+--+--+--+--+--+--
     |  |  |  |  |  |
...--+--+--+--+--+--+--
 
Vertical line 'X=3' and horizontal line 'Y=2' does NOT belong to the rectangle.

Definition at line 53 of file csrect.h.


Constructor & Destructor Documentation

csRect::csRect (  ) 

Create a empty rectangle.

csRect::csRect ( int  ixmin,
int  iymin,
int  ixmax,
int  iymax 
)

Create a new rectangle.

csRect::csRect ( const csRect copy  ) 

Copy constructor.

csRect::~csRect (  ) 

Destructor.


Member Function Documentation

void csRect::AddAdjacent ( const csRect rect  ) 

Adds an adjacent rectangle if resulting rectangle will have a larger area.

int csRect::Area (  )  const [inline]

Return area of this rectangle.

Definition at line 181 of file csrect.h.

bool csRect::ClipLine ( int &  x1,
int &  y1,
int &  x2,
int &  y2 
)

Clip a line to make it fit to this rectangle.

This algorithm is inclusive (the clipped line will touch the borders). If this function returns false the line is fully outside the rectangle. Note: this function is only guaranteed to work correctly if the lines are not longer than an integer that fits in 16 bits.

bool csRect::ClipLineGeneral ( int &  x1,
int &  y1,
int &  x2,
int &  y2 
)

This function is the same as ClipLine() except that it doesn't check for two trivial cases (horizontal and vertical lines).

It also doesn't check if the line is fully outside the box. Note: this function is only guaranteed to work correctly if the lines are not longer than an integer that fits in 16 bits.

bool csRect::ClipLineSafe ( int &  x1,
int &  y1,
int &  x2,
int &  y2 
)

Clip a line to make it fit to this rectangle.

This algorithm is inclusive (the clipped line will touch the borders). If this function returns false the line is fully outside the rectangle. Note: this function is guaranteed to work correctly even if the integer coordinates of the line are very big.

bool csRect::Contains ( int  x,
int  y 
) const [inline]

Return true if a point lies within rectangle bounds.

Definition at line 158 of file csrect.h.

bool csRect::ContainsRel ( int  x,
int  y 
) const [inline]

Return true if a relative point lies within rectangle bounds.

Definition at line 162 of file csrect.h.

bool csRect::Equal ( const csRect other  )  const [inline]

Same but compare with another csRect.

Definition at line 170 of file csrect.h.

References xmax, xmin, ymax, and ymin.

bool csRect::Equal ( int  ixmin,
int  iymin,
int  ixmax,
int  iymax 
) const [inline]

Return true if rectangle is the same.

Definition at line 166 of file csrect.h.

void csRect::Exclude ( const csRect other  )  [inline]

Same but works on a csRect argument.

Definition at line 102 of file csrect.h.

References xmax, xmin, ymax, and ymin.

void csRect::Exclude ( int  ixmin,
int  iymin,
int  ixmax,
int  iymax 
)

Subtract rectangle: find the minimal rectangle which embeds all parts of this rectangle which are not covered by given rectangle.

If rectangle is fully covered by argument, it becomes empty.

void csRect::Extend ( int  x,
int  y 
) [inline]

Extend rectangle so that it will include given point.

Definition at line 208 of file csrect.h.

int csRect::Height (  )  const [inline]

Return the height of rectangle.

Definition at line 155 of file csrect.h.

void csRect::Inset ( int  n  ) 

Contracts the whole rect by n units.

void csRect::Intersect ( const csRect other  )  [inline]

Intersect with another rectangle.

Definition at line 75 of file csrect.h.

References xmax, xmin, ymax, and ymin.

void csRect::Intersect ( int  ixmin,
int  iymin,
int  ixmax,
int  iymax 
)

Intersect with another rectangle.

bool csRect::Intersects ( const csRect target  )  const

Return true if rectangle intersects with target.

bool csRect::IsEmpty (  )  const [inline]

Return true if rectangle is empty.

Definition at line 112 of file csrect.h.

void csRect::Join ( const csRect rect  ) 

Joins two rects by their minimum and maximum bounds.

void csRect::MakeEmpty (  )  [inline]

Make rectangle empty.

Definition at line 116 of file csrect.h.

void csRect::Move ( int  dX,
int  dY 
) [inline]

Move rectangle by deltaX, deltaY.

Definition at line 148 of file csrect.h.

void csRect::Normalize (  )  [inline]

Normalize a rectangle such that xmin <= xmax and ymin <= ymax.

Definition at line 174 of file csrect.h.

bool csRect::operator!= ( const csRect rect  )  const [inline]

Test inequality of two rectangles.

Definition at line 202 of file csrect.h.

bool csRect::operator== ( const csRect rect  )  const [inline]

Test equality of two rectangles.

Definition at line 196 of file csrect.h.

void csRect::Outset ( int  n  ) 

Expands the whole rect by n units.

void csRect::Set ( const csRect target  )  [inline]

Copy rectangle.

Definition at line 127 of file csrect.h.

References xmax, xmin, ymax, and ymin.

void csRect::Set ( int  ixmin,
int  iymin,
int  ixmax,
int  iymax 
) [inline]

Set rectangle to given ixmin,iymin,ixmax,iymax position.

Definition at line 120 of file csrect.h.

void csRect::SetPos ( int  x,
int  y 
) [inline]

Set rectangle xmin,ymin position.

Definition at line 134 of file csrect.h.

void csRect::SetSize ( int  w,
int  h 
) [inline]

Set rectangle size.

Definition at line 144 of file csrect.h.

void csRect::Subtract ( const csRect rect  ) 

Alternative subtraction: find maximal area of this rectangle that is not covered by argument.

void csRect::Union ( const csRect other  )  [inline]

Add a rectangle: find minimal rectangle that embeds both given rectangles.

Definition at line 91 of file csrect.h.

References xmax, xmin, ymax, and ymin.

void csRect::Union ( int  ixmin,
int  iymin,
int  ixmax,
int  iymax 
)

Add a rectangle: find minimal rectangle that embeds both given rectangles.

int csRect::Width (  )  const [inline]

Return the width of rectangle.

Definition at line 152 of file csrect.h.


Member Data Documentation

Rectangle bounds.

Definition at line 57 of file csrect.h.

Referenced by Equal(), Exclude(), Intersect(), Set(), and Union().


The documentation for this class was generated from the following file:
Generated for Crystal Space 1.2.1 by doxygen 1.5.3