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

#include <rect.h>

Public Types

using Type = T
 

Public Member Functions

constexpr TRect ()
 
template<class U >
constexpr TRect (const TRect< U > &other)
 
constexpr TRect operator+ (const TRect &r) const
 
constexpr TRect operator- (const TRect &r) const
 
constexpr TRect operator* (Type scale) const
 
constexpr TRect operator* (const TRect &r) const
 
constexpr bool operator== (const TRect &r) const
 
constexpr TRect Scale (Type scale) const
 
constexpr TRect Scale (Type scale_x, Type scale_y) const
 
constexpr TRect Scale (TPoint< T > scale) const
 
constexpr TRect Scale (TSize< T > scale) const
 
constexpr bool Contains (const TPoint< Type > &p) const
 
constexpr bool Contains (const TRect &o) const
 
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< TypeGetOrigin () const
 Returns the upper left corner of the rectangle as specified when it was constructed. More...
 
constexpr TSize< TypeGetSize () const
 Returns the size of the rectangle as specified when it was constructed and which may be negative in either width or height. 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. 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 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< T > > Intersection (const TRect &o) const
 
constexpr bool IntersectsWithRect (const TRect &o) const
 
constexpr std::optional< TRect< T > > Cutout (const TRect &o) const
 Returns the new boundary rectangle that would result from the rectangle being cutout by a second rectangle. More...
 
constexpr TRect< T > Shift (TPoint< T > offset) const
 Returns a new rectangle translated by the given offset. More...
 
constexpr TRect< T > Expand (T left, T top, T right, T bottom) const
 Returns a rectangle with expanded edges. Negative expansion results in shrinking. More...
 
constexpr TRect< T > Expand (T amount) const
 Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking. More...
 
constexpr TRect< T > Expand (T horizontal_amount, T vertical_amount) const
 Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking. More...
 
constexpr TRect< T > Expand (TPoint< T > amount) const
 Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking. More...
 
constexpr TRect< T > Expand (TSize< T > amount) const
 Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking. More...
 
constexpr TRect< T > Project (TRect< T > source) const
 Returns a new rectangle that represents the projection of the source rectangle onto this rectangle. In other words, the source rectangle is redefined in terms of the corrdinate space of this rectangle. More...
 

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 MakeOriginSize (const TPoint< Type > &origin, const TSize< Type > &size)
 
template<class U >
constexpr static TRect MakeSize (const TSize< U > &size)
 
template<typename U >
constexpr static std::optional< TRectMakePointBounds (const U &value)
 
template<typename PointIter >
constexpr static std::optional< TRectMakePointBounds (const PointIter first, const PointIter last)
 
constexpr static TRect MakeMaximum ()
 
constexpr static TRect RoundOut (const TRect &r)
 
constexpr static std::optional< TRectUnion (const TRect &a, const std::optional< TRect > b)
 
constexpr static std::optional< TRectUnion (const std::optional< TRect > a, const TRect &b)
 
constexpr static std::optional< TRectUnion (const std::optional< TRect > a, const std::optional< TRect > b)
 
constexpr static std::optional< TRectIntersection (const TRect &a, const std::optional< TRect > b)
 
constexpr static std::optional< TRectIntersection (const std::optional< TRect > a, const TRect &b)
 
constexpr static std::optional< TRectIntersection (const std::optional< TRect > a, const std::optional< TRect > b)
 

Detailed Description

template<class T>
struct impeller::TRect< T >

Definition at line 22 of file rect.h.

Member Typedef Documentation

◆ Type

template<class T >
using impeller::TRect< T >::Type = T

Definition at line 23 of file rect.h.

Constructor & Destructor Documentation

◆ TRect() [1/2]

◆ TRect() [2/2]

template<class T >
template<class U >
constexpr impeller::TRect< T >::TRect ( const TRect< U > &  other)
inlineexplicitconstexpr

Definition at line 80 of file rect.h.

