Flutter Impeller
impeller::RoundRect Struct Reference

#include <round_rect.h>

Public Member Functions

 RoundRect ()=default
 
constexpr const RectGetBounds () const
 
constexpr const RoundingRadiiGetRadii () const
 
constexpr bool IsFinite () const
 
constexpr bool IsEmpty () const
 
constexpr bool IsRect () const
 
constexpr bool IsOval () const
 
bool Contains (const Point &p) const
 Returns true iff the provided point |p| is inside the half-open interior of this rectangle. More...
 
constexpr RoundRect Shift (Scalar dx, Scalar dy) const
 Returns a new round rectangle translated by the given offset. More...
 
constexpr RoundRect Expand (Scalar left, Scalar top, Scalar right, Scalar bottom) const
 Returns a round rectangle with expanded edges. Negative expansion results in shrinking. More...
 
constexpr RoundRect Expand (Scalar horizontal, Scalar vertical) const
 Returns a round rectangle with expanded edges. Negative expansion results in shrinking. More...
 
constexpr RoundRect Expand (Scalar amount) const
 Returns a round rectangle with expanded edges. Negative expansion results in shrinking. More...
 
constexpr bool operator== (const RoundRect &rr) const
 
constexpr bool operator!= (const RoundRect &r) const
 

Static Public Member Functions

constexpr static RoundRect MakeRect (const Rect &rect)
 
constexpr static RoundRect MakeOval (const Rect &rect)
 
constexpr static RoundRect MakeRectRadius (const Rect &rect, Scalar radius)
 
constexpr static RoundRect MakeRectXY (const Rect &rect, Scalar x_radius, Scalar y_radius)
 
constexpr static RoundRect MakeRectXY (const Rect &rect, Size corner_radii)
 
constexpr static RoundRect MakeNinePatch (const Rect &rect, Scalar left, Scalar top, Scalar right, Scalar bottom)
 
static RoundRect MakeRectRadii (const Rect &rect, const RoundingRadii &radii)
 

Detailed Description

Definition at line 15 of file round_rect.h.

Constructor & Destructor Documentation

◆ RoundRect()

impeller::RoundRect::RoundRect ( )
default

Referenced by MakeRectRadii().

Member Function Documentation

◆ Contains()

bool impeller::RoundRect::Contains ( const Point p) const

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 73 of file round_rect.cc.

