Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 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.
 
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)|).
 
 IsFinite () const
 Returns true if all of the fields of this floating point rectangle are finite.
 
constexpr bool IsEmpty () const
 Returns true if either of the width or height are 0, negative, or NaN.
 
constexpr bool IsSquare () const
 Returns true if width and height are equal and neither is NaN.
 
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.
 
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.
 
constexpr Type GetX () const
 Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
 
constexpr Type GetY () const
 Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
 
constexpr Type GetWidth () const
 Returns the width of the rectangle, equivalent to |GetSize().width|.
 
constexpr Type GetHeight () const
 Returns the height of the rectangle, equivalent to |GetSize().height|.
 
constexpr auto GetLeft () const
 
constexpr auto GetTop () const
 
constexpr auto GetRight () const
 
constexpr auto GetBottom () const
 
constexpr TPoint< TGetLeftTop () const
 
constexpr TPoint< TGetRightTop () const
 
constexpr TPoint< TGetLeftBottom () const
 
constexpr TPoint< TGetRightBottom () const
 
constexpr T Area () const
 Get the area of the rectangle, equivalent to |GetSize().Area()|.
 
constexpr Point GetCenter () const
 Get the center point as a |Point|.
 
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.
 
constexpr TRect GetPositive () const
 Get a version of this rectangle that has a non-negative size.
 
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.
 
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.
 
constexpr TRect TransformBounds (const Matrix &transform) const
 Creates a new bounding box that contains this transformed rectangle.
 
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).
 
constexpr TRect Union (const TRect &o) const
 
