ScummVM
Common::Rect Struct Reference

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

#include <rect.h>

Inheritance diagram for Common::Rect:

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. More...
 
bool contains (const Point &p) const
 Check if given point is inside this rectangle. More...
 
bool contains (const Rect &r) const
 Check if the given rect is contained inside this rectangle. More...
 
bool equals (const Rect &r) const
 Check if the given rect is equal to this one. More...
 
bool intersects (const Rect &r) const
 Check if given rectangle intersects with this rectangle. More...
 
Rect findIntersectingRect (const Rect &r) const
 Find the intersecting rectangle between this rectangle and the given rectangle. More...
 
void extend (const Rect &r)
 Extend this rectangle so that it contains r. More...
 
void grow (int16 offset)
 Extend this rectangle in all four directions by the given number of pixels. More...
 
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. More...
 

Public Attributes

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

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

◆ Rect() [1/3]

Common::Rect::Rect ( )
inline

Definition at line 99 of file rect.h.

◆ Rect() [2/3]

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

Definition at line 100 of file rect.h.

◆ Rect() [3/3]

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

Definition at line 101 of file rect.h.

Member Function Documentation

◆ center()

static Rect Common::Rect::center ( int16  cx,
int16  cy,
int16  w,
int16  h 
)
inlinestatic

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.

◆ clip() [1/2]

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

Definition at line 213 of file rect.h.

◆ clip() [2/2]

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

Definition at line 230 of file rect.h.

◆ contains() [1/3]

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

Check if given position is inside this rectangle.

Parameters
xthe horizontal position to check
ythe vertical position to check
Returns
true if the given position is inside this rectangle, false otherwise

Definition at line 126 of file rect.h.

◆ contains() [2/3]

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

Check if given point is inside this rectangle.

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

Definition at line 137 of file rect.h.

◆ contains() [3/3]

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

Check if the given rect is contained inside this rectangle.

Parameters
rThe rectangle to check
Returns
true if the given rect is inside, false otherwise

Definition at line 148 of file rect.h.

◆ debugPrint()

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

Definition at line 258 of file rect.h.

◆ equals()

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

Check if the given rect is equal to this one.

Parameters
rThe rectangle to check
Returns
true if the given rect is equal, false otherwise

Definition at line 159 of file rect.h.

◆ extend()

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

Extend this rectangle so that it contains r.

Parameters
rthe rectangle to extend by

Definition at line 194 of file rect.h.

◆ findIntersectingRect()

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

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

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

Definition at line 182 of file rect.h.

◆ grow()

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

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

Parameters
offsetthe size to grow by

Definition at line 206 of file rect.h.

◆ height()

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

Definition at line 108 of file rect.h.

◆ intersects()

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

Check if given rectangle intersects with this rectangle.

Parameters
rthe 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.

◆ isEmpty()

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

Definition at line 234 of file rect.h.

◆ isValidRect()

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

Definition at line 238 of file rect.h.

◆ moveTo() [1/2]

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

Definition at line 242 of file rect.h.

◆ moveTo() [2/2]

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

Definition at line 254 of file rect.h.

◆ operator!=()

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

Definition at line 105 of file rect.h.

◆ operator==()

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

Definition at line 104 of file rect.h.

◆ setHeight()

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

Definition at line 114 of file rect.h.

◆ setWidth()

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

Definition at line 110 of file rect.h.

◆ translate()

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

Definition at line 249 of file rect.h.

◆ width()

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

Definition at line 107 of file rect.h.

Member Data Documentation

◆ bottom

int16 Common::Rect::bottom

Definition at line 97 of file rect.h.

◆ left

int16 Common::Rect::left

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

Definition at line 96 of file rect.h.

◆ right

int16 Common::Rect::right

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

Definition at line 97 of file rect.h.

◆ top

int16 Common::Rect::top

Definition at line 96 of file rect.h.


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