ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

Simple class for handling a rectangular zone. More...

#include <rect.h>

List of all members.

Public Member Functions

 Rect ()
 Rect (int16 w, int16 h)
 Rect (int16 x1, int16 y1, int16 x2, int16 y2)
bool operator== (const Rect &rhs) const
bool operator!= (const Rect &rhs) const
int16 width () const
int16 height () const
void setWidth (int16 aWidth)
void setHeight (int16 aHeight)
bool contains (int16 x, int16 y) const
 Check if given position is inside this rectangle.
bool contains (const Point &p) const
 Check if given point is inside this rectangle.
bool contains (const Rect &r) const
 Check if the given rect is contained inside this rectangle.
bool equals (const Rect &r) const
 Check if the given rect is equal to this one.
bool intersects (const Rect &r) const
 Check if given rectangle intersects with this rectangle.
Rect findIntersectingRect (const Rect &r) const
 Find the intersecting rectangle between this rectangle and the given rectangle.
void extend (const Rect &r)
 Extend this rectangle so that it contains r.
void grow (int16 offset)
 Extend this rectangle in all four directions by the given number of pixels.
void clip (const Rect &r)
void clip (int16 maxw, int16 maxh)
bool isEmpty () const
bool isValidRect () const
void moveTo (int16 x, int16 y)
void translate (int16 dx, int16 dy)
void moveTo (const Point &p)
void debugPrint (int debuglevel=0, const char *caption="Rect:") const

Static Public Member Functions

static Rect center (int16 cx, int16 cy, int16 w, int16 h)
 Create a rectangle around the given center.

Public Attributes

int16 top
int16 left
 The point at the top left of the rectangle (part of the rect).
int16 bottom
int16 right
 The point at the bottom right of the rectangle (not part of the rect).

Detailed Description

Simple class for handling a rectangular zone.

Note: This implementation is built around the assumption that (top,left) is part of the rectangle, but (bottom,right) is not. This is reflected in various methods, including contains(), intersects() and others.

Another very wide spread approach to rectangle classes treats (bottom,right) also as a part of the rectangle.

Conceptually, both are sound, but the approach we use saves many intermediate computations (like computing the height in our case is done by doing this: height = bottom - top; while in the alternate system, it would be height = bottom - top + 1;

When writing code using our Rect class, always keep this principle in mind!

Definition at line 95 of file rect.h.


Constructor & Destructor Documentation

Common::Rect::Rect (  )  [inline]

Definition at line 99 of file rect.h.

Common::Rect::Rect ( int16  w,
int16  h 
) [inline]

Definition at line 100 of file rect.h.

Common::Rect::Rect ( int16  x1,
int16  y1,
int16  x2,
int16  y2 
) [inline]

Definition at line 101 of file rect.h.


Member Function Documentation

static Rect Common::Rect::center ( int16  cx,
int16  cy,
int16  w,
int16  h 
) [inline, static]

Create a rectangle around the given center.

Note:
the center point is rounded up and left when given an odd width and height

Definition at line 266 of file rect.h.

void Common::Rect::clip ( const Rect r  )  [inline]

Definition at line 213 of file rect.h.

void Common::Rect::clip ( int16  maxw,
int16  maxh 
) [inline]

Definition at line 230 of file rect.h.

bool Common::Rect::contains ( const Point p  )  const [inline]

Check if given point is inside this rectangle.

Parameters:
p the point to check
Returns:
true if the given point is inside this rectangle, false otherwise

Definition at line 137 of file rect.h.

bool Common::Rect::contains ( const Rect r  )  const [inline]

Check if the given rect is contained inside this rectangle.

Parameters:
r The rectangle to check
Returns:
true if the given rect is inside, false otherwise

Definition at line 148 of file rect.h.

bool Common::Rect::contains ( int16  x,
int16  y 
) const [inline]

Check if given position is inside this rectangle.

Parameters:
x the horizontal position to check
y the vertical position to check
Returns:
true if the given position is inside this rectangle, false otherwise

Definition at line 126 of file rect.h.

void Common::Rect::debugPrint ( int  debuglevel = 0,
const char *  caption = "Rect:" 
) const [inline]

Definition at line 258 of file rect.h.

bool Common::Rect::equals ( const Rect r  )  const [inline]

Check if the given rect is equal to this one.

Parameters:
r The rectangle to check
Returns:
true if the given rect is equal, false otherwise

Definition at line 159 of file rect.h.

void Common::Rect::extend ( const Rect r  )  [inline]

Extend this rectangle so that it contains r.

Parameters:
r the rectangle to extend by

Definition at line 194 of file rect.h.

Rect Common::Rect::findIntersectingRect ( const Rect r  )  const [inline]

Find the intersecting rectangle between this rectangle and the given rectangle.

Parameters:
r the intersecting rectangle
Returns:
the intersection of the rectangles or an empty rectangle if not intersecting

Definition at line 182 of file rect.h.

void Common::Rect::grow ( int16  offset  )  [inline]

Extend this rectangle in all four directions by the given number of pixels.

Parameters:
offset the size to grow by

Definition at line 206 of file rect.h.

int16 Common::Rect::height (  )  const [inline]

Definition at line 108 of file rect.h.

bool Common::Rect::intersects ( const Rect r  )  const [inline]

Check if given rectangle intersects with this rectangle.

Parameters:
r the rectangle to check
Returns:
true if the given rectangle has a non-empty intersection with this rectangle, false otherwise

Definition at line 171 of file rect.h.

bool Common::Rect::isEmpty (  )  const [inline]

Definition at line 234 of file rect.h.

bool Common::Rect::isValidRect (  )  const [inline]

Definition at line 238 of file rect.h.

void Common::Rect::moveTo ( const Point p  )  [inline]

Definition at line 254 of file rect.h.

void Common::Rect::moveTo ( int16  x,
int16  y 
) [inline]

Definition at line 242 of file rect.h.

bool Common::Rect::operator!= ( const Rect rhs  )  const [inline]

Definition at line 105 of file rect.h.

bool Common::Rect::operator== ( const Rect rhs  )  const [inline]

Definition at line 104 of file rect.h.

void Common::Rect::setHeight ( int16  aHeight  )  [inline]

Definition at line 114 of file rect.h.

void Common::Rect::setWidth ( int16  aWidth  )  [inline]

Definition at line 110 of file rect.h.

void Common::Rect::translate ( int16  dx,
int16  dy 
) [inline]

Definition at line 249 of file rect.h.

int16 Common::Rect::width (  )  const [inline]

Definition at line 107 of file rect.h.


Member Data Documentation

Definition at line 97 of file rect.h.

The point at the top left of the rectangle (part of the rect).

Definition at line 96 of file rect.h.

The point at the bottom right of the rectangle (not part of the rect).

Definition at line 97 of file rect.h.

Definition at line 96 of file rect.h.


The documentation for this struct was generated from the following file:


Generated on Sat Jan 12 2019 05:04:15 for ResidualVM by doxygen 1.7.1
curved edge   curved edge