constexpr std::optional< TRectIntersection (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.
 
constexpr TRect CutoutOrEmpty (const TRect &o) const
 
constexpr TRect< TShift (T dx, T dy) const
 Returns a new rectangle translated by the given offset.
 
constexpr TRect< TShift (TPoint< T > offset) const
 Returns a new rectangle translated by the given offset.
 
constexpr TRect< TExpand (T left, T top, T right, T bottom) const
 Returns a rectangle with expanded edges. Negative expansion results in shrinking.
 
constexpr TRect< TExpand (T amount) const
 Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.
 
constexpr TRect< TExpand (T horizontal_amount, T vertical_amount) const
 Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.
 
constexpr TRect< TExpand (TPoint< T > amount) const
 Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.
 
constexpr TRect< TExpand (TSize< T > amount) const
 Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.
 
constexpr TRect< TProject (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.
 
 RoundOut (const TRect< U > &r)
 
 Round (const TRect< U > &r)
 

Static Public Member Functions

static constexpr TRect MakeLTRB (Type left, Type top, Type right, Type bottom)
 
static constexpr TRect MakeXYWH (Type x, Type y, Type width, Type height)
 
static constexpr TRect MakeOriginSize (const TPoint< Type > &origin, const TSize< Type > &size)
 
template<class U >
static constexpr TRect MakeSize (const TSize< U > &size)
 
template<typename U >
static constexpr std::optional< TRectMakePointBounds (const U &value)
 
template<typename PointIter >
static constexpr std::optional< TRectMakePointBounds (const PointIter first, const PointIter last)
 
static constexpr TRect MakeMaximum ()
 
static constexpr std::optional< TRectUnion (const TRect &a, const std::optional< TRect > b)
 
static constexpr std::optional< TRectUnion (const std::optional< TRect > a, const TRect &b)
 
static constexpr std::optional< TRectUnion (const std::optional< TRect > a, const std::optional< TRect > b)
 
static constexpr std::optional< TRectIntersection (const TRect &a, const std::optional< TRect > b)
 
static constexpr std::optional< TRectIntersection (const std::optional< TRect > a, const TRect &b)
 
static constexpr std::optional< TRectIntersection (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 ( )
inlineconstexpr

Definition at line 127 of file rect.h.

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

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

343 {
344 // TODO(flutter/flutter#141710) - Use saturated math to avoid overflow
345 // https://github.com/flutter/flutter/issues/141710
346 return IsEmpty() ? 0 : (right_ - left_) * (bottom_ - top_);
347 }
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition rect.h:264

◆ Contains() [1/2]

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

217 {
218 return !this->IsEmpty() && //
219 p.x >= left_ && //
220 p.y >= top_ && //
221 p.x < right_ && //
222 p.y < bottom_;
223 }

◆ Contains() [2/2]

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

240 {
241 return !this->IsEmpty() && //
242 (o.IsEmpty() || (o.left_ >= left_ && //
243 o.top_ >= top_ && //
244 o.right_ <= right_ && //
245 o.bottom_ <= bottom_));
246 }

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

521 {
522 if (IsEmpty()) {
523 // This test isn't just a short-circuit, it also prevents the concise
524 // math below from returning the wrong answer on empty rects.
525 // Once we know that this rectangle is not empty, the math below can
526 // only succeed in computing a value if o is also non-empty and non-nan.
527 // Otherwise, the method returns *this by default.
528 return std::nullopt;
529 }
530
531 const auto& [a_left, a_top, a_right, a_bottom] = GetLTRB(); // Source rect.
532 const auto& [b_left, b_top, b_right, b_bottom] = o.GetLTRB(); // Cutout.
533 if (b_left <= a_left && b_right >= a_right) {
534 if (b_top <= a_top && b_bottom >= a_bottom) {
535 // Full cutout.
536 return std::nullopt;
537 }
538 if (b_top <= a_top && b_bottom > a_top) {
539 // Cuts off the top.
540 return TRect::MakeLTRB(a_left, b_bottom, a_right, a_bottom);
541 }
542 if (b_bottom >= a_bottom && b_top < a_bottom) {
543 // Cuts off the bottom.
544 return TRect::MakeLTRB(a_left, a_top, a_right, b_top);
545 }
546 }
547 if (b_top <= a_top && b_bottom >= a_bottom) {
548 if (b_left <= a_left && b_right > a_left) {
549 // Cuts off the left.
550 return TRect::MakeLTRB(b_right, a_top, a_right, a_bottom);
551 }
552 if (b_right >= a_right && b_left < a_right) {
553 // Cuts off the right.
554 return TRect::MakeLTRB(a_left, a_top, b_left, a_bottom);
555 }
556 }
557
558 return *this;
559 }
constexpr std::array< T, 4 > GetLTRB() const
Definition rect.h:355
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129

◆ CutoutOrEmpty()

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

Definition at line 561 of file rect.h.

561 {
562 return Cutout(o).value_or(TRect());
563 }
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:521
constexpr TRect()
Definition rect.h:127

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

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

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

608 {
609 return {
610 saturated::Sub(left_, horizontal_amount), //
611 saturated::Sub(top_, vertical_amount), //
612 saturated::Add(right_, horizontal_amount), //
613 saturated::Add(bottom_, vertical_amount), //
614 };
615 }

◆ Expand() [3/5]

template<class T >
constexpr TRect< T > impeller::TRect< T >::Expand ( T  left,
T  top,
T  right,
T  bottom 
) const
inlineconstexpr

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

Definition at line 582 of file rect.h.

585 {
586 return {
587 saturated::Sub(left_, left), //
588 saturated::Sub(top_, top), //
589 saturated::Add(right_, right), //
590 saturated::Add(bottom_, bottom), //
591 };
592 }
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)

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

619 {
620 return Expand(amount.x, amount.y);
621 }
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:582

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

625 {
626 return Expand(amount.width, amount.height);
627 }

◆ GetBottom()

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

Definition at line 324 of file rect.h.

324{ return bottom_; }

◆ GetCenter()

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

Get the center point as a |Point|.

Definition at line 350 of file rect.h.

350 {
351 return {saturated::AverageScalar(left_, right_),
352 saturated::AverageScalar(top_, bottom_)};
353 }

◆ GetHeight()

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

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

Definition at line 314 of file rect.h.

314 {
315 return saturated::Sub(bottom_, top_);
316 }

◆ GetLeft()

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

Definition at line 318 of file rect.h.

318{ return left_; }

◆ GetLeftBottom()

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

Definition at line 334 of file rect.h.

334 {
335 return {left_, bottom_};
336 }

◆ GetLeftTop()

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

Definition at line 326 of file rect.h.

326 { //
327 return {left_, top_};
328 }

◆ GetLTRB()

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

Definition at line 355 of file rect.h.

355 {
356 return {left_, top_, right_, bottom_};
357 }

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

459 {
460 if (!IsEmpty()) {
461 Scalar sx = 1.0 / GetWidth();
462 Scalar sy = 1.0 / GetHeight();
463 Scalar tx = left_ * -sx;
464 Scalar ty = top_ * -sy;
465
466 // Exclude NaN and infinities and either scale underflowing to zero
467 if (sx != 0.0 && sy != 0.0 && 0.0 * sx * sy * tx * ty == 0.0) {
468 // clang-format off
469 return Matrix( sx, 0.0f, 0.0f, 0.0f,
470 0.0f, sy, 0.0f, 0.0f,
471 0.0f, 0.0f, 1.0f, 0.0f,
472 tx, ty, 0.0f, 1.0f);
473 // clang-format on
474 }
475 }
476
477 // Map all coordinates to the origin.
478 return Matrix::MakeScale({0.0f, 0.0f, 1.0f});
479 }
float Scalar
Definition scalar.h:18
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:314
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition rect.h:308

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

287 {
288 return {left_, top_};
289 }

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

382 {
383 if (IsEmpty()) {
384 return {};
385 }
386 return {
387 TPoint{left_, top_},
388 TPoint{right_, top_},
389 TPoint{left_, bottom_},
390 TPoint{right_, bottom_},
391 };
392 }

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

366 {
367 if (!IsEmpty()) {
368 return *this;
369 }
370 return {
371 std::min(left_, right_),
372 std::min(top_, bottom_),
373 std::max(left_, right_),
374 std::max(top_, bottom_),
375 };
376 }

◆ GetRight()

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

Definition at line 322 of file rect.h.

322{ return right_; }

◆ GetRightBottom()

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

Definition at line 338 of file rect.h.

338 {
339 return {right_, bottom_};
340 }

◆ GetRightTop()

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

Definition at line 330 of file rect.h.

330 {
331 return {right_, top_};
332 }

◆ GetSize()

template<class T >
constexpr TSize< Type > impeller::TRect< T >::GetSize ( ) const
inlineconstexpr

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

294 {
295 return {GetWidth(), GetHeight()};
296 }

◆ GetTop()

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

Definition at line 320 of file rect.h.

320{ return top_; }

◆ GetTransformedPoints()

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

Definition at line 394 of file rect.h.

395 {
396 auto points = GetPoints();
397 for (size_t i = 0; i < points.size(); i++) {
398 points[i] = transform * points[i];
399 }
400 return points;
401 }
static const int points[]
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47
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:382

◆ GetWidth()

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

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

Definition at line 308 of file rect.h.

308 {
309 return saturated::Sub(right_, left_);
310 }

◆ GetX()

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

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

Definition at line 300 of file rect.h.

300{ return left_; }

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

361 {
362 return {left_, top_, GetWidth(), GetHeight()};
363 }

◆ GetY()

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

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

Definition at line 304 of file rect.h.

304{ return top_; }

◆ Intersection() [1/4]

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

Definition at line 688 of file rect.h.

690 {
691 return a.has_value() ? Intersection(a.value(), b) : b;
692 }
static bool b
struct MyStruct a[10]
constexpr std::optional< TRect > Intersection(const TRect &o) const
Definition rect.h:496

◆ Intersection() [2/4]

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

Definition at line 682 of file rect.h.

684 {
685 return a.has_value() ? a->Intersection(b) : b;
686 }

◆ Intersection() [3/4]

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

Definition at line 676 of file rect.h.

678 {
679 return b.has_value() ? a.Intersection(b.value()) : a;
680 }

◆ Intersection() [4/4]

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

Definition at line 496 of file rect.h.

497 {
498 if (IntersectsWithRect(o)) {
499 return TRect{
500 std::max(left_, o.left_),
501 std::max(top_, o.top_),
502 std::min(right_, o.right_),
503 std::min(bottom_, o.bottom_),
504 };
505 } else {
506 return std::nullopt;
507 }
508 }
constexpr bool IntersectsWithRect(const TRect &o) const
Definition rect.h:510

◆ IntersectsWithRect()

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

Definition at line 510 of file rect.h.

510 {
511 return !IsEmpty() && //
512 !o.IsEmpty() && //
513 left_ < o.right_ && //
514 top_ < o.bottom_ && //
515 right_ > o.left_ && //
516 bottom_ > o.top_;
517 }

◆ IsEmpty()

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

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

Definition at line 264 of file rect.h.

264 {
265 // Computing the non-empty condition and negating the result causes any
266 // NaN value to return true - i.e. is considered empty.
267 return !(left_ < right_ && top_ < bottom_);
268 }

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

255 {
256 return std::isfinite(left_) && //
257 std::isfinite(top_) && //
258 std::isfinite(right_) && //
259 std::isfinite(bottom_);
260 }

◆ IsMaximum()

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

Definition at line 281 of file rect.h.

281 {
282 return *this == MakeMaximum();
283 }
static constexpr TRect MakeMaximum()
Definition rect.h:174

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

271 {
272 // empty rectangles can technically be "square", but would be
273 // misleading to most callers. Using |IsEmpty| also prevents
274 // "non-empty and non-overflowing" computations from happening
275 // to be equal to "empty and overflowing" results.
276 // (Consider LTRB(10, 15, MAX-2, MIN+2) which is empty, but both
277 // w/h subtractions equal "5").
278 return !IsEmpty() && (right_ - left_) == (bottom_ - top_);
279 }

◆ MakeLTRB()

template<class T >
static constexpr TRect impeller::TRect< T >::MakeLTRB ( Type  left,
Type  top,
Type  right,
Type  bottom 
)
inlinestaticconstexpr

Definition at line 129 of file rect.h.

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

◆ MakeMaximum()

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

Definition at line 174 of file rect.h.

174 {
175 return TRect::MakeLTRB(std::numeric_limits<Type>::lowest(),
176 std::numeric_limits<Type>::lowest(),
177 std::numeric_limits<Type>::max(),
178 std::numeric_limits<Type>::max());
179 }

◆ MakeOriginSize()

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

Definition at line 140 of file rect.h.

141 {
142 return MakeXYWH(origin.x, origin.y, size.width, size.height);
143 }
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition rect.h:136

◆ MakePointBounds() [1/2]

template<class T >
template<typename PointIter >
static constexpr std::optional< TRect > impeller::TRect< T >::MakePointBounds ( const PointIter  first,
const PointIter  last 
)
inlinestaticconstexpr

Definition at line 156 of file rect.h.

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

◆ MakePointBounds() [2/2]

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

Definition at line 151 of file rect.h.

151 {
152 return MakePointBounds(value.begin(), value.end());
153 }
uint8_t value
static constexpr std::optional< TRect > MakePointBounds(const U &value)
Definition rect.h:151

◆ MakeSize()

template<class T >
template<class U >
static constexpr TRect impeller::TRect< T >::MakeSize ( const TSize< U > &  size)
inlinestaticconstexpr

Definition at line 146 of file rect.h.

146 {
147 return TRect(0.0, 0.0, size.width, size.height);
148 }

◆ MakeXYWH()

template<class T >
static constexpr 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 }
double y
double x
int32_t height
int32_t width

◆ operator==()

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

Definition at line 181 of file rect.h.

181 {
182 return left_ == r.left_ && //
183 top_ == r.top_ && //
184 right_ == r.right_ && //
185 bottom_ == r.bottom_;
186 }

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

633 {
634 if (IsEmpty()) {
635 return {};
636 }
637 return source.Shift(-left_, -top_)
638 .Scale(1.0 / static_cast<Scalar>(GetWidth()),
639 1.0 / static_cast<Scalar>(GetHeight()));
640 }
SkBitmap source
Definition examples.cpp:28

◆ Round()

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

Definition at line 651 of file rect.h.

651 {
652 return TRect::MakeLTRB(saturated::Cast<U, Type>(round(r.GetLeft())),
653 saturated::Cast<U, Type>(round(r.GetTop())),
654 saturated::Cast<U, Type>(round(r.GetRight())),
655 saturated::Cast<U, Type>(round(r.GetBottom())));
656 }
static void round(SkPoint *p)

◆ RoundOut()

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

Definition at line 643 of file rect.h.

643 {
644 return TRect::MakeLTRB(saturated::Cast<U, Type>(floor(r.GetLeft())),
645 saturated::Cast<U, Type>(floor(r.GetTop())),
646 saturated::Cast<U, Type>(ceil(r.GetRight())),
647 saturated::Cast<U, Type>(ceil(r.GetBottom())));
648 }
SIN Vec< N, float > floor(const Vec< N, float > &x)
Definition SkVx.h:703
SIN Vec< N, float > ceil(const Vec< N, float > &x)
Definition SkVx.h:702

◆ Scale() [1/4]

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

Definition at line 202 of file rect.h.

202 {
203 return Scale(scale.x, scale.y);
204 }
const Scalar scale

◆ Scale() [2/4]

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

Definition at line 206 of file rect.h.

206 {
207 return Scale(scale.width, scale.height);
208 }

◆ Scale() [3/4]

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

Definition at line 188 of file rect.h.

188 {
189 return TRect(left_ * scale, //
190 top_ * scale, //
191 right_ * scale, //
192 bottom_ * scale);
193 }

◆ Scale() [4/4]

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

Definition at line 195 of file rect.h.

195 {
196 return TRect(left_ * scale_x, //
197 top_ * scale_y, //
198 right_ * scale_x, //
199 bottom_ * scale_y);
200 }

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

566 {
567 return {
568 saturated::Add(left_, dx), //
569 saturated::Add(top_, dy), //
570 saturated::Add(right_, dx), //
571 saturated::Add(bottom_, dy), //
572 };
573 }

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

576 {
577 return Shift(offset.x, offset.y);
578 }
Point offset
constexpr TRect< T > Shift(T dx, T dy) const
Returns a new rectangle translated by the given offset.
Definition rect.h:566

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

407 {
408 if (!transform.HasPerspective2D()) {
410 }
411
412 if (IsEmpty()) {
413 return {};
414 }
415
416 auto ul = transform.TransformHomogenous({left_, top_});
417 auto ur = transform.TransformHomogenous({right_, top_});
418 auto ll = transform.TransformHomogenous({left_, bottom_});
419 auto lr = transform.TransformHomogenous({right_, bottom_});
420
421 // It can probably be proven that we only ever have 5 points at most
422 // which happens when only 1 corner is clipped and we get 2 points
423 // in return for it as we interpolate against its neighbors.
424 Point points[8];
425 int index = 0;
426
427 // Process (clip and interpolate) each point against its 2 neighbors:
428 // left, pt, right
429 index = ClipAndInsert(points, index, ll, ul, ur);
430 index = ClipAndInsert(points, index, ul, ur, lr);
431 index = ClipAndInsert(points, index, ur, lr, ll);
432 index = ClipAndInsert(points, index, lr, ll, ul);
433
435 return bounds.value_or(TRect{});
436 }
Optional< SkRect > bounds
Definition SkRecords.h:189
TPoint< Scalar > Point
Definition point.h:316
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition rect.h:440

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

440 {
441 if (IsEmpty()) {
442 return {};
443 }
445 auto bounds = TRect::MakePointBounds(points.begin(), points.end());
446 if (bounds.has_value()) {
447 return bounds.value();
448 }
450 }
#define FML_UNREACHABLE()
Definition logging.h:109
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
Definition rect.h:394

◆ Union() [1/4]

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

Definition at line 670 of file rect.h.

672 {
673 return a.has_value() ? Union(a.value(), b) : b;
674 }
constexpr TRect Union(const TRect &o) const
Definition rect.h:481

◆ Union() [2/4]

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

Definition at line 664 of file rect.h.

666 {
667 return a.has_value() ? a->Union(b) : b;
668 }

◆ Union() [3/4]

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

Definition at line 658 of file rect.h.

660 {
661 return b.has_value() ? a.Union(b.value()) : a;
662 }

◆ Union() [4/4]

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

Definition at line 481 of file rect.h.

481 {
482 if (IsEmpty()) {
483 return o;
484 }
485 if (o.IsEmpty()) {
486 return *this;
487 }
488 return {
489 std::min(left_, o.left_),
490 std::min(top_, o.top_),
491 std::max(right_, o.right_),
492 std::max(bottom_, o.bottom_),
493 };
494 }

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