| Flutter Impeller |

Public Member Functions | Static Public Member Functions | Friends | List of all members
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
constexpr bool | operator!= (const RoundRect &r) 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 }
77 if (!CornerContains(p, bounds_.GetLeftTop(), kUpperLeftDirection,
78 radii_.top_left) ||
79 !CornerContains(p, bounds_.GetRightTop(), kUpperRightDirection,
80 radii_.top_right) ||
81 !CornerContains(p, bounds_.GetLeftBottom(), kLowerLeftDirection,
82 radii_.bottom_left) ||
83 !CornerContains(p, bounds_.GetRightBottom(), kLowerRightDirection,
84 radii_.bottom_right)) {
85 return false;
86 }
87 return true;
88 }
impeller::CornerContains
static bool CornerContains(const Point &p, const Point &corner, const Point &direction, const Size &radii)
Definition: round_rect.cc:30
impeller::kUpperLeftDirection
static constexpr Point kUpperLeftDirection(-1.0f, -1.0f)
impeller::kLowerRightDirection
static constexpr Point kLowerRightDirection(1.0f, 1.0f)
impeller::kUpperRightDirection
static constexpr Point kUpperRightDirection(1.0f, -1.0f)
impeller::kLowerLeftDirection
static constexpr Point kLowerLeftDirection(-1.0f, 1.0f)
impeller::RoundingRadii::top_right
Size top_right
Definition: rounding_radii.h:16
impeller::RoundingRadii::bottom_left
Size bottom_left
Definition: rounding_radii.h:17
impeller::RoundingRadii::bottom_right
Size bottom_right
Definition: rounding_radii.h:18
impeller::RoundingRadii::top_left
Size top_left
Definition: rounding_radii.h:15
impeller::TRect::Contains
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
impeller::TRect::GetLeftBottom
constexpr TPoint< T > GetLeftBottom() const
Definition: rect.h:371
impeller::TRect::GetRightTop
constexpr TPoint< T > GetRightTop() const
Definition: rect.h:367
impeller::TRect::GetRightBottom
constexpr TPoint< T > GetRightBottom() const
Definition: rect.h:375
impeller::TRect::GetLeftTop
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]

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 }
impeller::RoundRect::MakeRectRadii
static RoundRect MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition: round_rect.cc:9
impeller::TRect::Expand
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]

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
| inline constexpr

Definition at line 53 of file round_rect.h.

53 { return bounds_; }

Referenced by impeller::FillRoundRectGeometry::CoversArea(), impeller::Canvas::DrawRoundRect(), impeller::RoundRectPathSource::GetBounds(), impeller::DiffRoundRectPathSource::GetBounds(), std::operator<<(), and impeller::testing::TEST().

## ◆ GetRadii()

constexpr const RoundingRadii& impeller::RoundRect::GetRadii | ( |  | ) | const
| inline constexpr

Definition at line 55 of file round_rect.h.

55 { return radii_; }

Referenced by impeller::FillRoundRectGeometry::CoversArea(), impeller::Canvas::DrawRoundRect(), std::operator<<(), and impeller::testing::TEST().

## ◆ IsEmpty()

constexpr bool impeller::RoundRect::IsEmpty | ( |  | ) | const
| inline constexpr

Definition at line 65 of file round_rect.h.

65 { return bounds_.IsEmpty(); }
impeller::TRect::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
| inline constexpr

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 }
impeller::TRect::IsFinite
IsFinite() const
Returns true if all of the fields of this floating point rectangle are finite.
Definition: rect.h:292
impeller::TSize::IsFinite
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
| inline constexpr

Definition at line 71 of file round_rect.h.

71 {
72 return !bounds_.IsEmpty() && radii_.AreAllCornersSame() &&
73 ScalarNearlyEqual(radii_.top_left.width,
74 bounds_.GetWidth() * 0.5f) &&
75 ScalarNearlyEqual(radii_.top_left.height,
76 bounds_.GetHeight() * 0.5f);
77 }
impeller::ScalarNearlyEqual
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:36
impeller::RoundingRadii::AreAllCornersSame
constexpr bool AreAllCornersSame(Scalar tolerance=kEhCloseEnough) const
Definition: rounding_radii.h:54
impeller::TRect::GetHeight
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:351
impeller::TRect::GetWidth
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:345
impeller::TSize::height
Type height
Definition: size.h:29
impeller::TSize::width
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
| inline constexpr

Definition at line 67 of file round_rect.h.

67 {
68 return !bounds_.IsEmpty() && radii_.AreAllCornersEmpty();
69 }
impeller::RoundingRadii::AreAllCornersEmpty
constexpr bool AreAllCornersEmpty() const
Definition: rounding_radii.h:47

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
| ) |  |
| inline static

Definition at line 42 of file round_rect.h.

46 {
47 return MakeRectRadii(
48 rect, RoundingRadii::MakeNinePatch(left, top, right, bottom));
49 }
impeller::RoundingRadii::MakeNinePatch
constexpr static RoundingRadii MakeNinePatch(Scalar left, Scalar top, Scalar right, Scalar bottom)
Definition: rounding_radii.h:28

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

## ◆ MakeOval()

static RoundRect impeller::RoundRect::MakeOval | ( | const Rect & | rect | ) |
| inline static

Definition at line 23 of file round_rect.h.

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

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

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

## ◆ MakeRect()

static RoundRect impeller::RoundRect::MakeRect | ( | const Rect & | rect | ) |
| inline static

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 }
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:792
impeller::RoundRect::RoundRect
RoundRect()=default
impeller::TRect::GetPositive
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()

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

Definition at line 27 of file round_rect.h.

27 {
28 return MakeRectRadii(rect, RoundingRadii::MakeRadius(radius));
29 }
impeller::RoundingRadii::MakeRadius
constexpr static RoundingRadii MakeRadius(Scalar radius)
Definition: rounding_radii.h:20

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

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

## ◆ MakeRectXY() [1/2]

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

Definition at line 31 of file round_rect.h.

33 {
34 return MakeRectRadii(rect,
35 RoundingRadii::MakeRadii(Size(x_radius, y_radius)));
36 }
impeller::Size
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
| ) |  |
| inline static

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 & | r | ) | const
| inline constexpr

Definition at line 131 of file round_rect.h.

131 {
132 return !(*this == r);
133 }

## ◆ operator==()

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

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 }
impeller::TRect::Shift
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().

## Friends And Related Function Documentation

## ◆ DiffRoundRectPathSource

friend class DiffRoundRectPathSource
| friend

Definition at line 146 of file round_rect.h.

## ◆ RoundRectPathSource

friend class RoundRectPathSource
| friend

Definition at line 145 of file round_rect.h.

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

- impeller/geometry/round_rect.h
- impeller/geometry/round_rect.cc