73  {
74  if (!bounds_.Contains(p)) {
75  return false;
76  }
78  radii_.top_left) ||
80  radii_.top_right) ||
82  radii_.bottom_left) ||
84  radii_.bottom_right)) {
85  return false;
86  }
87  return true;
88 }
static bool CornerContains(const Point &p, const Point &corner, const Point &direction, const Size &radii)
Definition: round_rect.cc:30
static constexpr Point kUpperLeftDirection(-1.0f, -1.0f)
static constexpr Point kLowerRightDirection(1.0f, 1.0f)
static constexpr Point kUpperRightDirection(1.0f, -1.0f)
static constexpr Point kLowerLeftDirection(-1.0f, 1.0f)
constexpr bool Contains(const TPoint< Type > &p) const
Returns true iff the provided point |p| is inside the half-open interior of this rectangle.
Definition: rect.h:235
constexpr TPoint< T > GetLeftBottom() const
Definition: rect.h:371
constexpr TPoint< T > GetRightTop() const
Definition: rect.h:367
constexpr TPoint< T > GetRightBottom() const
Definition: rect.h:375
constexpr TPoint< T > GetLeftTop() const
Definition: rect.h:363

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::TRect< T >::Contains(), impeller::CornerContains(), impeller::TRect< T >::GetLeftBottom(), impeller::TRect< T >::GetLeftTop(), impeller::TRect< T >::GetRightBottom(), impeller::TRect< T >::GetRightTop(), impeller::kLowerLeftDirection(), impeller::kLowerRightDirection(), impeller::kUpperLeftDirection(), impeller::kUpperRightDirection(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

◆ Expand() [1/3]

constexpr RoundRect impeller::RoundRect::Expand ( Scalar  amount) const
inlineconstexpr

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

Definition at line 118 of file round_rect.h.

118  {
119  // Use the factory rather than the internal constructor as the changing
120  // size of the rectangle requires that we re-validate the radii to the
121  // newly sized rectangle.
122  return MakeRectRadii(bounds_.Expand(amount), radii_);
123  }
static RoundRect MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition: round_rect.cc:9
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:622

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

◆ Expand() [2/3]

constexpr RoundRect impeller::RoundRect::Expand ( Scalar  horizontal,
Scalar  vertical 
) const
inlineconstexpr

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

Definition at line 108 of file round_rect.h.

109  {
110  // Use the factory rather than the internal constructor as the changing
111  // size of the rectangle requires that we re-validate the radii to the
112  // newly sized rectangle.
113  return MakeRectRadii(bounds_.Expand(horizontal, vertical), radii_);
114  }

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

◆ Expand() [3/3]

constexpr RoundRect impeller::RoundRect::Expand ( Scalar  left,
Scalar  top,
Scalar  right,
Scalar  bottom 
) const
inlineconstexpr

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

Definition at line 96 of file round_rect.h.

99  {
100  // Use the factory rather than the internal constructor as the changing
101  // size of the rectangle requires that we re-validate the radii to the
102  // newly sized rectangle.
103  return MakeRectRadii(bounds_.Expand(left, top, right, bottom), radii_);
104  }

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

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

◆ GetBounds()

constexpr const Rect& impeller::RoundRect::GetBounds ( ) const
inlineconstexpr

◆ GetRadii()

constexpr const RoundingRadii& impeller::RoundRect::GetRadii ( ) const
inlineconstexpr

◆ IsEmpty()

constexpr bool impeller::RoundRect::IsEmpty ( ) const
inlineconstexpr

Definition at line 63 of file round_rect.h.

63 { return bounds_.IsEmpty(); }
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: rect.h:301

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

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

◆ IsFinite()

constexpr bool impeller::RoundRect::IsFinite ( ) const
inlineconstexpr

Definition at line 55 of file round_rect.h.

55  {
56  return bounds_.IsFinite() && //
57  radii_.top_left.IsFinite() && //
58  radii_.top_right.IsFinite() && //
59  radii_.bottom_left.IsFinite() && //
60  radii_.bottom_right.IsFinite();
61  }
IsFinite() const
Returns true if all of the fields of this floating point rectangle are finite.
Definition: rect.h:292
IsFinite() const
Definition: size.h:126

References impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::TRect< T >::IsFinite(), impeller::TSize< T >::IsFinite(), impeller::RoundingRadii::top_left, and impeller::RoundingRadii::top_right.

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

◆ IsOval()

constexpr bool impeller::RoundRect::IsOval ( ) const
inlineconstexpr

Definition at line 69 of file round_rect.h.

69  {
70  return !bounds_.IsEmpty() && radii_.AreAllCornersSame() &&
72  bounds_.GetWidth() * 0.5f) &&
74  bounds_.GetHeight() * 0.5f);
75  }
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:35
constexpr bool AreAllCornersSame(Scalar tolerance=kEhCloseEnough) const
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:351
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:345
Type height
Definition: size.h:29
Type width
Definition: size.h:28

