주요 내용으로 건너뛰기

Rect

touchgfx/hal/Types.hpp

Class representing a Rectangle with a few convenient methods.

Public Functions

int32_tarea() const
Calculate the area of the rectangle.
FORCE_INLINE_FUNCTION int16_tbottom() const
Gets the y coordinate of the bottom edge of the Rect, i.e.
voidexpandToFit(const Rect & other)
Increases the area covered by this rectangle to encompass the area covered by supplied rectangle.
boolincludes(const Rect & other) const
Determines whether the specified rectangle is completely included in this rectangle.
boolintersect(const Rect & other) const
Determines whether specified rectangle intersects with this rectangle.
boolintersect(int16_t otherX, int16_t otherY) const
Determines whether specified point lies inside this rectangle.
boolisEmpty() const
Query if this object is empty.
booloperator!=(const Rect & other) const
Opposite of the == operator.
Rectoperator&(const Rect & other) const
Gets a rectangle describing the intersecting area between this rectangle and the supplied rectangle.
voidoperator&=(const Rect & other)
Assigns this Rect to the intersection of the current Rect and the assigned Rect.
booloperator==(const Rect & other) const
Compares equality of two Rect by the dimensions and position of these.
Rect()
Default constructor.
Rect(int16_t rectX, int16_t rectY, int16_t rectWidth, int16_t rectHeight)
Initializes a new instance of the Rect class.
voidrestrictTo(int16_t max_width, int16_t max_height)
Restrict the area to not exceed the given max width and max height.
FORCE_INLINE_FUNCTION int16_tright() const
Gets the x coordinate of the right edge of the Rect, i.e.

Public Attributes

int16_theight
The height.
int16_twidth
The width.
int16_tx
The x coordinate.
int16_ty
The y coordinate.

Public Functions Documentation

area

int32_t area()const

Calculate the area of the rectangle.

Returns:

area of the rectangle.

bottom

FORCE_INLINE_FUNCTION int16_t bottom()const

Gets the y coordinate of the bottom edge of the Rect, i.e.

the number of the first row just below the Rect.

Returns:

y coordinate of the bottom edge (calculated as "y + height").

expandToFit

void expandToFit(const Rect &other)

Increases the area covered by this rectangle to encompass the area covered by supplied rectangle.

Parameters:
otherThe other rectangle.

includes

bool includes(const Rect &other)

Determines whether the specified rectangle is completely included in this rectangle.

Parameters:
otherThe other rectangle.
Returns:

true if the specified rectangle is completely included.

intersect

bool intersect(const Rect &other)

Determines whether specified rectangle intersects with this rectangle.

Parameters:
otherThe other rectangle.
Returns:

true if the two rectangles intersect.

intersect

bool intersect(int16_totherX ,const
int16_totherYconst
)const

Determines whether specified point lies inside this rectangle.

Parameters:
otherXThe x coordinate of the point.
otherYThe y coordinate of the point.
Returns:

true if point lies inside rectangle.

isEmpty

bool isEmpty()const

Query if this object is empty.

Returns:

true if any of the dimensions are 0.

operator!=

bool operator!=(const Rect &other)

Opposite of the == operator.

Parameters:
otherThe Rect to compare with.
Returns:

true if the compared Rect differ in dimensions or coordinates.

operator&

Rect operator&(const Rect &other)

Gets a rectangle describing the intersecting area between this rectangle and the supplied rectangle.

Parameters:
otherThe other rectangle.
Returns:

Intersecting rectangle or empty Rect in case of no intersection.

operator&=

void operator&=(const Rect &other)

Assigns this Rect to the intersection of the current Rect and the assigned Rect.

The assignment will result in a empty Rect if they do not intersect.

Parameters:
otherThe rect to intersect with.

operator==

bool operator==(const Rect &other)

Compares equality of two Rect by the dimensions and position of these.

Parameters:
otherThe Rect to compare with.
Returns:

true if the compared Rect have the same dimensions and coordinates.

Rect

Default constructor.

Resulting in an empty Rect with coordinates 0,0.

Rect

Rect(int16_trectX ,
int16_trectY ,
int16_trectWidth ,
int16_trectHeight
)

Initializes a new instance of the Rect class.

Parameters:
rectXThe x coordinate.
rectYThe y coordinate.
rectWidthThe width.
rectHeightThe height.

restrictTo

void restrictTo(int16_tmax_width ,
int16_tmax_height
)

Restrict the area to not exceed the given max width and max height.

As a result, width or height can be negative if the rect is completely outside Rect(0, 0, max_width, max_height), but this is nicely handled by the isEmpty() function.

Parameters:
max_widthThe maximum width.
max_heightThe maximum height.
See also:
FORCE_INLINE_FUNCTION int16_t right()const

Gets the x coordinate of the right edge of the Rect, i.e.

the number of the first column just to the right of the Rect.

Returns:

x coordinate of the right edge (calculated as "x + width").

Public Attributes Documentation

height

int16_t height

The height.

width

int16_t width

The width.

x

int16_t x

The x coordinate.

y

int16_t y

The y coordinate.