Flutter Impeller
impeller::TRect< T > Struct Template Reference

#include <rect.h>

Public Member Functions

constexpr TRect ()
 
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...
 
template<class U , class FT = T>
constexpr std::enable_if_t< std::is_floating_point_v< FT >, bool > Contains (const TRect< U > &o) const
 
 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 std::optional< TRect< T > > ExpandToMinTransformedSize (TSize< T > min_transformed_size, const Matrix &transform) const
 Returns a rectangle with edges expanded to satisfy a minimum size in a 2D-transformed coordinate space. This function is not valid for a matrix with perspective elements. 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)
 
 RoundIn (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)
 
constexpr static TRect MakeCircleBounds (const TPoint< Type > &center, Type radius)
 
constexpr static TRect MakeEllipseBounds (const TPoint< Type > &center, const TSize< Type > &radii)
 
constexpr static TRect MakeEllipseBounds (const TPoint< Type > &center, const TPoint< Type > &radii)
 
template<class U , class FT = T>
constexpr static std::enable_if_t< std::is_floating_point_v< FT >, TRect > Make (const TRect< U > &rect)
 
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 TRect Union (const TRect &a, const std::optional< TRect > b)
 
constexpr static 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()

Member Function Documentation

◆ Area()

template<class T >
constexpr T impeller::TRect< T >::Area ( ) const
inlineconstexpr

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

Definition at line 410 of file rect.h.

410  {
411  // TODO(141710): Use saturated math to avoid overflow.
412  return IsEmpty() ? 0 : (right_ - left_) * (bottom_ - top_);
413  }
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: rect.h:331

References impeller::TRect< T >::IsEmpty().

◆ Contains() [1/3]

template<class T >
constexpr bool impeller::TRect< T >::Contains ( const TPoint< Type > &  p) const
inlineconstexpr

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 255 of file rect.h.

255  {
256  return !this->IsEmpty() && //
257  p.x >= left_ && //
258  p.y >= top_ && //
259  p.x < right_ && //
260  p.y < bottom_;
261  }

References impeller::TRect< T >::IsEmpty(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by impeller::RoundRect::Contains(), impeller::RoundSuperellipse::Contains(), impeller::FillPathSourceGeometry::CoversArea(), impeller::FillRectGeometry::CoversArea(), impeller::RoundRectGeometry::CoversArea(), impeller::FillRoundRectGeometry::CoversArea(), impeller::RoundSuperellipseGeometry::CoversArea(), impeller::UberSDFGeometry::CoversArea(), impeller::TiledTextureContents::RenderToSnapshot(), and impeller::testing::TEST().

◆ Contains() [2/3]

template<class T >
constexpr bool impeller::TRect< T >::Contains ( const TRect< T > &  o) const
inlineconstexpr

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 297 of file rect.h.

297  {
298  return !this->IsEmpty() && //
299  (o.IsEmpty() || (o.left_ >= left_ && //
300  o.top_ >= top_ && //
301  o.right_ <= right_ && //
302  o.bottom_ <= bottom_));
303  }

References impeller::TRect< T >::IsEmpty().

◆ Contains() [3/3]

template<class T >
template<class U , class FT = T>
constexpr std::enable_if_t<std::is_floating_point_v<FT>, bool> impeller::TRect< T >::Contains ( const TRect< U > &  o) const
inlineconstexpr

Definition at line 307 of file rect.h.

307  {
308  return !this->IsEmpty() && //
309  (o.IsEmpty() || (o.GetLeft() >= left_ && //
310  o.GetTop() >= top_ && //
311  o.GetRight() <= right_ && //
312  o.GetBottom() <= bottom_));
313  }

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), and impeller::TRect< T >::IsEmpty().

◆ ContainsInclusive()

template<class T >
constexpr bool impeller::TRect< T >::ContainsInclusive ( const TPoint< Type > &  p) const
inlineconstexpr

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 274 of file rect.h.

274  {
275  return !this->IsEmpty() && //
276  p.x >= left_ && //
277  p.y >= top_ && //
278  p.x <= right_ && //
279  p.y <= bottom_;
280  }

