CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

csRect Class Reference
[Geometry utilities]

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

#include <csrect.h>

Inheritance diagram for csRect:

csSubRect List of all members.

Public Methods

 csRect ()
 Create a empty rectangle.

 csRect (int ixmin, int iymin, int ixmax, int iymax)
 Create a new rectangle.

 csRect (const csRect &copy)
 Copy constructor.

virtual ~csRect ()
 Destructor.

void Intersect (int ixmin, int iymin, int ixmax, int iymax)
 Intersect with another rectangle.

void Intersect (const csRect &other)
 Intersect with another rectangle.

bool Intersects (const csRect &target) const
 Return true if rectangle intersects with target.

void Union (int ixmin, int iymin, int ixmax, int iymax)
 Add a rectangle: find minimal rectangle that embeds both given rectangles.

void Union (const csRect &other)
 Add a rectangle: find minimal rectangle that embeds both given rectangles.

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 Exclude (const csRect &other)
 Same but works on a csRect argument.

void Subtract (const csRect &rect)
 Alternative subtraction: find maximal area of this rectangle that is not covered by argument.

bool IsEmpty () const
 Return true if rectangle is empty.

void MakeEmpty ()
 Make rectangle empty.

void Set (int ixmin, int iymin, int ixmax, int iymax)
 Set rectangle to given ixmin,iymin,ixmax,iymax position.

void Set (const csRect &target)
 Copy rectangle.

void SetPos (int x, int y)
 Set rectangle xmin,ymin position.

void SetSize (int w, int h)
 Set rectangle size.

void Move (int dX, int dY)
 Move rectangle by deltaX, deltaY.

int Width () const
 Return the width of rectangle.

int Height () const
 Return the height of 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.

bool Equal (int ixmin, int iymin, int ixmax, int iymax) const
 Return true if rectangle is the same.

bool Equal (const csRect &other) const
 Same but compare with another csRect.

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

int Area () const
 Return area of this rectangle.

void AddAdjanced (const csRect &rect)
 Add an adjanced rectangle if resulting rectangle will have larger area.

bool operator== (const csRect &rect) const
 Test equality of two rectangles.

bool operator!= (const csRect &rect) const
 Test inequality of two rectangles.

void Extend (int x, int y)
 Extend rectangle so that it will include given point.

void Join (const csRect &rect)
 Joins two rects by their minimum and maximum bounds.

void Outset (int n)
 Expands the whole rect by n units.

void Inset (int n)
 Contracts the whole rect by n units.

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 ClipLine (int &x1, int &y1, int &x2, int &y2)
 Clip a line to make it fit to this rectangle.

bool ClipLineSafe (int &x1, int &y1, int &x2, int &y2)
 Clip a line to make it fit to this rectangle.


Public Attributes

int xmin
 Rectangle bounds.

int ymin
 Rectangle bounds.

int xmax
 Rectangle bounds.

int ymax
 Rectangle bounds.


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.

virtual csRect::~csRect   [virtual]
 

Destructor.


Member Function Documentation

void csRect::AddAdjanced const csRect &    rect
 

Add an adjanced rectangle if resulting rectangle will have larger area.

int csRect::Area   const [inline]
 

Return area of this rectangle.

Definition at line 175 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 152 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 156 of file csrect.h.

bool csRect::Equal const csRect &    other const [inline]
 

Same but compare with another csRect.

Definition at line 164 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 160 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 199 of file csrect.h.

int csRect::Height   const [inline]
 

Return the height of rectangle.

Definition at line 149 of file csrect.h.

Referenced by csComponent::Clear(), and csComponent::ClearZbuffer().

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.

Referenced by csComponent::SetClipRect().

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

Move rectangle by deltaX, deltaY.

Definition at line 142 of file csrect.h.

void csRect::Normalize   [inline]
 

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

Definition at line 168 of file csrect.h.

bool csRect::operator!= const csRect &    rect const [inline]
 

Test inequality of two rectangles.

Definition at line 193 of file csrect.h.

bool csRect::operator== const csRect &    rect const [inline]
 

Test equality of two rectangles.

Definition at line 187 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.

Referenced by csComponent::SetClipRect(), and csGridView::SetViewArea().

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 138 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 146 of file csrect.h.

Referenced by csComponent::Clear(), and csComponent::ClearZbuffer().


Member Data Documentation

int csRect::xmax
 

Rectangle bounds.

Definition at line 57 of file csrect.h.

Referenced by Equal(), Exclude(), Intersect(), csApp::pplSetClipRect(), Set(), csComponent::SetPos(), csComponent::SetRect(), csGridView::SetViewArea(), and Union().

int csRect::xmin
 

Rectangle bounds.

Definition at line 57 of file csrect.h.

Referenced by Equal(), Exclude(), Intersect(), csApp::pplSetClipRect(), Set(), csComponent::SetPos(), csComponent::SetRect(), csComponent::SetSize(), csGridView::SetViewArea(), and Union().

int csRect::ymax
 

Rectangle bounds.

Definition at line 57 of file csrect.h.

Referenced by Equal(), Exclude(), Intersect(), csApp::pplSetClipRect(), Set(), csComponent::SetPos(), csComponent::SetRect(), csGridView::SetViewArea(), and Union().

int csRect::ymin
 

Rectangle bounds.

Definition at line 57 of file csrect.h.

Referenced by Equal(), Exclude(), Intersect(), csApp::pplSetClipRect(), Set(), csComponent::SetPos(), csComponent::SetRect(), csComponent::SetSize(), csGridView::SetViewArea(), and Union().


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