| Flutter Impeller |

Public Member Functions | Static Public Member Functions | 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...
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 }
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]

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

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 }
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]

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

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

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

Definition at line 52 of file round_rect.h.

52 { return bounds_; }

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

## ◆ GetRadii()

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

Definition at line 53 of file round_rect.h.

53 { return radii_; }

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

## ◆ IsEmpty()

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

Definition at line 63 of file round_rect.h.

63 { 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 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 }
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 69 of file round_rect.h.

69 {
70 return !bounds_.IsEmpty() && radii_.AreAllCornersSame() &&
71 ScalarNearlyEqual(radii_.top_left.width,
72 bounds_.GetWidth() * 0.5f) &&
73 ScalarNearlyEqual(radii_.top_left.height,
74 bounds_.GetHeight() * 0.5f);
75 }
impeller::ScalarNearlyEqual
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:35
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 65 of file round_rect.h.

65 {
66 return !bounds_.IsEmpty() && radii_.AreAllCornersEmpty();
67 }
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()

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

Definition at line 41 of file round_rect.h.

45 {
46 return MakeRectRadii(
47 rect, RoundingRadii::MakeNinePatch(left, top, right, bottom));
48 }
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()

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

Definition at line 22 of file round_rect.h.

22 {
23 return MakeRectRadii(rect, RoundingRadii::MakeRadii(rect.GetSize() * 0.5f));
24 }
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()

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

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

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

Definition at line 26 of file round_rect.h.

26 {
27 return MakeRectRadii(rect, RoundingRadii::MakeRadius(radius));
28 }
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]

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

Definition at line 30 of file round_rect.h.

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

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

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

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

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

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

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