References impeller::RoundingRadii::AreAllCornersSame(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetWidth(), impeller::TSize< T >::height, impeller::TRect< T >::IsEmpty(), impeller::ScalarNearlyEqual(), impeller::RoundingRadii::top_left, and impeller::TSize< T >::width.

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

◆ IsRect()

constexpr bool impeller::RoundRect::IsRect ( ) const
inlineconstexpr

Definition at line 65 of file round_rect.h.

65  {
66  return !bounds_.IsEmpty() && radii_.AreAllCornersEmpty();
67  }
constexpr bool AreAllCornersEmpty() const

References impeller::RoundingRadii::AreAllCornersEmpty(), and impeller::TRect< T >::IsEmpty().

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

◆ MakeNinePatch()

constexpr static RoundRect impeller::RoundRect::MakeNinePatch ( const Rect rect,
Scalar  left,
Scalar  top,
Scalar  right,
Scalar  bottom 
)
inlinestaticconstexpr

Definition at line 41 of file round_rect.h.

45  {
46  return MakeRectRadii(
47  rect, RoundingRadii::MakeNinePatch(left, top, right, bottom));
48  }
constexpr static RoundingRadii MakeNinePatch(Scalar left, Scalar top, Scalar right, Scalar bottom)

References impeller::RoundingRadii::MakeNinePatch(), and MakeRectRadii().

◆ MakeOval()

constexpr static RoundRect impeller::RoundRect::MakeOval ( const Rect rect)
inlinestaticconstexpr

Definition at line 22 of file round_rect.h.

22  {
23  return MakeRectRadii(rect, RoundingRadii::MakeRadii(rect.GetSize() * 0.5f));
24  }
constexpr static RoundingRadii MakeRadii(Size radii)

References impeller::TRect< T >::GetSize(), impeller::RoundingRadii::MakeRadii(), and MakeRectRadii().

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

◆ MakeRect()

constexpr static RoundRect impeller::RoundRect::MakeRect ( const Rect rect)
inlinestaticconstexpr

Definition at line 18 of file round_rect.h.

18  {
19  return MakeRectRadii(rect, RoundingRadii());
20  }

References MakeRectRadii().

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

◆ MakeRectRadii()

RoundRect impeller::RoundRect::MakeRectRadii ( const Rect rect,
const RoundingRadii radii 
)
static

Definition at line 9 of file round_rect.cc.

10  {
11  if (!in_bounds.IsFinite()) {
12  return {};
13  }
14  Rect bounds = in_bounds.GetPositive();
15  // RoundingRadii::Scaled might return an empty radii if bounds or in_radii is
16  // empty, which is expected. Pass along the bounds even if the radii is empty
17  // as it would still have a valid location and/or 1-dimensional size which
18  // might appear when stroked
19  return RoundRect(bounds, in_radii.Scaled(bounds));
20 }
TRect< Scalar > Rect
Definition: rect.h:792
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition: rect.h:402

References impeller::TRect< T >::GetPositive(), impeller::TRect< T >::IsFinite(), RoundRect(), and impeller::RoundingRadii::Scaled().

Referenced by impeller::interop::DisplayListBuilder::ClipRoundedRect(), impeller::interop::DisplayListBuilder::DrawRoundedRect(), impeller::interop::DisplayListBuilder::DrawRoundedRectDifference(), Expand(), MakeNinePatch(), MakeOval(), MakeRect(), MakeRectRadius(), MakeRectXY(), Shift(), impeller::testing::TEST(), and impeller::RoundSuperellipse::ToApproximateRoundRect().

◆ MakeRectRadius()

constexpr static RoundRect impeller::RoundRect::MakeRectRadius ( const Rect rect,
Scalar  radius 
)
inlinestaticconstexpr

Definition at line 26 of file round_rect.h.

26  {
27  return MakeRectRadii(rect, RoundingRadii::MakeRadius(radius));
28  }
constexpr static RoundingRadii MakeRadius(Scalar radius)

References impeller::RoundingRadii::MakeRadius(), and MakeRectRadii().

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

◆ MakeRectXY() [1/2]

constexpr static RoundRect impeller::RoundRect::MakeRectXY ( const Rect rect,
Scalar  x_radius,
Scalar  y_radius 
)
inlinestaticconstexpr

Definition at line 30 of file round_rect.h.

32  {
33  return MakeRectRadii(rect,
34  RoundingRadii::MakeRadii(Size(x_radius, y_radius)));
35  }
TSize< Scalar > Size
Definition: size.h:159

References impeller::RoundingRadii::MakeRadii(), and MakeRectRadii().

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

◆ MakeRectXY() [2/2]

constexpr static RoundRect impeller::RoundRect::MakeRectXY ( const Rect rect,
Size  corner_radii 
)
inlinestaticconstexpr

Definition at line 37 of file round_rect.h.

37  {
38  return MakeRectRadii(rect, RoundingRadii::MakeRadii(corner_radii));
39  }

References impeller::RoundingRadii::MakeRadii(), and MakeRectRadii().

◆ operator!=()

constexpr bool impeller::RoundRect::operator!= ( const RoundRect r) const
inlineconstexpr

Definition at line 129 of file round_rect.h.

129  {
130  return !(*this == r);
131  }

◆ operator==()

constexpr bool impeller::RoundRect::operator== ( const RoundRect rr) const
inlineconstexpr

Definition at line 125 of file round_rect.h.

125  {
126  return bounds_ == rr.bounds_ && radii_ == rr.radii_;
127  }

◆ Shift()

constexpr RoundRect impeller::RoundRect::Shift ( Scalar  dx,
Scalar  dy 
) const
inlineconstexpr

Returns a new round rectangle translated by the given offset.

Definition at line 87 of file round_rect.h.

87  {
88  // Just in case, use the factory rather than the internal constructor
89  // as shifting the rectangle may increase/decrease its bit precision
90  // so we should re-validate the radii to the newly located rectangle.
91  return MakeRectRadii(bounds_.Shift(dx, dy), radii_);
92  }
constexpr TRect< T > Shift(T dx, T dy) const
Returns a new rectangle translated by the given offset.
Definition: rect.h:606

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

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


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