References impeller::TRect< T >::IsEmpty(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

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

◆ Cutout()

template<class T >
constexpr std::optional<TRect<T> > impeller::TRect< T >::Cutout ( const TRect< T > &  o) const
inlineconstexpr

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

Definition at line 591 of file rect.h.

591  {
592  if (IsEmpty()) {
593  // This test isn't just a short-circuit, it also prevents the concise
594  // math below from returning the wrong answer on empty rects.
595  // Once we know that this rectangle is not empty, the math below can
596  // only succeed in computing a value if o is also non-empty and non-nan.
597  // Otherwise, the method returns *this by default.
598  return std::nullopt;
599  }
600 
601  const auto& [a_left, a_top, a_right, a_bottom] = GetLTRB(); // Source rect.
602  const auto& [b_left, b_top, b_right, b_bottom] = o.GetLTRB(); // Cutout.
603  if (b_left <= a_left && b_right >= a_right) {
604  if (b_top <= a_top && b_bottom >= a_bottom) {
605  // Full cutout.
606  return std::nullopt;
607  }
608  if (b_top <= a_top && b_bottom > a_top) {
609  // Cuts off the top.
610  return TRect::MakeLTRB(a_left, b_bottom, a_right, a_bottom);
611  }
612  if (b_bottom >= a_bottom && b_top < a_bottom) {
613  // Cuts off the bottom.
614  return TRect::MakeLTRB(a_left, a_top, a_right, b_top);
615  }
616  }
617  if (b_top <= a_top && b_bottom >= a_bottom) {
618  if (b_left <= a_left && b_right > a_left) {
619  // Cuts off the left.
620  return TRect::MakeLTRB(b_right, a_top, a_right, a_bottom);
621  }
622  if (b_right >= a_right && b_left < a_right) {
623  // Cuts off the right.
624  return TRect::MakeLTRB(a_left, a_top, b_left, a_bottom);
625  }
626  }
627 
628  return *this;
629  }
constexpr std::array< T, 4 > GetLTRB() const
Definition: rect.h:421
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129

References impeller::TRect< T >::GetLTRB(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::MakeLTRB().

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

◆ CutoutOrEmpty()

template<class T >
constexpr TRect impeller::TRect< T >::CutoutOrEmpty ( const TRect< T > &  o) const
inlineconstexpr

Definition at line 631 of file rect.h.

631  {
632  return Cutout(o).value_or(TRect());
633  }
constexpr TRect()
Definition: rect.h:127
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:591

References impeller::TRect< T >::Cutout(), and impeller::TRect< T >::TRect().

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

◆ Expand() [1/5]

template<class T >
constexpr TRect<T> impeller::TRect< T >::Expand ( T  amount) const
inlineconstexpr

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

Definition at line 666 of file rect.h.

666  {
667  return {
668  saturated::Sub(left_, amount), //
669  saturated::Sub(top_, amount), //
670  saturated::Add(right_, amount), //
671  saturated::Add(bottom_, amount), //
672  };
673  }

◆ Expand() [2/5]

template<class T >
constexpr TRect<T> impeller::TRect< T >::Expand ( T  horizontal_amount,
T  vertical_amount 
) const
inlineconstexpr

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

Definition at line 677 of file rect.h.

678  {
679  return {
680  saturated::Sub(left_, horizontal_amount), //
681  saturated::Sub(top_, vertical_amount), //
682  saturated::Add(right_, horizontal_amount), //
683  saturated::Add(bottom_, vertical_amount), //
684  };
685  }

◆ Expand() [3/5]

◆ Expand() [4/5]

template<class T >
constexpr TRect<T> impeller::TRect< T >::Expand ( TPoint< T >  amount) const
inlineconstexpr

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

Definition at line 689 of file rect.h.

689  {
690  return Expand(amount.x, amount.y);
691  }
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:652

References impeller::TRect< T >::Expand(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

◆ Expand() [5/5]

template<class T >
constexpr TRect<T> impeller::TRect< T >::Expand ( TSize< T >  amount) const
inlineconstexpr

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

Definition at line 695 of file rect.h.

695  {
696  return Expand(amount.width, amount.height);
697  }

References impeller::TRect< T >::Expand(), impeller::TSize< T >::height, and impeller::TSize< T >::width.

◆ ExpandToMinTransformedSize()

template<class T >
constexpr std::optional<TRect<T> > impeller::TRect< T >::ExpandToMinTransformedSize ( TSize< T >  min_transformed_size,
const Matrix &  transform 
) const
inlineconstexpr

Returns a rectangle with edges expanded to satisfy a minimum size in a 2D-transformed coordinate space. This function is not valid for a matrix with perspective elements.

If the transform has a scaling factor of zero in either dimension, it cannot be expanded to the minimum size. This returns nullopt.

Definition at line 705 of file rect.h.

707  {
708  FML_DCHECK(!transform.HasPerspective2D());
709 
710  Vector2 transform_scaling = transform.GetBasisScaleXY();
711  if (transform_scaling.x == 0.0f || transform_scaling.y == 0.0f) {
712  return std::nullopt;
713  }
714 
715  Size min_local_size =
716  Size(min_transformed_size.width / transform_scaling.x,
717  min_transformed_size.height / transform_scaling.y);
718  if (!min_local_size.IsFinite()) {
719  return std::nullopt;
720  }
721  Size current_size = GetSize();
722 
723  if (current_size.width >= min_local_size.width &&
724  current_size.height >= min_local_size.height) {
725  // No expansion needed.
726  return *this;
727  }
728 
729  Size expanded_size = current_size.Max(min_local_size);
730  return MakeEllipseBounds(GetCenter(), Point(expanded_size.width * 0.5f,
731  expanded_size.height * 0.5f));
732  }
Point Vector2
Definition: point.h:430
TPoint< Scalar > Point
Definition: point.h:426
TSize< Scalar > Size
Definition: size.h:159
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
Definition: rect.h:361
constexpr Point GetCenter() const
Get the center point as a |Point|.
Definition: rect.h:416
constexpr static TRect MakeEllipseBounds(const TPoint< Type > &center, const TSize< Type > &radii)
Definition: rect.h:164
constexpr TSize Max(const TSize &o) const
Definition: size.h:97

References impeller::TRect< T >::GetCenter(), impeller::TRect< T >::GetSize(), impeller::TSize< T >::height, impeller::TSize< T >::IsFinite(), impeller::TRect< T >::MakeEllipseBounds(), impeller::TSize< T >::Max(), transform, impeller::TSize< T >::width, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

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

◆ GetBottom()

◆ GetCenter()

◆ GetHeight()

◆ GetLeft()

◆ GetLeftBottom()

template<class T >
constexpr TPoint<T> impeller::TRect< T >::GetLeftBottom ( ) const
inlineconstexpr

◆ GetLeftTop()

◆ GetLTRB()

template<class T >
constexpr std::array<T, 4> impeller::TRect< T >::GetLTRB ( ) const
inlineconstexpr

Definition at line 421 of file rect.h.

421  {
422  return {left_, top_, right_, bottom_};
423  }

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

◆ GetNormalizingTransform()

template<class T >
constexpr Matrix impeller::TRect< T >::GetNormalizingTransform ( ) const
inlineconstexpr

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 525 of file rect.h.

525  {
526  if (!IsEmpty()) {
527  Scalar sx = 1.0 / GetWidth();
528  Scalar sy = 1.0 / GetHeight();
529  Scalar tx = left_ * -sx;
530  Scalar ty = top_ * -sy;
531 
532  // Exclude NaN and infinities and either scale underflowing to zero
533  if (sx != 0.0 && sy != 0.0 && 0.0 * sx * sy * tx * ty == 0.0) {
534  // clang-format off
535  return Matrix( sx, 0.0f, 0.0f, 0.0f,
536  0.0f, sy, 0.0f, 0.0f,
537  0.0f, 0.0f, 1.0f, 0.0f,
538  tx, ty, 0.0f, 1.0f);
539  // clang-format on
540  }
541  }
542 
543  // Map all coordinates to the origin.
544  return Matrix::MakeScale({0.0f, 0.0f, 1.0f});
545  }
float Scalar
Definition: scalar.h:19
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:104
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:381
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:375

References impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::IsEmpty(), and impeller::Matrix::MakeScale().

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

◆ GetOrigin()

template<class T >
constexpr TPoint<Type> impeller::TRect< T >::GetOrigin ( ) const
inlineconstexpr

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 354 of file rect.h.

354  {
355  return {left_, top_};
356  }

Referenced by impeller::AdvancedBlend(), impeller::DirectionalMorphologyFilterContents::GetFilterCoverage(), impeller::PipelineBlend(), impeller::SolidRRectLikeBlurContents::Render(), impeller::Canvas::Restore(), and impeller::testing::TEST().

◆ GetPoints()

template<class T >
constexpr std::array<TPoint<T>, 4> impeller::TRect< T >::GetPoints ( ) const
inlineconstexpr

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 448 of file rect.h.

448  {
449  if (IsEmpty()) {
450  return {};
451  }
452  return {
453  TPoint{left_, top_},
454  TPoint{right_, top_},
455  TPoint{left_, bottom_},
456  TPoint{right_, bottom_},
457  };
458  }

References impeller::TRect< T >::IsEmpty().

Referenced by impeller::DrawImageRectAtlasGeometry::CreateBlendVertexBuffer(), impeller::DrawImageRectAtlasGeometry::CreateSimpleVertexBuffer(), impeller::FillRectGeometry::GetPositionBuffer(), impeller::TRect< T >::GetTransformedPoints(), impeller::ClipContents::Render(), and impeller::testing::TEST().

◆ GetPositive()

template<class T >
constexpr TRect impeller::TRect< T >::GetPositive ( ) const
inlineconstexpr

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

Definition at line 432 of file rect.h.

432  {
433  if (!IsEmpty()) {
434  return *this;
435  }
436  return {
437  std::min(left_, right_),
438  std::min(top_, bottom_),
439  std::max(left_, right_),
440  std::max(top_, bottom_),
441  };
442  }

References impeller::TRect< T >::IsEmpty().

Referenced by impeller::DashedLinePathSource::GetBounds(), impeller::RoundRect::MakeRectRadii(), impeller::RoundSuperellipse::MakeRectRadii(), impeller::SolidRRectLikeBlurContents::Render(), impeller::RoundingRadii::Scaled(), and impeller::testing::TEST().

◆ GetRight()

◆ GetRightBottom()

template<class T >
constexpr TPoint<T> impeller::TRect< T >::GetRightBottom ( ) const
inlineconstexpr

◆ GetRightTop()

template<class T >
constexpr TPoint<T> impeller::TRect< T >::GetRightTop ( ) const
inlineconstexpr

◆ GetSize()

◆ GetTop()

◆ GetTransformedPoints()

template<class T >
constexpr std::array<TPoint<T>, 4> impeller::TRect< T >::GetTransformedPoints ( const Matrix &  transform) const
inlineconstexpr

Definition at line 460 of file rect.h.

461  {
462  auto points = GetPoints();
463  for (size_t i = 0; i < points.size(); i++) {
464  points[i] = transform * points[i];
465  }
466  return points;
467  }
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:448
std::vector< Point > points

References impeller::TRect< T >::GetPoints(), points, and transform.

Referenced by impeller::GaussianBlurFilterContents::CalculateUVs(), impeller::Snapshot::GetCoverageUVs(), impeller::testing::TEST(), and impeller::TRect< T >::TransformBounds().

◆ GetWidth()

◆ GetX()

◆ GetXYWH()

template<class T >
constexpr std::array<T, 4> impeller::TRect< T >::GetXYWH ( ) const
inlineconstexpr

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

Definition at line 427 of file rect.h.

427  {
428  return {left_, top_, GetWidth(), GetHeight()};
429  }

References impeller::TRect< T >::GetHeight(), and impeller::TRect< T >::GetWidth().

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

◆ GetY()

◆ 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 
)
inlinestaticconstexpr

Definition at line 799 of file rect.h.

801  {
802  return a.has_value() ? Intersection(a.value(), b) : b;
803  }
constexpr std::optional< TRect > Intersection(const TRect &o) const
Definition: rect.h:562

References impeller::saturated::b, and impeller::TRect< T >::Intersection().

◆ 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 
)
inlinestaticconstexpr

Definition at line 793 of file rect.h.

795  {
796  return a.has_value() ? a->Intersection(b) : b;
797  }

References impeller::saturated::b.

◆ 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 
)
inlinestaticconstexpr

