Flutter Impeller
impeller::RoundRect Struct Reference

#include <round_rect.h>

Public Member Functions

 RoundRect ()=default
 
constexpr const Rect & GetBounds () const
 
constexpr const RoundingRadii & GetRadii () 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...
 
RoundRect Shift (Scalar dx, Scalar dy) const
 Returns a new round rectangle translated by the given offset. More...
 
RoundRect Expand (Scalar left, Scalar top, Scalar right, Scalar bottom) const
 Returns a round rectangle with expanded edges. Negative expansion results in shrinking. More...
 
RoundRect Expand (Scalar horizontal, Scalar vertical) const
 Returns a round rectangle with expanded edges. Negative expansion results in shrinking. More...
 
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
 

Static Public Member Functions

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

Friends

class RoundRectPathSource
 
class DiffRoundRectPathSource
 

Detailed Description

Definition at line 16 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:255
constexpr TPoint< T > GetLeftBottom() const
Definition: rect.h:401
constexpr TPoint< T > GetRightTop() const
Definition: rect.h:397
constexpr TPoint< T > GetRightBottom() const
Definition: rect.h:405
constexpr TPoint< T > GetLeftTop() const
Definition: rect.h:393

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]

RoundRect impeller::RoundRect::Expand ( Scalar  amount) const
inline

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

Definition at line 120 of file round_rect.h.

120  {
121  // Use the factory rather than the internal constructor as the changing
122  // size of the rectangle requires that we re-validate the radii to the
123  // newly sized rectangle.
124  return MakeRectRadii(bounds_.Expand(amount), radii_);
125  }
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:652

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

◆ Expand() [2/3]

RoundRect impeller::RoundRect::Expand ( Scalar  horizontal,
Scalar  vertical 
) const
inline

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

Definition at line 110 of file round_rect.h.

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

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

◆ Expand() [3/3]

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

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

Definition at line 98 of file round_rect.h.

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

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 65 of file round_rect.h.

65 { return bounds_.IsEmpty(); }
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().

Referenced by impeller::Canvas::DrawRoundRect(), and impeller::testing::TEST().

◆ IsFinite()

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

Definition at line 57 of file round_rect.h.

57  {
58  return bounds_.IsFinite() && //
59  radii_.top_left.IsFinite() && //
60  radii_.top_right.IsFinite() && //
61  radii_.bottom_left.IsFinite() && //
62  radii_.bottom_right.IsFinite();
63  }
IsFinite() const
Returns true if all of the fields of this floating point rectangle are finite.
Definition: rect.h:322
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 71 of file round_rect.h.

71  {
72  return !bounds_.IsEmpty() && radii_.AreAllCornersSame() &&
74  bounds_.GetWidth() * 0.5f) &&
76  bounds_.GetHeight() * 0.5f);
77  }
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:36
constexpr bool AreAllCornersSame(Scalar tolerance=kEhCloseEnough) const
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
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 67 of file round_rect.h.

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

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

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

◆ MakeNinePatch()

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

Definition at line 42 of file round_rect.h.

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

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

◆ MakeOval()

static RoundRect impeller::RoundRect::MakeOval ( const Rect &  rect)
inlinestatic

Definition at line 23 of file round_rect.h.

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

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

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

◆ MakeRect()

static RoundRect impeller::RoundRect::MakeRect ( const Rect &  rect)
inlinestatic

Definition at line 19 of file round_rect.h.

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

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:857
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition: rect.h:432

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

static RoundRect impeller::RoundRect::MakeRectRadius ( const Rect &  rect,
Scalar  radius 
)
inlinestatic

Definition at line 27 of file round_rect.h.

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

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

Referenced by impeller::testing::TEST(), and impeller::testing::TEST_P().

◆ MakeRectXY() [1/2]

static RoundRect impeller::RoundRect::MakeRectXY ( const Rect &  rect,
Scalar  x_radius,
Scalar  y_radius 
)
inlinestatic

Definition at line 31 of file round_rect.h.

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

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

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

◆ MakeRectXY() [2/2]

static RoundRect impeller::RoundRect::MakeRectXY ( const Rect &  rect,
Size  corner_radii 
)
inlinestatic

Definition at line 38 of file round_rect.h.

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

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

◆ operator==()

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

Definition at line 127 of file round_rect.h.

127  {
128  return bounds_ == rr.bounds_ && radii_ == rr.radii_;
129  }

◆ Shift()

RoundRect impeller::RoundRect::Shift ( Scalar  dx,
Scalar  dy 
) const
inline

Returns a new round rectangle translated by the given offset.

Definition at line 89 of file round_rect.h.

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

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

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

Friends And Related Function Documentation

◆ DiffRoundRectPathSource

friend class DiffRoundRectPathSource
friend

Definition at line 142 of file round_rect.h.

◆ RoundRectPathSource

friend class RoundRectPathSource
friend

Definition at line 141 of file round_rect.h.


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