ScummVM API documentation
Common::RectBase< T, ConcreteRect, ConcretePoint > Struct Template Reference

#include <rect.h>

Public Member Functions

constexpr RectBase (T w, T h)
 
 RectBase (const ConcretePoint &topLeft, const ConcretePoint &bottomRight)
 
constexpr RectBase (const ConcretePoint &topLeft, T w, T h)
 
 RectBase (T x1, T y1, T x2, T y2)
 
bool operator== (const ConcreteRect &rhs) const
 
bool operator!= (const ConcreteRect &rhs) const
 
ConcretePoint origin () const
 
width () const
 
height () const
 
void setWidth (T aWidth)
 
void setHeight (T aHeight)
 
void setRect (T newLeft, T newTop, T newRight, T newBottom)
 
bool contains (T x, T y) const
 
bool contains (const ConcretePoint &p) const
 
bool contains (const ConcreteRect &r) const
 
bool equals (const ConcreteRect &r) const
 
bool intersects (const ConcreteRect &r) const
 
ConcreteRect findIntersectingRect (const ConcreteRect &r) const
 
void extend (const ConcreteRect &r)
 
void grow (T offset)
 
void clip (const ConcreteRect &r)
 
void clip (T maxw, T maxh)
 
void setEmpty ()
 
bool isEmpty () const
 
bool isValidRect () const
 
void moveTo (T x, T y)
 
void translate (T dx, T dy)
 
void moveTo (const ConcretePoint &p)
 
bool constrain (const ConcreteRect &o)
 
bool constrain (T &x, T &y, T w, T h) const
 
void debugPrint (int debuglevel=0, const char *caption="Rect:") const
 
void debugPrintC (int debuglevel, uint32 debugChannel, const char *caption="Rect:") const
 
String toString () const
 
ConcretePoint center () const
 

Static Public Member Functions

static ConcreteRect center (T cx, T cy, T w, T h)
 
static bool getBlitRect (ConcretePoint &dst, ConcreteRect &rect, const ConcreteRect &clip)
 

Public Attributes

top
 
left
 
bottom
 
right
 

Detailed Description

template<typename T, typename ConcreteRect, typename ConcretePoint>
struct Common::RectBase< T, ConcreteRect, ConcretePoint >

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 widespread 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!

Constructor & Destructor Documentation

◆ RectBase() [1/4]

template<typename T, typename ConcreteRect, typename ConcretePoint>
constexpr Common::RectBase< T, ConcreteRect, ConcretePoint >::RectBase ( w,
h 
)
inline

Create a rectangle with the top-left corner at position (0, 0) and the given width w and height h.

◆ RectBase() [2/4]

template<typename T, typename ConcreteRect, typename ConcretePoint>
Common::RectBase< T, ConcreteRect, ConcretePoint >::RectBase ( const ConcretePoint &  topLeft,
const ConcretePoint &  bottomRight 
)
inline

Create a rectangle with the top-left corner at the position topLeft and the bottom-right corner at the position bottomRight.

The topLeft x value must be greater or equal bottomRight x and topLeft y must be greater or equal bottomRight y.

◆ RectBase() [3/4]

template<typename T, typename ConcreteRect, typename ConcretePoint>
constexpr Common::RectBase< T, ConcreteRect, ConcretePoint >::RectBase ( const ConcretePoint &  topLeft,
w,
h 
)
inline

Create a rectangle with the top-left corner at the position topLeft and the given width w and height h.

◆ RectBase() [4/4]

template<typename T, typename ConcreteRect, typename ConcretePoint>
Common::RectBase< T, ConcreteRect, ConcretePoint >::RectBase ( x1,
y1,
x2,
y2 
)
inline

Create a rectangle with the top-left corner at the given position (x1, y1) and the bottom-right corner at the position (x2, y2).

The x2 value must be greater or equal x1 and y2 must be greater or equal y1.

Member Function Documentation

◆ operator==()

template<typename T, typename ConcreteRect, typename ConcretePoint>
bool Common::RectBase< T, ConcreteRect, ConcretePoint >::operator== ( const ConcreteRect &  rhs) const
inline

Check if two rectangles are identical.

Returns
True if the rectangles are identical, false otherwise.

◆ operator!=()

template<typename T, typename ConcreteRect, typename ConcretePoint>
bool Common::RectBase< T, ConcreteRect, ConcretePoint >::operator!= ( const ConcreteRect &  rhs) const
inline

Check if two rectangles are different.

Returns
True if the rectangles are different, false otherwise.

◆ origin()

template<typename T, typename ConcreteRect, typename ConcretePoint>
ConcretePoint Common::RectBase< T, ConcreteRect, ConcretePoint >::origin ( ) const
inline

Return the origin of a rectangle.

◆ width()

template<typename T, typename ConcreteRect, typename ConcretePoint>
T Common::RectBase< T, ConcreteRect, ConcretePoint >::width ( ) const
inline

Return the width of a rectangle.

◆ height()

template<typename T, typename ConcreteRect, typename ConcretePoint>
T Common::RectBase< T, ConcreteRect, ConcretePoint >::height ( ) const
inline

Return the height of a rectangle.

◆ setWidth()

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::setWidth ( aWidth)
inline

< Set the width to aWidth value.

◆ setHeight()

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::setHeight ( aHeight)
inline

< Set the height to aHeight value.

◆ setRect()

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::setRect ( newLeft,
newTop,
newRight,
newBottom 
)
inline

Set the rectangle to a new position and size.

◆ contains() [1/3]

template<typename T, typename ConcreteRect, typename ConcretePoint>
bool Common::RectBase< T, ConcreteRect, ConcretePoint >::contains ( x,
y 
) const
inline