Definition at line 787 of file rect.h.

789  {
790  return b.has_value() ? a.Intersection(b.value()) : a;
791  }

References impeller::saturated::b, and impeller::TRect< T >::Intersection().

◆ Intersection() [4/4]

template<class T >
constexpr std::optional<TRect> impeller::TRect< T >::Intersection ( const TRect< T > &  o) const
inlineconstexpr

Definition at line 562 of file rect.h.

563  {
564  if (IntersectsWithRect(o)) {
565  return TRect{
566  std::max(left_, o.left_),
567  std::max(top_, o.top_),
568  std::min(right_, o.right_),
569  std::min(bottom_, o.bottom_),
570  };
571  } else {
572  return std::nullopt;
573  }
574  }
constexpr bool IntersectsWithRect(const TRect &o) const
Definition: rect.h:580

References impeller::TRect< T >::IntersectsWithRect().

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

◆ IntersectionOrEmpty()

template<class T >
constexpr TRect impeller::TRect< T >::IntersectionOrEmpty ( const TRect< T > &  o) const
inlineconstexpr

Definition at line 576 of file rect.h.

576  {
577  return Intersection(o).value_or(TRect());
578  }

References impeller::TRect< T >::Intersection(), and impeller::TRect< T >::TRect().

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

◆ IntersectsWithRect()

