| Flutter Impeller |

Public Member Functions | Static Public Member Functions | List of all members
impeller::TRect< T > Struct Template Reference

`#include <rect.h>`

## Public Member Functions
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 TRect | IntersectionOrEmpty (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 Public Member Functions
constexpr static TRect | MakeLTRB (Type left, Type top, Type right, Type bottom)
constexpr static TRect | MakeXYWH (Type x, Type y, Type width, Type height)
constexpr static TRect | MakeWH (Type width, Type height)
constexpr static TRect | MakeOriginSize (const TPoint< Type > &origin, const TSize< Type > &size)
template<class U >
constexpr static TRect | MakeSize (const TSize< U > &size)
template<typename U >
constexpr static std::optional< TRect > | MakePointBounds (const U &value)
template<typename PointIter >
constexpr static std::optional< TRect > | MakePointBounds (const PointIter first, const PointIter last)
constexpr static TRect | MakeMaximum ()
constexpr static std::optional< TRect > | Union (const TRect &a, const std::optional< TRect > b)
constexpr static std::optional< TRect > | Union (const std::optional< TRect > a, const TRect &b)
constexpr static std::optional< TRect > | Union (const std::optional< TRect > a, const std::optional< TRect > b)
constexpr static std::optional< TRect > | Intersection (const TRect &a, const std::optional< TRect > b)
constexpr static std::optional< TRect > | Intersection (const std::optional< TRect > a, const TRect &b)
constexpr static std::optional< TRect > | Intersection (const std::optional< TRect > a, const std::optional< TRect > b)

## Detailed Description

### 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.

## Constructor & Destructor Documentation

## ◆ TRect()

template<class T >

constexpr impeller::TRect< T >::TRect | ( |  | ) |
| inline constexpr

Definition at line 127 of file rect.h.

127 : left_(0), top_(0), right_(0), bottom_(0) {}

Referenced by impeller::TRect< Scalar >::CutoutOrEmpty(), impeller::TRect< Scalar >::IntersectionOrEmpty(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeSize(), impeller::TRect< Scalar >::MakeWH(), impeller::TRect< Scalar >::MakeXYWH(), and impeller::TRect< Scalar >::Scale().

## Member Function Documentation

## ◆ Area()

template<class T >

constexpr T impeller::TRect< T >::Area | ( |  | ) | const
| inline constexpr

Get the area of the rectangle, equivalent to |GetSize().Area()|.

Definition at line 370 of file rect.h.

370 {
371 // TODO(141710): Use saturated math to avoid overflow.
372 return IsEmpty() ? 0 : (right_ - left_) * (bottom_ - top_);
373 }

Referenced by impeller::BlitPass::AddCopy(), and impeller::BlitCopyBufferToTextureCommandGLES::Encode().

## ◆ Contains() [1/2]

template<class T >

constexpr bool impeller::TRect< T >::Contains | ( | const TPoint< Type > & | p | ) | const
| inline constexpr

Returns true iff the provided point |p| is inside the half-open interior of this rectangle.

For purposes of containment, a rectangle contains points along the top and left edges but not points along the right and bottom edges so that a point is only ever considered inside one of two abutting rectangles.

Definition at line 225 of file rect.h.

225 {
226 return !this->IsEmpty() && //
227 p.x >= left_ && //
228 p.y >= top_ && //
229 p.x < right_ && //
230 p.y < bottom_;
231 }

Referenced by impeller::RectGeometry::CoversArea(), impeller::RoundRectGeometry::CoversArea(), impeller::FillPathGeometry::CoversArea(), impeller::TiledTextureContents::RenderToSnapshot(), and impeller::testing::TEST().

## ◆ Contains() [2/2]

template<class T >

constexpr bool impeller::TRect< T >::Contains | ( | const TRect< T > & | o | ) | const
| inline constexpr

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)|).

This is similar to a definition where the result is true iff the union of the two rectangles is equal to this rectangle, ignoring precision issues with performing those operations and assuming that empty rectangles are never equal.

An empty rectangle can contain no other rectangle.

An empty rectangle is, however, contained within any other non-empy rectangle as the set of points it contains is an empty set and so there are no points to fail the containment criteria.

Definition at line 267 of file rect.h.

267 {
268 return !this->IsEmpty() && //
269 (o.IsEmpty() || (o.left_ >= left_ && //
270 o.top_ >= top_ && //
271 o.right_ <= right_ && //
272 o.bottom_ <= bottom_));
273 }

## ◆ ContainsInclusive()

template<class T >

constexpr bool impeller::TRect< T >::ContainsInclusive | ( | const TPoint< Type > & | p | ) | const
| inline constexpr

Returns true iff the provided point |p| is inside the closed-range interior of this rectangle.

Unlike the regular |Contains(TPoint)| method, this method considers all points along the boundary of the rectangle to be contained within the rectangle - useful for testing if vertices that define a filled shape would carry the interior of that shape outside the bounds of the rectangle. Since both geometries are defining half-open spaces, their defining geometry needs to consider their boundaries to be equivalent with respect to interior and exterior.

Definition at line 244 of file rect.h.

244 {
245 return !this->IsEmpty() && //
246 p.x >= left_ && //
247 p.y >= top_ && //
248 p.x <= right_ && //
249 p.y <= bottom_;
250 }

Referenced by impeller::testing::TEST().

## ◆ Cutout()

template<class T >

constexpr std::optional<TRect<T> > impeller::TRect< T >::Cutout | ( | const TRect< T > & | o | ) | const
| inline constexpr

Returns the new boundary rectangle that would result from this rectangle being cut out by the specified rectangle.

Definition at line 551 of file rect.h.