Check if the 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.

◆ contains() [2/3]

template<typename T, typename ConcreteRect, typename ConcretePoint>
bool Common::RectBase< T, ConcreteRect, ConcretePoint >::contains ( const ConcretePoint &  p) const
inline

Check if the given point is inside this rectangle.

Parameters
pThe point to check.
Returns
True if the given point is inside this rectangle, false otherwise.

◆ contains() [3/3]

template<typename T, typename ConcreteRect, typename ConcretePoint>
bool Common::RectBase< T, ConcreteRect, ConcretePoint >::contains ( const ConcreteRect &  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.

◆ equals()

template<typename T, typename ConcreteRect, typename ConcretePoint>
bool Common::RectBase< T, ConcreteRect, ConcretePoint >::equals ( const ConcreteRect &  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.

◆ intersects()

template<typename T, typename ConcreteRect, typename ConcretePoint>
bool Common::RectBase< T, ConcreteRect, ConcretePoint >::intersects ( const ConcreteRect &  r) const
inline

Check if the 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.

◆ findIntersectingRect()

template<typename T, typename ConcreteRect, typename ConcretePoint>
ConcreteRect Common::RectBase< T, ConcreteRect, ConcretePoint >::findIntersectingRect ( const ConcreteRect &  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.

◆ extend()

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::extend ( const ConcreteRect &  r)
inline

Extend this rectangle so that it contains r.

Parameters
rThe rectangle to extend by.

◆ grow()

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::grow ( offset)
inline

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

Parameters
offsetThe size to grow by.

◆ clip() [1/2]

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::clip ( const ConcreteRect &  r)
inline

Clip this rectangle to within the bounds of another rectangle r.

◆ clip() [2/2]

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::clip ( maxw,
maxh 
)
inline

Reduce the dimensions of this rectangle by setting max width and max height.

◆ setEmpty()

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::setEmpty ( )
inline

Reset the rectangle to an empty state.

◆ isEmpty()

template<typename T, typename ConcreteRect, typename ConcretePoint>
bool Common::RectBase< T, ConcreteRect, ConcretePoint >::isEmpty ( ) const
inline

Check if the rectangle is empty (its width or length is 0) or invalid (its width or length are negative).

Return values
trueThe rectangle is empty or invalid.
falseThe rectangle is valid and not empty.

◆ isValidRect()

template<typename T, typename ConcreteRect, typename ConcretePoint>
bool Common::RectBase< T, ConcreteRect, ConcretePoint >::isValidRect ( ) const
inline

Check if this is a valid rectangle.

◆ moveTo() [1/2]

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::moveTo ( x,
y 
)
inline

Move this rectangle to the position defined by x, y.

◆ translate()

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::translate ( dx,
dy 
)
inline

Move the rectangle by the given delta x and y values.

◆ moveTo() [2/2]

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::moveTo ( const ConcretePoint &  p)
inline

Move this rectangle to the position of the point p.

◆ constrain() [1/2]

template<typename T, typename ConcreteRect, typename ConcretePoint>
bool Common::RectBase< T, ConcreteRect, ConcretePoint >::constrain ( const ConcreteRect &  o)
inline

Ensures the rectangle fits in an another one

Returns
True if the rectangle could be constrained

◆ constrain() [2/2]

template<typename T, typename ConcreteRect, typename ConcretePoint>
bool Common::RectBase< T, ConcreteRect, ConcretePoint >::constrain ( T &  x,
T &  y,
w,
h 
) const
inline

Ensures the provided coordinates fit inside our rectangle

Returns
True if the rectangle could be constrained

◆ debugPrint()

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::debugPrint ( int  debuglevel = 0,
const char *  caption = "Rect:" 
) const
inline

Print debug messages related to this class.

◆ debugPrintC()

template<typename T, typename ConcreteRect, typename ConcretePoint>
void Common::RectBase< T, ConcreteRect, ConcretePoint >::debugPrintC ( int  debuglevel,
uint32  debugChannel,
const char *  caption = "Rect:" 
) const
inline

Print debug messages related to this class.

◆ toString()

template<typename T, typename ConcreteRect, typename ConcretePoint>
String Common::RectBase< T, ConcreteRect, ConcretePoint >::toString ( ) const
inline

Return string representation of the rectangle.

◆ center() [1/2]

template<typename T, typename ConcreteRect, typename ConcretePoint>
static ConcreteRect Common::RectBase< T, ConcreteRect, ConcretePoint >::center ( cx,
cy,
w,
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.

◆ center() [2/2]

template<typename T, typename ConcreteRect, typename ConcretePoint>
ConcretePoint Common::RectBase< T, ConcreteRect, ConcretePoint >::center ( ) const
inline

Return a Point indicating the centroid of the rectangle

Note
The center point is rounded up and left when width and/or height are odd

◆ getBlitRect()

template<typename T, typename ConcreteRect, typename ConcretePoint>
static bool Common::RectBase< T, ConcreteRect, ConcretePoint >::getBlitRect ( ConcretePoint &  dst,
ConcreteRect &  rect,
const ConcreteRect &  clip 
)
inlinestatic

Given target surface with size clip, this function ensures that blit arguments dst and rect are within the clip rectangle, shrinking them as necessary.

Parameters
dstBlit destination coordinates.
rectBlit source rectangle.
clipClip rectangle (size of destination surface).

Member Data Documentation

◆ left

template<typename T, typename ConcreteRect, typename ConcretePoint>
T Common::RectBase< T, ConcreteRect, ConcretePoint >::left

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

◆ right

template<typename T, typename ConcreteRect, typename ConcretePoint>
T Common::RectBase< T, ConcreteRect, ConcretePoint >::right

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


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