template<class T >
constexpr bool impeller::TRect< T >::IntersectsWithRect ( const TRect< T > &  o) const
inlineconstexpr

Definition at line 580 of file rect.h.

580  {
581  return !IsEmpty() && //
582  !o.IsEmpty() && //
583  left_ < o.right_ && //
584  top_ < o.bottom_ && //
585  right_ > o.left_ && //
586  bottom_ > o.top_;
587  }

References impeller::TRect< T >::IsEmpty().

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

◆ IsEmpty()

◆ 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 322 of file rect.h.

322  {
323  return std::isfinite(left_) && //
324  std::isfinite(top_) && //
325  std::isfinite(right_) && //
326  std::isfinite(bottom_);
327  }

Referenced by impeller::Arc::Arc(), impeller::RoundRect::IsFinite(), impeller::RoundSuperellipse::IsFinite(), impeller::RoundRect::MakeRectRadii(), impeller::RoundSuperellipse::MakeRectRadii(), and impeller::testing::TEST().

◆ IsMaximum()

template<class T >
constexpr bool impeller::TRect< T >::IsMaximum ( ) const
inlineconstexpr

Definition at line 348 of file rect.h.

348  {
349  return *this == MakeMaximum();
350  }
constexpr static TRect MakeMaximum()
Definition: rect.h:212