551 {
552 if (IsEmpty()) {
553 // This test isn't just a short-circuit, it also prevents the concise
554 // math below from returning the wrong answer on empty rects.
555 // Once we know that this rectangle is not empty, the math below can
556 // only succeed in computing a value if o is also non-empty and non-nan.
557 // Otherwise, the method returns *this by default.
558 return std::nullopt;
559 }
560
561 const auto& [a_left, a_top, a_right, a_bottom] = GetLTRB(); // Source rect.
562 const auto& [b_left, b_top, b_right, b_bottom] = o.GetLTRB(); // Cutout.
563 if (b_left <= a_left && b_right >= a_right) {
564 if (b_top <= a_top && b_bottom >= a_bottom) {
565 // Full cutout.
566 return std::nullopt;
567 }
568 if (b_top <= a_top && b_bottom > a_top) {
569 // Cuts off the top.
570 return TRect::MakeLTRB(a_left, b_bottom, a_right, a_bottom);
571 }
572 if (b_bottom >= a_bottom && b_top < a_bottom) {
573 // Cuts off the bottom.
574 return TRect::MakeLTRB(a_left, a_top, a_right, b_top);
575 }
576 }
577 if (b_top <= a_top && b_bottom >= a_bottom) {
578 if (b_left <= a_left && b_right > a_left) {
579 // Cuts off the left.
580 return TRect::MakeLTRB(b_right, a_top, a_right, a_bottom);
581 }
582 if (b_right >= a_right && b_left < a_right) {
583 // Cuts off the right.
584 return TRect::MakeLTRB(a_left, a_top, b_left, a_bottom);
585 }
586 }
587
588 return *this;
589 }

Referenced by impeller::TRect< Scalar >::CutoutOrEmpty(), and impeller::testing::TEST().

## ◆ CutoutOrEmpty()

template<class T >

constexpr TRect impeller::TRect< T >::CutoutOrEmpty | ( | const TRect< T > & | o | ) | const
| inline constexpr

Definition at line 591 of file rect.h.

591 {
592 return Cutout(o).value_or(TRect());
593 }

Referenced by impeller::testing::TEST().

## ◆ Expand() [1/5]

template<class T >

constexpr TRect<T> impeller::TRect< T >::Expand | ( | T | amount | ) | const
| inline constexpr

Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.

Definition at line 626 of file rect.h.

626 {
627 return {
628 saturated::Sub(left_, amount), //
629 saturated::Sub(top_, amount), //
630 saturated::Add(right_, amount), //
631 saturated::Add(bottom_, amount), //
632 };
633 }

## ◆ Expand() [2/5]

template<class T >

constexpr TRect<T> impeller::TRect< T >::Expand | ( | T | horizontal_amount,
|  | T | vertical_amount
| ) |  | const
| inline constexpr

Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.

Definition at line 637 of file rect.h.

638 {
639 return {
640 saturated::Sub(left_, horizontal_amount), //
641 saturated::Sub(top_, vertical_amount), //
642 saturated::Add(right_, horizontal_amount), //
643 saturated::Add(bottom_, vertical_amount), //
644 };
645 }

## ◆ Expand() [3/5]

template<class T >

constexpr TRect<T> impeller::TRect< T >::Expand | ( | T | left,
|  | T | top,
|  | T | right,
|  | T | bottom
| ) |  | const
| inline constexpr

Returns a rectangle with expanded edges. Negative expansion results in shrinking.

Definition at line 612 of file rect.h.

615 {
616 return {
617 saturated::Sub(left_, left), //
618 saturated::Sub(top_, top), //
619 saturated::Add(right_, right), //
620 saturated::Add(bottom_, bottom), //
621 };
622 }

Referenced by impeller::RoundRectGeometry::CoversArea(), impeller::TRect< Scalar >::Expand(), impeller::BorderMaskBlurFilterContents::GetFilterCoverage(), impeller::BorderMaskBlurFilterContents::GetFilterSourceCoverage(), impeller::DirectionalMorphologyFilterContents::GetFilterSourceCoverage(), impeller::GaussianBlurFilterContents::GetFilterSourceCoverage(), impeller::TextureContents::Render(), and impeller::testing::TEST_P().

## ◆ Expand() [4/5]

template<class T >

constexpr TRect<T> impeller::TRect< T >::Expand | ( | TPoint< T > | amount | ) | const
| inline constexpr

Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.

Definition at line 649 of file rect.h.

649 {
650 return Expand(amount.x, amount.y);
651 }

## ◆ Expand() [5/5]

template<class T >

constexpr TRect<T> impeller::TRect< T >::Expand | ( | TSize< T > | amount | ) | const
| inline constexpr

Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.

Definition at line 655 of file rect.h.

655 {
656 return Expand(amount.width, amount.height);
657 }

## ◆ GetBottom()

template<class T >

constexpr auto impeller::TRect< T >::GetBottom | ( |  | ) | const
| inline constexpr

Definition at line 351 of file rect.h.

351 { return bottom_; }

