|
constexpr | TRect () |
|
constexpr bool | operator== (const TRect &r) const |
|
constexpr bool | operator!= (const TRect &r) const |
|
constexpr TRect | Scale (Type scale) const |
|
constexpr TRect | Scale (Type scale_x, Type scale_y) const |
|
constexpr TRect | Scale (TPoint< T > scale) const |
|
constexpr TRect | Scale (TSize< T > scale) const |
|
constexpr bool | Contains (const TPoint< Type > &p) const |
| Returns true iff the provided point |p| is inside the half-open interior of this rectangle. More...
|
|
constexpr bool | ContainsInclusive (const TPoint< Type > &p) const |
| Returns true iff the provided point |p| is inside the closed-range interior of this rectangle. More...
|
|
constexpr bool | Contains (const TRect &o) const |
| Returns true iff this rectangle is not empty and it also contains every point considered inside the provided rectangle |o| (as determined by |Contains(TPoint)|). More...
|
|
| IsFinite () const |
| Returns true if all of the fields of this floating point rectangle are finite. More...
|
|
constexpr bool | IsEmpty () const |
| Returns true if either of the width or height are 0, negative, or NaN. More...
|
|
constexpr bool | IsSquare () const |
| Returns true if width and height are equal and neither is NaN. More...
|
|
constexpr bool | IsMaximum () const |
|
constexpr TPoint< Type > | GetOrigin () const |
| Returns the upper left corner of the rectangle as specified by the left/top or x/y values when it was constructed. More...
|
|
constexpr TSize< Type > | GetSize () const |
| Returns the size of the rectangle which may be negative in either width or height and may have been clipped to the maximum integer values for integer rects whose size overflows. More...
|
|
constexpr Type | GetX () const |
| Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|. More...
|
|
constexpr Type | GetY () const |
| Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|. More...
|
|
constexpr Type | GetWidth () const |
| Returns the width of the rectangle, equivalent to |GetSize().width|. More...
|
|
constexpr Type | GetHeight () const |
| Returns the height of the rectangle, equivalent to |GetSize().height|. More...
|
|
constexpr auto | GetLeft () const |
|
constexpr auto | GetTop () const |
|
constexpr auto | GetRight () const |
|
constexpr auto | GetBottom () const |
|
constexpr TPoint< T > | GetLeftTop () const |
|
constexpr TPoint< T > | GetRightTop () const |
|
constexpr TPoint< T > | GetLeftBottom () const |
|
constexpr TPoint< T > | GetRightBottom () const |
|
constexpr T | Area () const |
| Get the area of the rectangle, equivalent to |GetSize().Area()|. More...
|
|
constexpr Point | GetCenter () const |
| Get the center point as a |Point|. More...
|
|
constexpr std::array< T, 4 > | GetLTRB () const |
|
constexpr std::array< T, 4 > | GetXYWH () const |
| Get the x, y coordinates of the origin and the width and height of the rectangle in an array. More...
|
|
constexpr TRect | GetPositive () const |
| Get a version of this rectangle that has a non-negative size. More...
|
|
constexpr std::array< TPoint< T >, 4 > | GetPoints () const |
| Get the points that represent the 4 corners of this rectangle in a Z order that is compatible with triangle strips or a set of all zero points if the rectangle is empty. The order is: Top left, top right, bottom left, bottom right. More...
|
|
constexpr std::array< TPoint< T >, 4 > | GetTransformedPoints (const Matrix &transform) const |
|
constexpr TRect | TransformAndClipBounds (const Matrix &transform) const |
| Creates a new bounding box that contains this transformed rectangle, clipped against the near clipping plane if necessary. More...
|
|
constexpr TRect | TransformBounds (const Matrix &transform) const |
| Creates a new bounding box that contains this transformed rectangle. More...
|
|
constexpr Matrix | GetNormalizingTransform () const |
| Constructs a Matrix that will map all points in the coordinate space of the rectangle into a new normalized coordinate space where the upper left corner of the rectangle maps to (0, 0) and the lower right corner of the rectangle maps to (1, 1). More...
|
|
constexpr TRect | Union (const TRect &o) const |
|
constexpr std::optional< TRect > | Intersection (const TRect &o) const |
|
constexpr bool | IntersectsWithRect (const TRect &o) const |
|
constexpr std::optional< TRect< T > > | Cutout (const TRect &o) const |
| Returns the new boundary rectangle that would result from this rectangle being cut out by the specified rectangle. More...
|
|
constexpr TRect | CutoutOrEmpty (const TRect &o) const |
|
constexpr TRect< T > | Shift (T dx, T dy) const |
| Returns a new rectangle translated by the given offset. More...
|
|
constexpr TRect< T > | Shift (TPoint< T > offset) const |
| Returns a new rectangle translated by the given offset. More...
|
|
constexpr TRect< T > | Expand (T left, T top, T right, T bottom) const |
| Returns a rectangle with expanded edges. Negative expansion results in shrinking. More...
|
|
constexpr TRect< T > | Expand (T amount) const |
| Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking. More...
|
|
constexpr TRect< T > | Expand (T horizontal_amount, T vertical_amount) const |
| Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking. More...
|
|
constexpr TRect< T > | Expand (TPoint< T > amount) const |
| Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking. More...
|
|
constexpr TRect< T > | Expand (TSize< T > amount) const |
| Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking. More...
|
|
constexpr TRect< T > | Project (TRect< T > source) const |
| Returns a new rectangle that represents the projection of the source rectangle onto this rectangle. In other words, the source rectangle is redefined in terms of the coordinate space of this rectangle. More...
|
|
| RoundOut (const TRect< U > &r) |
|
| Round (const TRect< U > &r) |
|
|
static constexpr TRect | MakeLTRB (Type left, Type top, Type right, Type bottom) |
|
static constexpr TRect | MakeXYWH (Type x, Type y, Type width, Type height) |
|
static constexpr TRect | MakeOriginSize (const TPoint< Type > &origin, const TSize< Type > &size) |
|
template<class U > |
static constexpr TRect | MakeSize (const TSize< U > &size) |
|
template<typename U > |
static constexpr std::optional< TRect > | MakePointBounds (const U &value) |
|
template<typename PointIter > |
static constexpr std::optional< TRect > | MakePointBounds (const PointIter first, const PointIter last) |
|
static constexpr TRect | MakeMaximum () |
|
static constexpr std::optional< TRect > | Union (const TRect &a, const std::optional< TRect > b) |
|
static constexpr std::optional< TRect > | Union (const std::optional< TRect > a, const TRect &b) |
|
static constexpr std::optional< TRect > | Union (const std::optional< TRect > a, const std::optional< TRect > b) |
|
static constexpr std::optional< TRect > | Intersection (const TRect &a, const std::optional< TRect > b) |
|
static constexpr std::optional< TRect > | Intersection (const std::optional< TRect > a, const TRect &b) |
|
static constexpr std::optional< TRect > | Intersection (const std::optional< TRect > a, const std::optional< TRect > b) |
|
template<class
T>
struct impeller::TRect< T >
Templated struct for holding an axis-aligned rectangle.
Rectangles are defined as 4 axis-aligned edges that might contain space. They can be viewed as 2 X coordinates that define the left and right edges and 2 Y coordinates that define the top and bottom edges; or they can be viewed as an origin and horizontal and vertical dimensions (width and height).
When the left and right edges are equal or reversed (right <= left) or the top and bottom edges are equal or reversed (bottom <= top), the rectangle is considered empty. Considering the rectangle in XYWH form, the width and/or the height would be negative or zero. Such reversed/empty rectangles contain no space and act as such in the methods that operate on them (Intersection, Union, IntersectsWithRect, Contains, Cutout, etc.)
Rectangles cannot be modified by any method and a new value can only be stored into an existing rect using assignment. This keeps the API clean compared to implementations that might have similar methods that produce the answer in place, or construct a new object with the answer, or place the result in an indicated result object.
Methods that might fail to produce an answer will use |std::optional| to indicate that success or failure (see |Intersection| and |CutOut|). For convenience, |Intersection| and |Union| both have overloaded variants that take |std::optional| arguments and treat them as if the argument was an empty rect to allow chaining multiple such methods and only needing to check the optional condition of the final result. The primary methods also provide |...OrEmpty| overloaded variants that translate an empty optional answer into a simple empty rectangle of the same type.
Rounding instance methods are not provided as the return value might be wanted as another floating point rectangle or sometimes as an integer rectangle. Instead a |RoundOut| factory, defined only for floating point input rectangles, is provided to provide control over the result type.
NaN and Infinity values
Constructing an LTRB rectangle using Infinity values should work as expected with either 0 or +Infinity returned as dimensions depending on which side the Infinity values are on and the sign.
Constructing an XYWH rectangle using Infinity values will usually not work if the math requires the object to compute a right or bottom edge from ([xy] -Infinity + [wh] +Infinity). Other combinations might work.
The special factory |MakeMaximum| is provided to construct a rectangle of the indicated coordinate type that covers all finite coordinates. It does not use infinity values, but rather the largest finite values to avoid math that might produce a NaN value from various getters.
Any rectangle that is constructed with, or computed to have a NaN value will be considered the same as any empty rectangle.
Empty Rectangle canonical results summary:
Union will ignore any empty rects and return the other rect Intersection will return nullopt if either rect is empty IntersectsWithRect will return false if either rect is empty Cutout will return the source rect if the argument is empty Cutout will return nullopt if the source rectangle is empty Contains(Point) will return false if the source rectangle is empty Contains(Rect) will return false if the source rectangle is empty Contains(Rect) will otherwise return true if the argument is empty Specifically, EmptyRect.Contains(EmptyRect) returns false
Special notes on problems using the XYWH form of specifying rectangles:
It is possible to have integer rectangles whose dimensions exceed the maximum number that their coordinates can represent since (MAX_INT - MIN_INT) overflows the representable positive numbers. Floating point rectangles technically have a similar issue in that overflow can occur, but it will be automatically converted into either an infinity, or a finite-overflow value and still be representable, just with little to no precision.
Secondly, specifying a rectangle using XYWH leads to cases where the math for (x+w) and/or (y+h) are also beyond the maximum representable coordinates. For N-bit integer rectangles declared as XYWH, the maximum right coordinate will require N+1 signed bits which cannot be stored in storage that uses N-bit integers.
Saturated math is used when constructing a rectangle from XYWH values and when returning the dimensions of the rectangle. Constructing an integer rectangle from values such that xy + wh is beyond the range of the integer type will place the right or bottom edges at the maximum value for the integer type. Similarly, constructing an integer rectangle such that the distance from the left to the right (or top to bottom) is greater than the range of the integer type will simply return the maximum integer value as the dimension. Floating point rectangles are naturally saturated by the rules of IEEE arithmetic.
Definition at line 122 of file rect.h.