References impeller::TRect< T >::MakeMaximum().

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

◆ IsSquare()

template<class T >
constexpr bool impeller::TRect< T >::IsSquare ( ) const
inlineconstexpr

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

Definition at line 338 of file rect.h.

338  {
339  // empty rectangles can technically be "square", but would be
340  // misleading to most callers. Using |IsEmpty| also prevents
341  // "non-empty and non-overflowing" computations from happening
342  // to be equal to "empty and overflowing" results.
343  // (Consider LTRB(10, 15, MAX-2, MIN+2) which is empty, but both
344  // w/h subtractions equal "5").
345  return !IsEmpty() && (right_ - left_) == (bottom_ - top_);
346  }

References impeller::TRect< T >::IsEmpty().

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

◆ Make()

template<class T >
template<class U , class FT = T>
constexpr static std::enable_if_t<std::is_floating_point_v<FT>, TRect> impeller::TRect< T >::Make ( const TRect< U > &  rect)
inlinestaticconstexpr

Construct a floating point rect |Rect| from another Rect of a potentially different storage type (eg. |IRect|).

Definition at line 181 of file rect.h.

182  {
183  return MakeLTRB(
184  static_cast<FT>(rect.GetLeft()), static_cast<FT>(rect.GetTop()),
185  static_cast<FT>(rect.GetRight()), static_cast<FT>(rect.GetBottom()));
186  }

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), and impeller::TRect< T >::MakeLTRB().

◆ MakeCircleBounds()

template<class T >
constexpr static TRect impeller::TRect< T >::MakeCircleBounds ( const TPoint< Type > &  center,
Type  radius 
)
inlinestaticconstexpr

Construct the rectangular bounds of a circle with the supplied center point and uniform radius.

Definition at line 156 of file rect.h.

157  {
158  return MakeLTRB(center.x - radius, center.y - radius, //
159  center.x + radius, center.y + radius);
160  }