Referenced by impeller::BlitPass::AddCopy(), impeller::Canvas::Canvas(), impeller::DlDispatcherBase::drawDisplayList(), impeller::TextFrameDispatcher::drawDisplayList(), impeller::NinePatchConverter::DrawNinePatch(), RectNear(), impeller::testing::swap_nan(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ GetCenter()

template<class T >

constexpr Point impeller::TRect< T >::GetCenter | ( |  | ) | const
| inline constexpr

Get the center point as a |Point|.

Definition at line 376 of file rect.h.

376 {
377 return {saturated::AverageScalar(left_, right_),
378 saturated::AverageScalar(top_, bottom_)};
379 }

Referenced by impeller::PathBuilder::AddArc(), impeller::PathBuilder::AddOval(), impeller::Canvas::DrawOval(), impeller::Tessellator::FilledEllipse(), and impeller::SolidRRectBlurContents::Render().

## ◆ GetHeight()

template<class T >

constexpr Type impeller::TRect< T >::GetHeight | ( |  | ) | const
| inline constexpr

Returns the height of the rectangle, equivalent to |GetSize().height|.

Definition at line 341 of file rect.h.

341 {
342 return saturated::Sub(bottom_, top_);
343 }

Referenced by impeller::RoundRectGeometry::CoversArea(), impeller::DrawGlyph(), impeller::BlitCopyBufferToTextureCommandGLES::Encode(), impeller::BlitCopyTextureToTextureCommandGLES::Encode(), impeller::BlitCopyTextureToBufferCommandGLES::Encode(), impeller::BlitResizeTextureCommandGLES::Encode(), impeller::Tessellator::FilledRoundRect(), impeller::TRect< Scalar >::GetNormalizingTransform(), impeller::TRect< Scalar >::GetSize(), impeller::TRect< Scalar >::GetXYWH(), impeller::TRect< Scalar >::Project(), impeller::SolidRRectBlurContents::Render(), impeller::PassBindingsCacheMTL::SetScissor(), impeller::PassBindingsCacheMTL::SetViewport(), impeller::testing::TEST(), and impeller::interop::ToSkiaType().

## ◆ GetLeft()

template<class T >

constexpr auto impeller::TRect< T >::GetLeft | ( |  | ) | const
| inline constexpr

Definition at line 345 of file rect.h.

345 { return left_; }

Referenced by impeller::Canvas::Canvas(), impeller::DlDispatcherBase::drawDisplayList(), impeller::TextFrameDispatcher::drawDisplayList(), impeller::DrawGlyph(), impeller::NinePatchConverter::DrawNinePatch(), RectNear(), impeller::testing::swap_nan(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ GetLeftBottom()

template<class T >

constexpr TPoint<T> impeller::TRect< T >::GetLeftBottom | ( |  | ) | const
| inline constexpr

Definition at line 361 of file rect.h.

361 {
362 return {left_, bottom_};
363 }

Referenced by impeller::TextureContents::Render(), and impeller::testing::TEST().

## ◆ GetLeftTop()

template<class T >

constexpr TPoint<T> impeller::TRect< T >::GetLeftTop | ( |  | ) | const
| inline constexpr

Definition at line 353 of file rect.h.

353 { //
354 return {left_, top_};
355 }

Referenced by impeller::Tessellator::FilledRoundRect(), impeller::TextContents::Render(), impeller::TextureContents::Render(), and impeller::testing::TEST().

## ◆ GetLTRB()

template<class T >

constexpr std::array<T, 4> impeller::TRect< T >::GetLTRB | ( |  | ) | const
| inline constexpr

Definition at line 381 of file rect.h.

381 {
382 return {left_, top_, right_, bottom_};
383 }

Referenced by impeller::TRect< Scalar >::Cutout().

## ◆ GetNormalizingTransform()

template<class T >

constexpr Matrix impeller::TRect< T >::GetNormalizingTransform | ( |  | ) | const
| inline constexpr

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).

Empty and non-finite rectangles will return a zero-scaling transform that maps all points to (0, 0).

Definition at line 485 of file rect.h.

485 {
486 if (!IsEmpty()) {
487 Scalar sx = 1.0 / GetWidth();
488 Scalar sy = 1.0 / GetHeight();
489 Scalar tx = left_ * -sx;
490 Scalar ty = top_ * -sy;
491
492 // Exclude NaN and infinities and either scale underflowing to zero
493 if (sx != 0.0 && sy != 0.0 && 0.0 * sx * sy * tx * ty == 0.0) {
494 // clang-format off
495 return Matrix( sx, 0.0f, 0.0f, 0.0f,
496 0.0f, sy, 0.0f, 0.0f,
497 0.0f, 0.0f, 1.0f, 0.0f,
498 tx, ty, 0.0f, 1.0f);
499 // clang-format on
500 }
501 }
502
503 // Map all coordinates to the origin.
504 return Matrix::MakeScale({0.0f, 0.0f, 1.0f});
505 }

Referenced by impeller::DlVerticesGeometry::GetPositionUVColorBuffer(), and impeller::TiledTextureContents::Render().

## ◆ GetOrigin()

template<class T >

constexpr TPoint<Type> impeller::TRect< T >::GetOrigin | ( |  | ) | const
| inline constexpr

Returns the upper left corner of the rectangle as specified by the left/top or x/y values when it was constructed.

Definition at line 314 of file rect.h.

314 {
315 return {left_, top_};
316 }

Referenced by impeller::PathBuilder::AddArc(), impeller::PathBuilder::AddOval(), impeller::PathBuilder::AddRect(), impeller::PathBuilder::AddRoundedRect(), impeller::AdvancedBlend(), impeller::DirectionalMorphologyFilterContents::GetFilterCoverage(), std::operator<<(), impeller::PipelineBlend(), impeller::SolidRRectBlurContents::Render(), impeller::Canvas::Restore(), and impeller::testing::TEST().

## ◆ GetPoints()

template<class T >

constexpr std::array<TPoint<T>, 4> impeller::TRect< T >::GetPoints | ( |  | ) | const
| inline constexpr

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.

Definition at line 408 of file rect.h.

408 {
409 if (IsEmpty()) {
410 return {};
411 }
412 return {
413 TPoint{left_, top_},
414 TPoint{right_, top_},
415 TPoint{left_, bottom_},
416 TPoint{right_, bottom_},
417 };
418 }

Referenced by impeller::RectGeometry::GetPositionBuffer(), impeller::TRect< Scalar >::GetTransformedPoints(), impeller::ClipContents::Render(), and impeller::testing::TEST().

## ◆ GetPositive()

template<class T >

constexpr TRect impeller::TRect< T >::GetPositive | ( |  | ) | const
| inline constexpr

Get a version of this rectangle that has a non-negative size.

Definition at line 392 of file rect.h.

392 {
393 if (!IsEmpty()) {
394 return *this;
395 }
396 return {
397 std::min(left_, right_),
398 std::min(top_, bottom_),
399 std::max(left_, right_),
400 std::max(top_, bottom_),
401 };
402 }

Referenced by impeller::testing::TEST().

## ◆ GetRight()

template<class T >

constexpr auto impeller::TRect< T >::GetRight | ( |  | ) | const
| inline constexpr

Definition at line 349 of file rect.h.

349 { return right_; }

Referenced by impeller::BlitPass::AddCopy(), impeller::Canvas::Canvas(), impeller::DlDispatcherBase::drawDisplayList(), impeller::TextFrameDispatcher::drawDisplayList(), impeller::NinePatchConverter::DrawNinePatch(), RectNear(), impeller::testing::swap_nan(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ GetRightBottom()

template<class T >

constexpr TPoint<T> impeller::TRect< T >::GetRightBottom | ( |  | ) | const
| inline constexpr

Definition at line 365 of file rect.h.

365 {
366 return {right_, bottom_};
367 }

Referenced by impeller::Tessellator::FilledRoundRect(), impeller::TextureContents::Render(), and impeller::testing::TEST().

## ◆ GetRightTop()

template<class T >

constexpr TPoint<T> impeller::TRect< T >::GetRightTop | ( |  | ) | const
| inline constexpr

Definition at line 357 of file rect.h.

357 {
358 return {right_, top_};
359 }

Referenced by impeller::TextureContents::Render(), and impeller::testing::TEST().

## ◆ GetSize()

template<class T >

constexpr TSize<Type> impeller::TRect< T >::GetSize | ( |  | ) | const
| inline constexpr

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.

Definition at line 321 of file rect.h.

321 {
322 return {GetWidth(), GetHeight()};
323 }

Referenced by impeller::PathBuilder::AddRect(), impeller::PathBuilder::AddRoundedRect(), impeller::AdvancedBlend(), impeller::Canvas::DrawOval(), impeller::Tessellator::FilledEllipse(), impeller::DirectionalMorphologyFilterContents::GetFilterCoverage(), std::operator<<(), impeller::PipelineBlend(), impeller::SolidRRectBlurContents::Render(), impeller::TextContents::Render(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ GetTop()

template<class T >

constexpr auto impeller::TRect< T >::GetTop | ( |  | ) | const
| inline constexpr

Definition at line 347 of file rect.h.

347 { return top_; }

Referenced by impeller::Canvas::Canvas(), impeller::DlDispatcherBase::drawDisplayList(), impeller::TextFrameDispatcher::drawDisplayList(), impeller::DrawGlyph(), impeller::NinePatchConverter::DrawNinePatch(), RectNear(), impeller::testing::swap_nan(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ GetTransformedPoints()

template<class T >

constexpr std::array<TPoint<T>, 4> impeller::TRect< T >::GetTransformedPoints | ( | const Matrix & | transform | ) | const
| inline constexpr

Definition at line 420 of file rect.h.

421 {
422 auto points = GetPoints();
423 for (size_t i = 0; i < points.size(); i++) {
424 points[i] = transform * points[i];
425 }
426 return points;
427 }

Referenced by impeller::GaussianBlurFilterContents::CalculateUVs(), impeller::DlAtlasGeometry::CreateBlendVertexBuffer(), impeller::DlAtlasGeometry::CreateSimpleVertexBuffer(), impeller::Snapshot::GetCoverageUVs(), impeller::testing::TEST(), and impeller::TRect< Scalar >::TransformBounds().

## ◆ GetWidth()

template<class T >

constexpr Type impeller::TRect< T >::GetWidth | ( |  | ) | const
| inline constexpr

Returns the width of the rectangle, equivalent to |GetSize().width|.

Definition at line 335 of file rect.h.

335 {
336 return saturated::Sub(right_, left_);
337 }

Referenced by impeller::RoundRectGeometry::CoversArea(), impeller::DrawGlyph(), impeller::Canvas::DrawOval(), impeller::BlitCopyBufferToTextureCommandGLES::Encode(), impeller::BlitCopyTextureToTextureCommandGLES::Encode(), impeller::BlitCopyTextureToBufferCommandGLES::Encode(), impeller::BlitResizeTextureCommandGLES::Encode(), impeller::Tessellator::FilledEllipse(), impeller::Tessellator::FilledRoundRect(), impeller::TRect< Scalar >::GetNormalizingTransform(), impeller::TRect< Scalar >::GetSize(), impeller::TRect< Scalar >::GetXYWH(), impeller::TRect< Scalar >::Project(), impeller::SolidRRectBlurContents::Render(), impeller::PassBindingsCacheMTL::SetScissor(), impeller::PassBindingsCacheMTL::SetViewport(), impeller::testing::TEST(), and impeller::interop::ToSkiaType().

## ◆ GetX()

template<class T >

constexpr Type impeller::TRect< T >::GetX | ( |  | ) | const
| inline constexpr

Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.

Definition at line 327 of file rect.h.

327 { return left_; }

Referenced by impeller::BlitPass::AddCopy(), impeller::DrawGlyph(), impeller::BlitCopyBufferToTextureCommandGLES::Encode(), impeller::BlitCopyTextureToTextureCommandGLES::Encode(), impeller::BlitCopyTextureToBufferCommandGLES::Encode(), impeller::BlitResizeTextureCommandGLES::Encode(), impeller::PassBindingsCacheMTL::SetScissor(), impeller::PassBindingsCacheMTL::SetViewport(), impeller::testing::TEST(), and impeller::interop::ToSkiaType().

## ◆ GetXYWH()

template<class T >

constexpr std::array<T, 4> impeller::TRect< T >::GetXYWH | ( |  | ) | const
| inline constexpr

Get the x, y coordinates of the origin and the width and height of the rectangle in an array.

Definition at line 387 of file rect.h.

387 {
388 return {left_, top_, GetWidth(), GetHeight()};
389 }

Referenced by impeller::testing::TEST().

## ◆ GetY()

template<class T >

constexpr Type impeller::TRect< T >::GetY | ( |  | ) | const
| inline constexpr

Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.

Definition at line 331 of file rect.h.

331 { return top_; }

Referenced by impeller::BlitPass::AddCopy(), impeller::DrawGlyph(), impeller::BlitCopyBufferToTextureCommandGLES::Encode(), impeller::BlitCopyTextureToTextureCommandGLES::Encode(), impeller::BlitCopyTextureToBufferCommandGLES::Encode(), impeller::BlitResizeTextureCommandGLES::Encode(), impeller::PassBindingsCacheMTL::SetScissor(), impeller::PassBindingsCacheMTL::SetViewport(), impeller::testing::TEST(), and impeller::interop::ToSkiaType().

## ◆ Intersection() [1/4]

template<class T >

constexpr static std::optional<TRect> impeller::TRect< T >::Intersection | ( | const std::optional< TRect< T > > | a,
|  | const std::optional< TRect< T > > | b
| ) |  |
| inline static constexpr

Definition at line 718 of file rect.h.

720 {
721 return a.has_value() ? Intersection(a.value(), b) : b;
722 }

## ◆ Intersection() [2/4]

template<class T >

constexpr static std::optional<TRect> impeller::TRect< T >::Intersection | ( | const std::optional< TRect< T > > | a,
|  | const TRect< T > & | b
| ) |  |
| inline static constexpr

Definition at line 712 of file rect.h.

714 {
715 return a.has_value() ? a->Intersection(b) : b;
716 }

## ◆ Intersection() [3/4]

template<class T >

constexpr static std::optional<TRect> impeller::TRect< T >::Intersection | ( | const TRect< T > & | a,
|  | const std::optional< TRect< T > > | b
| ) |  |
| inline static constexpr

Definition at line 706 of file rect.h.

708 {
709 return b.has_value() ? a.Intersection(b.value()) : a;
710 }

## ◆ Intersection() [4/4]

template<class T >

constexpr std::optional<TRect> impeller::TRect< T >::Intersection | ( | const TRect< T > & | o | ) | const
| inline constexpr

Definition at line 522 of file rect.h.

523 {
524 if (IntersectsWithRect(o)) {
525 return TRect{
526 std::max(left_, o.left_),
527 std::max(top_, o.top_),
528 std::min(right_, o.right_),
529 std::min(bottom_, o.bottom_),
530 };
531 } else {
532 return std::nullopt;
533 }
534 }

Referenced by impeller::AdvancedBlend(), impeller::ComputeSaveLayerCoverage(), impeller::Canvas::GetLocalCoverageLimit(), impeller::TRect< Scalar >::Intersection(), impeller::TRect< Scalar >::IntersectionOrEmpty(), impeller::PipelineBlend(), and impeller::testing::TEST().

## ◆ IntersectionOrEmpty()

template<class T >

constexpr TRect impeller::TRect< T >::IntersectionOrEmpty | ( | const TRect< T > & | o | ) | const
| inline constexpr

Definition at line 536 of file rect.h.

536 {
537 return Intersection(o).value_or(TRect());
538 }

Referenced by impeller::testing::TEST().

## ◆ IntersectsWithRect()

template<class T >

constexpr bool impeller::TRect< T >::IntersectsWithRect | ( | const TRect< T > & | o | ) | const
| inline constexpr

Definition at line 540 of file rect.h.

540 {
541 return !IsEmpty() && //
542 !o.IsEmpty() && //
543 left_ < o.right_ && //
544 top_ < o.bottom_ && //
545 right_ > o.left_ && //
546 bottom_ > o.top_;
547 }

Referenced by impeller::TRect< Scalar >::Intersection(), and impeller::testing::TEST().

## ◆ IsEmpty()

template<class T >

constexpr bool impeller::TRect< T >::IsEmpty | ( |  | ) | const
| inline constexpr

Returns true if either of the width or height are 0, negative, or NaN.

Definition at line 291 of file rect.h.

291 {
292 // Computing the non-empty condition and negating the result causes any
293 // NaN value to return true - i.e. is considered empty.
294 return !(left_ < right_ && top_ < bottom_);
295 }

Referenced by impeller::TRect< Scalar >::Area(), impeller::TRect< Scalar >::Contains(), impeller::TRect< Scalar >::ContainsInclusive(), impeller::TRect< Scalar >::Cutout(), impeller::TextFrameDispatcher::drawDisplayList(), impeller::Canvas::DrawImageRect(), impeller::NinePatchConverter::DrawNinePatch(), impeller::TRect< Scalar >::GetNormalizingTransform(), impeller::TRect< Scalar >::GetPoints(), impeller::TRect< Scalar >::GetPositive(), impeller::TRect< Scalar >::IntersectsWithRect(), impeller::TRect< Scalar >::IsSquare(), impeller::TRect< Scalar >::Project(), impeller::TextureContents::Render(), impeller::testing::TEST(), impeller::TRect< Scalar >::TransformAndClipBounds(), impeller::TRect< Scalar >::TransformBounds(), and impeller::TRect< Scalar >::Union().

## ◆ IsFinite()

template<class T >

impeller::TRect< T >::IsFinite | ( |  | ) | const
| inline

Returns true if all of the fields of this floating point rectangle are finite.

Note that the results of |GetWidth()| and |GetHeight()| may still be infinite due to overflow even if the fields themselves are finite.

Definition at line 282 of file rect.h.

282 {
283 return std::isfinite(left_) && //
284 std::isfinite(top_) && //
285 std::isfinite(right_) && //
286 std::isfinite(bottom_);
287 }

Referenced by impeller::testing::TEST().

## ◆ IsMaximum()

template<class T >

constexpr bool impeller::TRect< T >::IsMaximum | ( |  | ) | const
| inline constexpr

Definition at line 308 of file rect.h.

308 {
309 return *this == MakeMaximum();
310 }

Referenced by impeller::ComputeSaveLayerCoverage(), and impeller::TextFrameDispatcher::drawDisplayList().

## ◆ IsSquare()

template<class T >

constexpr bool impeller::TRect< T >::IsSquare | ( |  | ) | const
| inline constexpr

Returns true if width and height are equal and neither is NaN.

Definition at line 298 of file rect.h.

298 {
299 // empty rectangles can technically be "square", but would be
300 // misleading to most callers. Using |IsEmpty| also prevents
301 // "non-empty and non-overflowing" computations from happening
302 // to be equal to "empty and overflowing" results.
303 // (Consider LTRB(10, 15, MAX-2, MIN+2) which is empty, but both
304 // w/h subtractions equal "5").
305 return !IsEmpty() && (right_ - left_) == (bottom_ - top_);
306 }

Referenced by impeller::Canvas::DrawOval(), and impeller::Tessellator::FilledEllipse().

## ◆ MakeLTRB()

template<class T >

constexpr static TRect impeller::TRect< T >::MakeLTRB | ( | Type | left,
|  | Type | top,
|  | Type | right,
|  | Type | bottom
| ) |  |
| inline static constexpr

Definition at line 129 of file rect.h.

132 {
133 return TRect(left, top, right, bottom);
134 }

Referenced by impeller::TRect< Scalar >::Cutout(), impeller::TRect< Scalar >::MakeMaximum(), impeller::TRect< Scalar >::MakePointBounds(), impeller::TRect< Scalar >::Round(), impeller::TRect< Scalar >::RoundOut(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ MakeMaximum()

template<class T >

constexpr static TRect impeller::TRect< T >::MakeMaximum | ( |  | ) |
| inline static constexpr

Definition at line 178 of file rect.h.

178 {
179 return TRect::MakeLTRB(std::numeric_limits<Type>::lowest(),
180 std::numeric_limits<Type>::lowest(),
181 std::numeric_limits<Type>::max(),
182 std::numeric_limits<Type>::max());
183 }

Referenced by impeller::TRect< Scalar >::IsMaximum(), impeller::DlPlayground::OpenPlaygroundHere(), impeller::AiksPlayground::OpenPlaygroundHere(), and impeller::testing::TEST().

## ◆ MakeOriginSize()

template<class T >

constexpr static TRect impeller::TRect< T >::MakeOriginSize | ( | const TPoint< Type > & | origin,
|  | const TSize< Type > & | size
| ) |  |
| inline static constexpr

Definition at line 144 of file rect.h.

145 {
146 return MakeXYWH(origin.x, origin.y, size.width, size.height);
147 }

Referenced by impeller::BlitPass::AddCopy(), and impeller::testing::TEST().

## ◆ MakePointBounds() [1/2]

template<class T >
template<typename PointIter >

constexpr static std::optional<TRect> impeller::TRect< T >::MakePointBounds | ( | const PointIter | first,
|  | const PointIter | last
| ) |  |
| inline static constexpr

Definition at line 160 of file rect.h.

161 {
162 if (first == last) {
163 return std::nullopt;
164 }
165 auto left = first->x;
166 auto top = first->y;
167 auto right = first->x;
168 auto bottom = first->y;
169 for (auto it = first + 1; it < last; ++it) {
170 left = std::min(left, it->x);
171 top = std::min(top, it->y);
172 right = std::max(right, it->x);
173 bottom = std::max(bottom, it->y);
174 }
175 return TRect::MakeLTRB(left, top, right, bottom);
176 }

## ◆ MakePointBounds() [2/2]

template<class T >
template<typename U >

constexpr static std::optional<TRect> impeller::TRect< T >::MakePointBounds | ( | const U & | value | ) |
| inline static constexpr

Definition at line 155 of file rect.h.

155 {
156 return MakePointBounds(value.begin(), value.end());
157 }

Referenced by impeller::TRect< Scalar >::MakePointBounds(), impeller::TRect< Scalar >::TransformAndClipBounds(), and impeller::TRect< Scalar >::TransformBounds().

## ◆ MakeSize()

template<class T >
template<class U >

constexpr static TRect impeller::TRect< T >::MakeSize | ( | const TSize< U > & | size | ) |
| inline static constexpr

Definition at line 150 of file rect.h.

150 {
151 return TRect(0.0, 0.0, size.width, size.height);
152 }

Referenced by impeller::RenderPass::AddCommand(), impeller::BlitPass::AddCopy(), impeller::SurfaceMTL::coverage(), impeller::TypographerContextSkia::CreateGlyphAtlas(), impeller::DisplayListToTexture(), impeller::interop::Surface::DrawDisplayList(), impeller::BlitResizeTextureCommandGLES::Encode(), and impeller::testing::TEST().

## ◆ MakeWH()

template<class T >

constexpr static TRect impeller::TRect< T >::MakeWH | ( | Type | width,
|  | Type | height
| ) |  |
| inline static constexpr

Definition at line 140 of file rect.h.

140 {
141 return TRect(0, 0, width, height);
142 }

Referenced by impeller::testing::TEST().

## ◆ MakeXYWH()

template<class T >

constexpr static TRect impeller::TRect< T >::MakeXYWH | ( | Type | x,
|  | Type | y,
|  | Type | width,
|  | Type | height
| ) |  |
| inline static constexpr

Definition at line 136 of file rect.h.

136 {
137 return TRect(x, y, saturated::Add(x, width), saturated::Add(y, height));
138 }

Referenced by impeller::BulkUpdateAtlasBitmap(), impeller::TRect< Scalar >::MakeOriginSize(), impeller::testing::TEST(), and impeller::UpdateAtlasBitmap().

## ◆ operator!=()

template<class T >

constexpr bool impeller::TRect< T >::operator!= | ( | const TRect< T > & | r | ) | const
| inline constexpr

Definition at line 192 of file rect.h.

192 {
193 return !(*this == r);
194 }

## ◆ operator==()

template<class T >

constexpr bool impeller::TRect< T >::operator== | ( | const TRect< T > & | r | ) | const
| inline constexpr

Definition at line 185 of file rect.h.

185 {
186 return left_ == r.left_ && //
187 top_ == r.top_ && //
188 right_ == r.right_ && //
189 bottom_ == r.bottom_;
190 }

## ◆ Project()

template<class T >

constexpr TRect<T> impeller::TRect< T >::Project | ( | TRect< T > | source | ) | const
| inline constexpr

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.

Definition at line 663 of file rect.h.

663 {
664 if (IsEmpty()) {
665 return {};
666 }
667 return source.Shift(-left_, -top_)
668 .Scale(1.0 / static_cast<Scalar>(GetWidth()),
669 1.0 / static_cast<Scalar>(GetHeight()));
670 }

Referenced by impeller::TextureContents::Render().

## ◆ Round()

template<class T >

impeller::TRect< T >::Round | ( | const TRect< U > & | r | ) |
| inline

Definition at line 681 of file rect.h.

681 {
682 return TRect::MakeLTRB(saturated::Cast<U, Type>(round(r.GetLeft())),
683 saturated::Cast<U, Type>(round(r.GetTop())),
684 saturated::Cast<U, Type>(round(r.GetRight())),
685 saturated::Cast<U, Type>(round(r.GetBottom())));
686 }

Referenced by impeller::testing::TEST().

## ◆ RoundOut()

template<class T >

impeller::TRect< T >::RoundOut | ( | const TRect< U > & | r | ) |
| inline

Definition at line 673 of file rect.h.

673 {
674 return TRect::MakeLTRB(saturated::Cast<U, Type>(floor(r.GetLeft())),
675 saturated::Cast<U, Type>(floor(r.GetTop())),
676 saturated::Cast<U, Type>(ceil(r.GetRight())),
677 saturated::Cast<U, Type>(ceil(r.GetBottom())));
678 }

Referenced by impeller::TextFrameDispatcher::drawDisplayList(), ImGui_ImplImpeller_RenderDrawData(), impeller::RenderToOnscreen(), impeller::Canvas::SaveLayer(), and impeller::testing::TEST().

## ◆ Scale() [1/4]

template<class T >

constexpr TRect impeller::TRect< T >::Scale | ( | TPoint< T > | scale | ) | const
| inline constexpr

Definition at line 210 of file rect.h.

210 {
211 return Scale(scale.x, scale.y);
212 }

## ◆ Scale() [2/4]

template<class T >

constexpr TRect impeller::TRect< T >::Scale | ( | TSize< T > | scale | ) | const
| inline constexpr

Definition at line 214 of file rect.h.

214 {
215 return Scale(scale.width, scale.height);
216 }

## ◆ Scale() [3/4]

template<class T >

constexpr TRect impeller::TRect< T >::Scale | ( | Type | scale | ) | const
| inline constexpr

Definition at line 196 of file rect.h.

196 {
197 return TRect(left_ * scale, //
198 top_ * scale, //
199 right_ * scale, //
200 bottom_ * scale);
201 }

Referenced by ImGui_ImplImpeller_RenderDrawData(), impeller::TextContents::Render(), impeller::TRect< Scalar >::Scale(), and impeller::testing::TEST().

## ◆ Scale() [4/4]

template<class T >

constexpr TRect impeller::TRect< T >::Scale | ( | Type | scale_x,
|  | Type | scale_y
| ) |  | const
| inline constexpr

Definition at line 203 of file rect.h.

203 {
204 return TRect(left_ * scale_x, //
205 top_ * scale_y, //
206 right_ * scale_x, //
207 bottom_ * scale_y);
208 }

## ◆ Shift() [1/2]

template<class T >

constexpr TRect<T> impeller::TRect< T >::Shift | ( | T | dx,
|  | T | dy
| ) |  | const
| inline constexpr

Returns a new rectangle translated by the given offset.

Definition at line 596 of file rect.h.

596 {
597 return {
598 saturated::Add(left_, dx), //
599 saturated::Add(top_, dy), //
600 saturated::Add(right_, dx), //
601 saturated::Add(bottom_, dy), //
602 };
603 }

Referenced by impeller::TRect< Scalar >::Project(), impeller::TRect< Scalar >::Shift(), and impeller::testing::TEST_P().

## ◆ Shift() [2/2]

template<class T >

constexpr TRect<T> impeller::TRect< T >::Shift | ( | TPoint< T > | offset | ) | const
| inline constexpr

Returns a new rectangle translated by the given offset.

Definition at line 606 of file rect.h.

606 {
607 return Shift(offset.x, offset.y);
608 }

## ◆ TransformAndClipBounds()

template<class T >

constexpr TRect impeller::TRect< T >::TransformAndClipBounds | ( | const Matrix & | transform | ) | const
| inline constexpr

Creates a new bounding box that contains this transformed rectangle, clipped against the near clipping plane if necessary.

Definition at line 432 of file rect.h.

433 {
434 if (!transform.HasPerspective2D()) {
435 return TransformBounds(transform);
436 }
437
438 if (IsEmpty()) {
439 return {};
440 }
441
442 auto ul = transform.TransformHomogenous({left_, top_});
443 auto ur = transform.TransformHomogenous({right_, top_});
444 auto ll = transform.TransformHomogenous({left_, bottom_});
445 auto lr = transform.TransformHomogenous({right_, bottom_});
446
447 // It can probably be proven that we only ever have 5 points at most
448 // which happens when only 1 corner is clipped and we get 2 points
449 // in return for it as we interpolate against its neighbors.
450 Point points[8];
451 int index = 0;
452
453 // Process (clip and interpolate) each point against its 2 neighbors:
454 // left, pt, right
455 index = ClipAndInsert(points, index, ll, ul, ur);
456 index = ClipAndInsert(points, index, ul, ur, lr);
457 index = ClipAndInsert(points, index, ur, lr, ll);
458 index = ClipAndInsert(points, index, lr, ll, ul);
459
460 auto bounds = TRect::MakePointBounds(points, points + index);
461 return bounds.value_or(TRect{});
462 }

Referenced by impeller::testing::TEST().

## ◆ TransformBounds()

template<class T >

constexpr TRect impeller::TRect< T >::TransformBounds | ( | const Matrix & | transform | ) | const
| inline constexpr

Creates a new bounding box that contains this transformed rectangle.

Definition at line 466 of file rect.h.

466 {
467 if (IsEmpty()) {
468 return {};
469 }
470 auto points = GetTransformedPoints(transform);
471 auto bounds = TRect::MakePointBounds(points.begin(), points.end());
472 if (bounds.has_value()) {
473 return bounds.value();
474 }
475 FML_UNREACHABLE();
476 }

Referenced by impeller::DlAtlasGeometry::ComputeBoundingBox(), impeller::ComputeSaveLayerCoverage(), impeller::RectGeometry::CoversArea(), impeller::RoundRectGeometry::CoversArea(), impeller::DlDispatcherBase::drawDisplayList(), impeller::TextureFilterInput::GetCoverage(), impeller::RectGeometry::GetCoverage(), impeller::DlVerticesGeometry::GetCoverage(), impeller::Snapshot::GetCoverage(), impeller::AtlasContents::GetCoverage(), impeller::TextureContents::GetCoverage(), impeller::MatrixFilterContents::GetFilterCoverage(), impeller::LocalMatrixFilterContents::GetFilterSourceCoverage(), and impeller::TRect< Scalar >::TransformAndClipBounds().

## ◆ Union() [1/4]

template<class T >

constexpr static std::optional<TRect> impeller::TRect< T >::Union | ( | const std::optional< TRect< T > > | a,
|  | const std::optional< TRect< T > > | b
| ) |  |
| inline static constexpr

Definition at line 700 of file rect.h.

702 {
703 return a.has_value() ? Union(a.value(), b) : b;
704 }

## ◆ Union() [2/4]

template<class T >

constexpr static std::optional<TRect> impeller::TRect< T >::Union | ( | const std::optional< TRect< T > > | a,
|  | const TRect< T > & | b
| ) |  |
| inline static constexpr

Definition at line 694 of file rect.h.

696 {
697 return a.has_value() ? a->Union(b) : b;
698 }

## ◆ Union() [3/4]

template<class T >

constexpr static std::optional<TRect> impeller::TRect< T >::Union | ( | const TRect< T > & | a,
|  | const std::optional< TRect< T > > | b
| ) |  |
| inline static constexpr

Definition at line 688 of file rect.h.

690 {
691 return b.has_value() ? a.Union(b.value()) : a;
692 }

## ◆ Union() [4/4]

template<class T >

constexpr TRect impeller::TRect< T >::Union | ( | const TRect< T > & | o | ) | const
| inline constexpr

Definition at line 507 of file rect.h.

507 {
508 if (IsEmpty()) {
509 return o;
510 }
511 if (o.IsEmpty()) {
512 return *this;
513 }
514 return {
515 std::min(left_, o.left_),
516 std::min(top_, o.top_),
517 std::max(right_, o.right_),
518 std::max(bottom_, o.bottom_),
519 };
520 }

Referenced by impeller::DlAtlasGeometry::ComputeBoundingBox(), impeller::testing::TEST(), and impeller::TRect< Scalar >::Union().

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

- impeller/geometry/rect.h

impeller::TRect::GetLTRB
constexpr std::array< T, 4 > GetLTRB() const
Definition: rect.h:381
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::TRect::MakeXYWH
constexpr static TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition: rect.h:136
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:466
impeller::TRect::Intersection
constexpr std::optional< TRect > Intersection(const TRect &o) const
Definition: rect.h:522
impeller::TRect::TRect
constexpr TRect()
Definition: rect.h:127
impeller::TRect::GetHeight
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:341
offset
SeparatedVector2 offset
Definition: stroke_path_geometry.cc:304
impeller::TRect::IntersectsWithRect
constexpr bool IntersectsWithRect(const TRect &o) const
Definition: rect.h:540
impeller::TRect::GetPoints
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 tr...
Definition: rect.h:408
impeller::TRect::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:155
impeller::TRect::Shift
constexpr TRect< T > Shift(T dx, T dy) const
Returns a new rectangle translated by the given offset.
Definition: rect.h:596
impeller::TRect::IsEmpty
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: rect.h:291
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
impeller::TRect::GetTransformedPoints
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
Definition: rect.h:420
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:213
impeller::TRect::GetWidth
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:335
impeller::TRect::Scale
constexpr TRect Scale(Type scale) const
Definition: rect.h:196
impeller::TRect::Cutout
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 specifi...
Definition: rect.h:551
impeller::TRect::MakeMaximum
constexpr static TRect MakeMaximum()
Definition: rect.h:178
impeller::saturated::b
SI b
Definition: saturated_math.h:87
scale
const Scalar scale
Definition: stroke_path_geometry.cc:301
impeller::TRect::Union
constexpr TRect Union(const TRect &o) const
Definition: rect.h:507
impeller::TRect::MakeLTRB
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129
impeller::Matrix::MakeScale
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:104
impeller::TRect::Expand
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
Definition: rect.h:612