81  : origin(static_cast<T>(other.GetX()), static_cast<T>(other.GetY())),
82  size(static_cast<T>(other.GetWidth()),
83  static_cast<T>(other.GetHeight())) {}

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

222 { return size.Area(); }

◆ Contains() [1/2]

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

Definition at line 127 of file rect.h.

127  {
128  return p.x >= GetLeft() && p.x < GetRight() && p.y >= GetTop() &&
129  p.y < GetBottom();
130  }

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

◆ Contains() [2/2]

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

Definition at line 132 of file rect.h.

132  {
133  return o.GetLeft() >= GetLeft() && o.GetTop() >= GetTop() &&
134  o.GetRight() <= GetRight() && o.GetBottom() <= GetBottom();
135  }

◆ 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 the rectangle being cutout by a second rectangle.

Definition at line 334 of file rect.h.

334  {
335  const auto& [a_left, a_top, a_right, a_bottom] = GetLTRB(); // Source rect.
336  const auto& [b_left, b_top, b_right, b_bottom] = o.GetLTRB(); // Cutout.
337  if (b_left <= a_left && b_right >= a_right) {
338  if (b_top <= a_top && b_bottom >= a_bottom) {
339  // Full cutout.
340  return std::nullopt;
341  }
342  if (b_top <= a_top && b_bottom > a_top) {
343  // Cuts off the top.
344  return TRect::MakeLTRB(a_left, b_bottom, a_right, a_bottom);
345  }
346  if (b_bottom >= a_bottom && b_top < a_bottom) {
347  // Cuts out the bottom.
348  return TRect::MakeLTRB(a_left, a_top, a_right, b_top);
349  }
350  }
351  if (b_top <= a_top && b_bottom >= a_bottom) {
352  if (b_left <= a_left && b_right > a_left) {
353  // Cuts out the left.
354  return TRect::MakeLTRB(b_right, a_top, a_right, a_bottom);
355  }
356  if (b_right >= a_right && b_left < a_right) {
357  // Cuts out the right.
358  return TRect::MakeLTRB(a_left, a_top, b_left, a_bottom);
359  }
360  }
361 
362  return *this;
363  }

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

◆ Expand() [1/5]

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

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

Definition at line 385 of file rect.h.

385  {
386  return TRect(origin.x - amount, //
387  origin.y - amount, //
388  size.width + amount * 2, //
389  size.height + amount * 2);
390  }

◆ Expand() [2/5]

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

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

Definition at line 394 of file rect.h.

395  {
396  return TRect(origin.x - horizontal_amount, //
397  origin.y - vertical_amount, //
398  size.width + horizontal_amount * 2, //
399  size.height + vertical_amount * 2);
400  }

◆ Expand() [3/5]

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

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

404  {
405  return TRect(origin.x - amount.x, //
406  origin.y - amount.y, //
407  size.width + amount.x * 2, //
408  size.height + amount.y * 2);
409  }

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

413  {
414  return TRect(origin.x - amount.width, //
415  origin.y - amount.height, //
416  size.width + amount.width * 2, //
417  size.height + amount.height * 2);
418  }

◆ GetBottom()

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

◆ GetCenter()

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

Get the center point as a |Point|.

Definition at line 225 of file rect.h.

225  {
226  return Point(origin.x + size.width * 0.5f, origin.y + size.height * 0.5f);
227  }

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

◆ GetHeight()

◆ GetLeft()

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

◆ GetLeftBottom()

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

Definition at line 213 of file rect.h.

213  {
214  return {GetLeft(), GetBottom()};
215  }

◆ GetLeftTop()

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

Definition at line 205 of file rect.h.

205  {
206  return {GetLeft(), GetTop()};
207  }

Referenced by impeller::Tessellator::FilledRoundRect().

◆ GetLTRB()

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

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