References impeller::TRect< T >::MakeLTRB(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

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

◆ MakeEllipseBounds() [1/2]

template<class T >
constexpr static TRect impeller::TRect< T >::MakeEllipseBounds ( const TPoint< Type > &  center,
const TPoint< Type > &  radii 
)
inlinestaticconstexpr

Construct the rectangular bounds of a circle with the supplied center point and non-uniform horizontal and vertical radii.

Definition at line 172 of file rect.h.

173  {
174  return MakeLTRB(center.x - radii.x, center.y - radii.y, //
175  center.x + radii.x, center.y + radii.y);
176  }

References impeller::TRect< T >::MakeLTRB(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

◆ MakeEllipseBounds() [2/2]

template<class T >
constexpr static TRect impeller::TRect< T >::MakeEllipseBounds ( const TPoint< Type > &  center,
const TSize< Type > &  radii 
)
inlinestaticconstexpr

Construct the rectangular bounds of a circle with the supplied center point and non-uniform horizontal and vertical radii.

Definition at line 164 of file rect.h.

165  {
166  return MakeLTRB(center.x - radii.width, center.y - radii.height, //
167  center.x + radii.width, center.y + radii.height);
168  }

References impeller::TSize< T >::height, impeller::TRect< T >::MakeLTRB(), impeller::TSize< T >::width, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by impeller::TRect< T >::ExpandToMinTransformedSize(), and impeller::testing::TEST().

◆ MakeLTRB()

◆ MakeMaximum()

template<class T >
constexpr static TRect impeller::TRect< T >::MakeMaximum ( )
inlinestaticconstexpr

Definition at line 212 of file rect.h.

212  {
213  return TRect::MakeLTRB(std::numeric_limits<Type>::lowest(),
214  std::numeric_limits<Type>::lowest(),
215  std::numeric_limits<Type>::max(),
216  std::numeric_limits<Type>::max());
217  }

References impeller::TRect< T >::MakeLTRB().

Referenced by impeller::TRect< T >::IsMaximum(), and impeller::testing::TEST().

◆ MakeOriginSize()

template<class T >
constexpr static TRect impeller::TRect< T >::MakeOriginSize ( const TPoint< Type > &  origin,
const TSize< Type > &  size 
)
inlinestaticconstexpr

Definition at line 144 of file rect.h.

145  {
146  return MakeXYWH(origin.x, origin.y, size.width, size.height);
147  }
constexpr static TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition: rect.h:136

References impeller::TSize< T >::height, impeller::TRect< T >::MakeXYWH(), impeller::TSize< T >::width, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by 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 
)
inlinestaticconstexpr

Definition at line 194 of file rect.h.

195  {
196  if (first == last) {
197  return std::nullopt;
198  }
199  auto left = first->x;
200  auto top = first->y;
201  auto right = first->x;
202  auto bottom = first->y;
203  for (auto it = first + 1; it < last; ++it) {
204  left = std::min(left, it->x);
205  top = std::min(top, it->y);
206  right = std::max(right, it->x);
207  bottom = std::max(bottom, it->y);
208  }
209  return TRect::MakeLTRB(left, top, right, bottom);
210  }

References impeller::TRect< T >::MakeLTRB().

◆ MakePointBounds() [2/2]

template<class T >
template<typename U >
constexpr static std::optional<TRect> impeller::TRect< T >::MakePointBounds ( const U &  value)
inlinestaticconstexpr

Definition at line 189 of file rect.h.

189  {
190  return MakePointBounds(value.begin(), value.end());
191  }
int32_t value
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:189

References value.

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

◆ MakeSize()

◆ MakeWH()

template<class T >
constexpr static TRect impeller::TRect< T >::MakeWH ( Type  width,
Type  height 
)
inlinestaticconstexpr

Definition at line 140 of file rect.h.

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

References impeller::TRect< T >::TRect().

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

◆ MakeXYWH()

template<class T >
constexpr static TRect impeller::TRect< T >::MakeXYWH ( Type  x,
Type  y,
Type  width,
Type  height 
)
inlinestaticconstexpr

Definition at line 136 of file rect.h.

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

References impeller::TRect< T >::TRect(), and x.

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

◆ operator==()

template<class T >
constexpr bool impeller::TRect< T >::operator== ( const TRect< T > &  r) const
inlineconstexpr

Definition at line 219 of file rect.h.

219  {
220  return left_ == r.left_ && //
221  top_ == r.top_ && //
222  right_ == r.right_ && //
223  bottom_ == r.bottom_;
224  }

◆ Project()

template<class T >
constexpr TRect<T> impeller::TRect< T >::Project ( TRect< T >  source) const
inlineconstexpr

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 738 of file rect.h.

738  {
739  if (IsEmpty()) {
740  return {};
741  }
742  return source.Shift(-left_, -top_)
743  .Scale(1.0 / static_cast<Scalar>(GetWidth()),
744  1.0 / static_cast<Scalar>(GetHeight()));
745  }

References impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::IsEmpty(), and impeller::TRect< T >::Shift().

Referenced by impeller::DrawImageRectAtlasGeometry::CreateBlendVertexBuffer(), impeller::DrawImageRectAtlasGeometry::CreateSimpleVertexBuffer(), impeller::DrawImageRectAtlasGeometry::GetStrictSrcRect(), and impeller::TextureContents::Render().

◆ Round()

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

Definition at line 764 of file rect.h.

764  {
765  return TRect::MakeLTRB(saturated::Cast<U, Type>(round(r.GetLeft())),
766  saturated::Cast<U, Type>(round(r.GetTop())),
767  saturated::Cast<U, Type>(round(r.GetRight())),
768  saturated::Cast<U, Type>(round(r.GetBottom())));
769  }

References impeller::TRect< T >::MakeLTRB().

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

◆ RoundIn()

template<class T >
impeller::TRect< T >::RoundIn ( const TRect< U > &  r)
inline

Definition at line 756 of file rect.h.

756  {
757  return TRect::MakeLTRB(saturated::Cast<U, Type>(ceil(r.GetLeft())),
758  saturated::Cast<U, Type>(ceil(r.GetTop())),
759  saturated::Cast<U, Type>(floor(r.GetRight())),
760  saturated::Cast<U, Type>(floor(r.GetBottom())));
761  }

References impeller::TRect< T >::MakeLTRB().

◆ RoundOut()

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

Definition at line 748 of file rect.h.

748  {
749  return TRect::MakeLTRB(saturated::Cast<U, Type>(floor(r.GetLeft())),
750  saturated::Cast<U, Type>(floor(r.GetTop())),
751  saturated::Cast<U, Type>(ceil(r.GetRight())),
752  saturated::Cast<U, Type>(ceil(r.GetBottom())));
753  }

References impeller::TRect< T >::MakeLTRB().

Referenced by ImGui_ImplImpeller_RenderDrawData(), impeller::RenderToTarget(), impeller::Canvas::SaveLayer(), and impeller::testing::TEST().

◆ Scale() [1/4]

template<class T >
constexpr TRect impeller::TRect< T >::Scale ( TPoint< T >  scale) const
inlineconstexpr

Definition at line 240 of file rect.h.

240  {
241  return Scale(scale.x, scale.y);
242  }
constexpr TRect Scale(Type scale) const
Definition: rect.h:226

References impeller::TRect< T >::Scale(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

◆ Scale() [2/4]

template<class T >
constexpr TRect impeller::TRect< T >::Scale ( TSize< T >  scale) const
inlineconstexpr

Definition at line 244 of file rect.h.

244  {
245  return Scale(scale.width, scale.height);
246  }

References impeller::TSize< T >::height, impeller::TRect< T >::Scale(), and impeller::TSize< T >::width.

◆ Scale() [3/4]

template<class T >
constexpr TRect impeller::TRect< T >::Scale ( Type  scale) const
inlineconstexpr

Definition at line 226 of file rect.h.

226  {
227  return TRect(left_ * scale, //
228  top_ * scale, //
229  right_ * scale, //
230  bottom_ * scale);
231  }

References impeller::TRect< T >::TRect().

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

◆ Scale() [4/4]

template<class T >
constexpr TRect impeller::TRect< T >::Scale ( Type  scale_x,
Type  scale_y 
) const
inlineconstexpr

Definition at line 233 of file rect.h.

233  {
234  return TRect(left_ * scale_x, //
235  top_ * scale_y, //
236  right_ * scale_x, //
237  bottom_ * scale_y);
238  }

References impeller::TRect< T >::TRect().

◆ Shift() [1/2]

template<class T >
constexpr TRect<T> impeller::TRect< T >::Shift ( T  dx,
T  dy 
) const
inlineconstexpr

Returns a new rectangle translated by the given offset.

Definition at line 636 of file rect.h.

636  {
637  return {
638  saturated::Add(left_, dx), //
639  saturated::Add(top_, dy), //
640  saturated::Add(right_, dx), //
641  saturated::Add(bottom_, dy), //
642  };
643  }

Referenced by impeller::Canvas::DrawImage(), impeller::TRect< T >::Project(), impeller::RoundRect::Shift(), impeller::RoundSuperellipse::Shift(), impeller::TRect< T >::Shift(), and impeller::testing::TEST_P().

◆ Shift() [2/2]

template<class T >
constexpr TRect<T> impeller::TRect< T >::Shift ( TPoint< T >  offset) const
inlineconstexpr

Returns a new rectangle translated by the given offset.

Definition at line 646 of file rect.h.

646  {
647  return Shift(offset.x, offset.y);
648  }
constexpr TRect< T > Shift(T dx, T dy) const
Returns a new rectangle translated by the given offset.
Definition: rect.h:636

References impeller::TRect< T >::Shift(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

◆ TransformAndClipBounds()

template<class T >
constexpr TRect impeller::TRect< T >::TransformAndClipBounds ( const Matrix &  transform) const
inlineconstexpr

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

Definition at line 472 of file rect.h.

473  {
474  if (!transform.HasPerspective2D()) {
475  return TransformBounds(transform);
476  }
477 
478  if (IsEmpty()) {
479  return {};
480  }
481 
482  auto ul = transform.TransformHomogenous({left_, top_});
483  auto ur = transform.TransformHomogenous({right_, top_});
484  auto ll = transform.TransformHomogenous({left_, bottom_});
485  auto lr = transform.TransformHomogenous({right_, bottom_});
486 
487  // It can probably be proven that we only ever have 5 points at most
488  // which happens when only 1 corner is clipped and we get 2 points
489  // in return for it as we interpolate against its neighbors.
490  Point points[8];
491  int index = 0;
492 
493  // Process (clip and interpolate) each point against its 2 neighbors:
494  // left, pt, right
495  index = ClipAndInsert(points, index, ll, ul, ur);
496  index = ClipAndInsert(points, index, ul, ur, lr);
497  index = ClipAndInsert(points, index, ur, lr, ll);
498  index = ClipAndInsert(points, index, lr, ll, ul);
499 
500  auto bounds = TRect::MakePointBounds(points, points + index);
501  return bounds.value_or(TRect{});
502  }
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:506

References impeller::TRect< T >::IsEmpty(), impeller::TRect< T >::MakePointBounds(), points, transform, and impeller::TRect< T >::TransformBounds().

Referenced by impeller::CircleGeometry::GetCoverage(), impeller::FillRectGeometry::GetCoverage(), impeller::UberSDFGeometry::GetCoverage(), and impeller::testing::TEST().

◆ TransformBounds()

template<class T >
constexpr TRect impeller::TRect< T >::TransformBounds ( const Matrix &  transform) const
inlineconstexpr

Creates a new bounding box that contains this transformed rectangle.

Definition at line 506 of file rect.h.

506  {
507  if (IsEmpty()) {
508  return {};
509  }
511  auto bounds = TRect::MakePointBounds(points.begin(), points.end());
512  if (bounds.has_value()) {
513  return bounds.value();
514  }
515  FML_UNREACHABLE();
516  }
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
Definition: rect.h:460

References impeller::TRect< T >::GetTransformedPoints(), impeller::TRect< T >::IsEmpty(), impeller::TRect< T >::MakePointBounds(), points, and transform.

Referenced by impeller::ComputeSaveLayerCoverage(), impeller::FillRectGeometry::CoversArea(), impeller::RoundRectGeometry::CoversArea(), impeller::FillRoundRectGeometry::CoversArea(), impeller::RoundSuperellipseGeometry::CoversArea(), impeller::UberSDFGeometry::CoversArea(), impeller::DlDispatcherBase::drawDisplayList(), impeller::Canvas::DrawImageRect(), impeller::Snapshot::GetCoverage(), impeller::AtlasContents::GetCoverage(), impeller::ColorFilterAtlasContents::GetCoverage(), impeller::SolidRRectLikeBlurContents::GetCoverage(), impeller::TextureContents::GetCoverage(), impeller::DlVerticesGeometry::GetCoverage(), impeller::PointFieldGeometry::GetCoverage(), impeller::StrokeRectGeometry::GetCoverage(), impeller::MatrixFilterContents::GetFilterCoverage(), impeller::LocalMatrixFilterContents::GetFilterSourceCoverage(), impeller::StrokeSegmentsGeometry::GetStrokeCoverage(), impeller::testing::TEST(), and impeller::TRect< T >::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 
)
inlinestaticconstexpr

Definition at line 781 of file rect.h.

783  {
784  return a.has_value() ? Union(a.value(), b) : b;
785  }
constexpr TRect Union(const TRect &o) const
Definition: rect.h:547

References impeller::saturated::b, and impeller::TRect< T >::Union().

◆ Union() [2/4]

template<class T >
constexpr static TRect impeller::TRect< T >::Union ( const std::optional< TRect< T > >  a,
const TRect< T > &  b 
)
inlinestaticconstexpr

Definition at line 776 of file rect.h.

777  {
778  return a.has_value() ? a->Union(b) : b;
779  }

References impeller::saturated::b, and impeller::TRect< T >::Union().

◆ Union() [3/4]

template<class T >
constexpr static TRect impeller::TRect< T >::Union ( const TRect< T > &  a,
const std::optional< TRect< T > >  b 
)
inlinestaticconstexpr

Definition at line 771 of file rect.h.

772  {
773  return b.has_value() ? a.Union(b.value()) : a;
774  }

References impeller::saturated::b, and impeller::TRect< T >::Union().

◆ Union() [4/4]

template<class T >
constexpr TRect impeller::TRect< T >::Union ( const TRect< T > &  o) const
inlineconstexpr

Definition at line 547 of file rect.h.

547  {
548  if (IsEmpty()) {
549  return o;
550  }
551  if (o.IsEmpty()) {
552  return *this;
553  }
554  return {
555  std::min(left_, o.left_),
556  std::min(top_, o.top_),
557  std::max(right_, o.right_),
558  std::max(bottom_, o.bottom_),
559  };
560  }

References impeller::TRect< T >::IsEmpty().

Referenced by impeller::testing::TEST(), and impeller::TRect< T >::Union().


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