280  {
281  if (!IsEmpty()) {
282  Scalar sx = 1.0 / size.width;
283  Scalar sy = 1.0 / size.height;
284  Scalar tx = origin.x * -sx;
285  Scalar ty = origin.y * -sy;
286 
287  // Exclude NaN and infinities and either scale underflowing to zero
288  if (sx != 0.0 && sy != 0.0 && 0.0 * sx * sy * tx * ty == 0.0) {
289  // clang-format off
290  return Matrix( sx, 0.0f, 0.0f, 0.0f,
291  0.0f, sy, 0.0f, 0.0f,
292  0.0f, 0.0f, 1.0f, 0.0f,
293  tx, ty, 0.0f, 1.0f);
294  // clang-format on
295  }
296  }
297 
298  // Map all coordinates to the origin.
299  return Matrix::MakeScale({0.0f, 0.0f, 1.0f});
300  }

Referenced by impeller::ComputeUVGeometryForRect(), and impeller::VerticesGeometry::GetPositionUVBuffer().

◆ GetOrigin()

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

Returns the upper left corner of the rectangle as specified when it was constructed.

Note that unlike the |GetLeft|, |GetTop|, and |GetLeftTop| methods which will return values as if the rectangle had been "unswapped" by calling |GetPositive| on it, this method returns the raw origin values.

Definition at line 154 of file rect.h.

154 { return origin; }

Referenced by impeller::PathBuilder::AddArc(), impeller::PathBuilder::AddOval(), impeller::PathBuilder::AddRect(), impeller::PathBuilder::AddRoundedRect(), impeller::AdvancedBlend(), impeller::DirectionalMorphologyFilterContents::GetFilterCoverage(), std::operator<<(), impeller::PipelineBlend(), 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. The order is: Top left, top right, bottom left, bottom right.

Definition at line 247 of file rect.h.

247  {
248  auto [left, top, right, bottom] = GetLTRB();
249  return {TPoint(left, top), TPoint(right, top), TPoint(left, bottom),
250  TPoint(right, bottom)};
251  }

Referenced by impeller::ComputeUVGeometryForRect(), impeller::TRect< Scalar >::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 240 of file rect.h.

240  {
241  auto ltrb = GetLTRB();
242  return MakeLTRB(ltrb[0], ltrb[1], ltrb[2], ltrb[3]);
243  }

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

◆ GetRight()

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

◆ GetRightBottom()

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

Definition at line 217 of file rect.h.

217  {
218  return {GetRight(), GetBottom()};
219  }

Referenced by impeller::Tessellator::FilledRoundRect().

◆ GetRightTop()

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

Definition at line 209 of file rect.h.

209  {
210  return {GetRight(), GetTop()};
211  }

◆ GetSize()

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

◆ GetTop()

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

◆ GetTransformedPoints()

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

Definition at line 253 of file rect.h.

254  {
255  auto points = GetPoints();
256  for (size_t i = 0; i < points.size(); i++) {
257  points[i] = transform * points[i];
258  }
259  return points;
260  }

Referenced by impeller::GaussianBlurFilterContents::CalculateUVs(), impeller::Snapshot::GetCoverageUVs(), impeller::AtlasContents::Render(), impeller::AtlasTextureContents::Render(), impeller::AtlasColorContents::Render(), impeller::testing::TEST(), and impeller::TRect< Scalar >::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 235 of file rect.h.

235  {
236  return {origin.x, origin.y, size.width, size.height};
237  }

Referenced by impeller::TextContents::Render(), and 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 465 of file rect.h.

467  {
468  return a.has_value() ? Intersection(a.value(), b) : b;
469  }

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

461  {
462  return Intersection(b, a);
463  }

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

455  {
456  return b.has_value() ? a.Intersection(b.value()) : a;
457  }

◆ Intersection() [4/4]

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

Definition at line 312 of file rect.h.

313  {
314  auto this_ltrb = GetLTRB();
315  auto other_ltrb = o.GetLTRB();
316  auto intersection =
317  TRect::MakeLTRB(std::max(this_ltrb[0], other_ltrb[0]), //
318  std::max(this_ltrb[1], other_ltrb[1]), //
319  std::min(this_ltrb[2], other_ltrb[2]), //
320  std::min(this_ltrb[3], other_ltrb[3]) //
321  );
322  if (intersection.size.IsEmpty()) {
323  return std::nullopt;
324  }
325  return intersection;
326  }

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

◆ IntersectsWithRect()

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

Definition at line 328 of file rect.h.

328  {
329  return Intersection(o).has_value();
330  }

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

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

138 { return size.IsEmpty(); }

Referenced by impeller::Canvas::DrawImageRect(), impeller::NinePatchConverter::DrawNinePatch(), impeller::TRect< Scalar >::GetNormalizingTransform(), and impeller::TextureContents::Render().

◆ IsMaximum()

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

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

141 { return size.IsSquare(); }

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

◆ MakeLTRB()

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

◆ MakeMaximum()

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

Definition at line 72 of file rect.h.

72  {
73  return TRect::MakeLTRB(-std::numeric_limits<Type>::infinity(),
74  -std::numeric_limits<Type>::infinity(),
75  std::numeric_limits<Type>::infinity(),
76  std::numeric_limits<Type>::infinity());
77  }

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

◆ MakeOriginSize()

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

Definition at line 38 of file rect.h.

39  {
40  return TRect(origin, size);
41  }

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

55  {
56  if (first == last) {
57  return std::nullopt;
58  }
59  auto left = first->x;
60  auto top = first->y;
61  auto right = first->x;
62  auto bottom = first->y;
63  for (auto it = first + 1; it < last; ++it) {
64  left = std::min(left, it->x);
65  top = std::min(top, it->y);
66  right = std::max(right, it->x);
67  bottom = std::max(bottom, it->y);
68  }
69  return TRect::MakeLTRB(left, top, right, bottom);
70  }

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

49  {
50  return MakePointBounds(value.begin(), value.end());
51  }

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

◆ MakeSize()

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

Definition at line 44 of file rect.h.

44  {
45  return TRect(0.0, 0.0, size.width, size.height);
46  }

◆ MakeXYWH()

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

Definition at line 34 of file rect.h.

34  {
35  return TRect(x, y, width, height);
36  }

◆ operator*() [1/2]

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

Definition at line 99 of file rect.h.

99  {
100  return TRect({origin.x * r.origin.x, origin.y * r.origin.y},
101  {size.width * r.size.width, size.height * r.size.height});
102  }

◆ operator*() [2/2]

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

Definition at line 95 of file rect.h.

95  {
96  return Scale(scale);
97  }

◆ operator+()

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

Definition at line 85 of file rect.h.

85  {
86  return TRect({origin.x + r.origin.x, origin.y + r.origin.y},
87  {size.width + r.size.width, size.height + r.size.height});
88  }

◆ operator-()

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

Definition at line 90 of file rect.h.

90  {
91  return TRect({origin.x - r.origin.x, origin.y - r.origin.y},
92  {size.width - r.size.width, size.height - r.size.height});
93  }

◆ operator==()

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

Definition at line 104 of file rect.h.

104  {
105  return origin == r.origin && size == r.size;
106  }

◆ 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 corrdinate space of this rectangle.

Definition at line 424 of file rect.h.

424  {
425  return source.Shift(-origin).Scale(
426  TSize<T>(1.0 / static_cast<Scalar>(size.width),
427  1.0 / static_cast<Scalar>(size.height)));
428  }

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

◆ RoundOut()

template<class T >
constexpr static TRect impeller::TRect< T >::RoundOut ( const TRect< T > &  r)
inlinestaticconstexpr

Definition at line 430 of file rect.h.

430  {
431  return TRect::MakeLTRB(floor(r.GetLeft()), floor(r.GetTop()),
432  ceil(r.GetRight()), ceil(r.GetBottom()));
433  }

◆ Scale() [1/4]

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

Definition at line 118 of file rect.h.

118  {
119  return TRect({origin.x * scale.x, origin.y * scale.y},
120  {size.width * scale.x, size.height * scale.y});
121  }

◆ Scale() [2/4]

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

Definition at line 123 of file rect.h.

123  {
124  return Scale(TPoint<T>(scale));
125  }

◆ Scale() [3/4]

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

Definition at line 108 of file rect.h.

108  {
109  return TRect({origin.x * scale, origin.y * scale},
110  {size.width * scale, size.height * scale});
111  }

Referenced by ImGui_ImplImpeller_RenderDrawData(), impeller::MakeTextFrameFromTextBlobSkia(), impeller::TRect< Scalar >::operator*(), impeller::TRect< Scalar >::Scale(), and impeller::testing::TEST().

◆ Scale() [4/4]

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

Definition at line 113 of file rect.h.

113  {
114  return TRect({origin.x * scale_x, origin.y * scale_y},
115  {size.width * scale_x, size.height * scale_y});
116  }

◆ Shift()

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

366  {
367  return TRect(origin.x + offset.x, origin.y + offset.y, size.width,
368  size.height);
369  }

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

◆ TransformBounds()

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

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

449  {
450  return a.has_value() ? Union(a.value(), b) : b;
451  }

◆ Union() [2/4]

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

Definition at line 441 of file rect.h.

443  {
444  return Union(b, a);
445  }

◆ Union() [3/4]

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

Definition at line 435 of file rect.h.

437  {
438  return b.has_value() ? a.Union(b.value()) : a;
439  }

◆ Union() [4/4]

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

Definition at line 302 of file rect.h.

302  {
303  auto this_ltrb = GetLTRB();
304  auto other_ltrb = o.GetLTRB();
305  return TRect::MakeLTRB(std::min(this_ltrb[0], other_ltrb[0]), //
306  std::min(this_ltrb[1], other_ltrb[1]), //
307  std::max(this_ltrb[2], other_ltrb[2]), //
308  std::max(this_ltrb[3], other_ltrb[3]) //
309  );
310  }

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


The documentation for this struct was generated from the following file:
impeller::TRect::GetLTRB
constexpr std::array< T, 4 > GetLTRB() const
Definition: rect.h:229
impeller::TPoint::y
Type y
Definition: point.h:26
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::TSize::IsSquare
constexpr bool IsSquare() const
Definition: size.h:107
impeller::TRect::IsMaximum
constexpr bool IsMaximum() const
Definition: rect.h:143
impeller::TRect::TRect
constexpr TRect()
Definition: rect.h:25
impeller::TRect::GetPoints
constexpr std::array< TPoint< T >, 4 > GetPoints() const
Get the points that represent the 4 corners of this rectangle. The order is: Top left,...
Definition: rect.h:247
impeller::TRect::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:49
impeller::TRect::IsEmpty
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: rect.h:138
impeller::Point
TPoint< Scalar > Point
Definition: point.h:308
impeller::TRect::Intersection
constexpr std::optional< TRect< T > > Intersection(const TRect &o) const
Definition: rect.h:312
impeller::TRect::GetLeft
constexpr auto GetLeft() const
Definition: rect.h:177
impeller::TRect::GetTransformedPoints
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
Definition: rect.h:253
impeller::TRect::Scale
constexpr TRect Scale(Type scale) const
Definition: rect.h:108
impeller::TSize::width
Type width
Definition: size.h:22
impeller::TPoint::x
Type x
Definition: point.h:25
impeller::TRect::GetRight
constexpr auto GetRight() const
Definition: rect.h:191
impeller::TSize::Area
constexpr Type Area() const
Definition: size.h:102
impeller::TRect::MakeMaximum
constexpr static TRect MakeMaximum()
Definition: rect.h:72
impeller::TRect::Union
constexpr TRect Union(const TRect &o) const
Definition: rect.h:302
impeller::TRect::GetBottom
constexpr auto GetBottom() const
Definition: rect.h:198
impeller::TSize::height
Type height
Definition: size.h:23
impeller::TRect::MakeLTRB
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:27
impeller::TSize::IsEmpty
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: size.h:105
impeller::Matrix::MakeScale
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:104
impeller::TRect::GetTop
constexpr auto GetTop() const
Definition: rect.h:184