| Flutter Impeller |

Public Member Functions | Static Public Member Functions | List of all members
impeller::RoundSuperellipse Struct Reference

`#include <round_superellipse.h>`

## Public Member Functions
| RoundSuperellipse ()=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 RoundSuperellipse | Shift (Scalar dx, Scalar dy) const
| Returns a new round rectangle translated by the given offset. More...
constexpr RoundSuperellipse | Expand (Scalar left, Scalar top, Scalar right, Scalar bottom) const
| Returns a round rectangle with expanded edges. Negative expansion results in shrinking. More...
constexpr RoundSuperellipse | Expand (Scalar horizontal, Scalar vertical) const
| Returns a round rectangle with expanded edges. Negative expansion results in shrinking. More...
constexpr RoundSuperellipse | Expand (Scalar amount) const
| Returns a round rectangle with expanded edges. Negative expansion results in shrinking. More...
constexpr bool | operator== (const RoundSuperellipse &rr) const
constexpr bool | operator!= (const RoundSuperellipse &r) const
RoundRect | ToApproximateRoundRect () const

## Static Public Member Functions
constexpr static RoundSuperellipse | MakeRect (const Rect &rect)
constexpr static RoundSuperellipse | MakeOval (const Rect &rect)
constexpr static RoundSuperellipse | MakeRectRadius (const Rect &rect, Scalar radius)
constexpr static RoundSuperellipse | MakeRectXY (const Rect &rect, Scalar x_radius, Scalar y_radius)
constexpr static RoundSuperellipse | MakeRectXY (const Rect &rect, Size corner_radii)
static RoundSuperellipse | MakeRectRadii (const Rect &rect, const RoundingRadii &radii)

## Detailed Description

Definition at line 17 of file round_superellipse.h.

## Constructor & Destructor Documentation

## ◆ RoundSuperellipse()

impeller::RoundSuperellipse::RoundSuperellipse | ( |  | ) |
| default

Referenced by MakeRectRadii().

## Member Function Documentation

## ◆ Contains()

bool impeller::RoundSuperellipse::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 26 of file round_superellipse.cc.

26 {
27 if (!bounds_.Contains(p)) {
28 return false;
29 }
30 auto param = RoundSuperellipseParam::MakeBoundsRadii(bounds_, radii_);
31 return param.Contains(p);
32 }
impeller::RoundSuperellipseParam::MakeBoundsRadii
static RoundSuperellipseParam MakeBoundsRadii(const Rect &bounds, const RoundingRadii &radii)
Definition: round_superellipse_param.cc:463
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

References impeller::TRect< T >::Contains(), and impeller::RoundSuperellipseParam::MakeBoundsRadii().

## ◆ Expand() [1/3]

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

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

Definition at line 114 of file round_superellipse.h.

114 {
115 // Use the factory rather than the internal constructor as the changing
116 // size of the rectangle requires that we re-validate the radii to the
117 // newly sized rectangle.
118 return MakeRectRadii(bounds_.Expand(amount), radii_);
119 }
impeller::RoundSuperellipse::MakeRectRadii
static RoundSuperellipse MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition: round_superellipse.cc:12
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 RoundSuperellipse impeller::RoundSuperellipse::Expand | ( | Scalar | horizontal,
|  | Scalar | vertical
| ) |  | const
| inline constexpr

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

Definition at line 104 of file round_superellipse.h.

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

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

## ◆ Expand() [3/3]

constexpr RoundSuperellipse impeller::RoundSuperellipse::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 92 of file round_superellipse.h.

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

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

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

## ◆ GetBounds()

constexpr const Rect& impeller::RoundSuperellipse::GetBounds | ( |  | ) | const
| inline constexpr

Definition at line 48 of file round_superellipse.h.

48 { return bounds_; }

Referenced by impeller::PathBuilder::AddRoundSuperellipse(), impeller::Canvas::DrawRoundSuperellipse(), std::operator<<(), impeller::testing::TEST(), and ToApproximateRoundRect().

## ◆ GetRadii()

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

Definition at line 49 of file round_superellipse.h.

49 { return radii_; }

Referenced by impeller::PathBuilder::AddRoundSuperellipse(), impeller::Canvas::DrawRoundSuperellipse(), std::operator<<(), impeller::testing::TEST(), and ToApproximateRoundRect().

## ◆ IsEmpty()

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

Definition at line 59 of file round_superellipse.h.

59 { 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::RoundSuperellipse::IsFinite | ( |  | ) | const
| inline constexpr

Definition at line 51 of file round_superellipse.h.

51 {
52 return bounds_.IsFinite() && //
53 radii_.top_left.IsFinite() && //
54 radii_.top_right.IsFinite() && //
55 radii_.bottom_left.IsFinite() && //
56 radii_.bottom_right.IsFinite();
57 }
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::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::RoundSuperellipse::IsOval | ( |  | ) | const
| inline constexpr

Definition at line 65 of file round_superellipse.h.

65 {
66 return !bounds_.IsEmpty() && radii_.AreAllCornersSame() &&
67 ScalarNearlyEqual(radii_.top_left.width,
68 bounds_.GetWidth() * 0.5f) &&
69 ScalarNearlyEqual(radii_.top_left.height,
70 bounds_.GetHeight() * 0.5f);
71 }
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::PathBuilder::AddRoundSuperellipse(), and impeller::testing::TEST().

## ◆ IsRect()

constexpr bool impeller::RoundSuperellipse::IsRect | ( |  | ) | const
| inline constexpr

Definition at line 61 of file round_superellipse.h.

61 {
62 return !bounds_.IsEmpty() && radii_.AreAllCornersEmpty();
63 }
impeller::RoundingRadii::AreAllCornersEmpty
constexpr bool AreAllCornersEmpty() const
Definition: rounding_radii.h:47

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

Referenced by impeller::PathBuilder::AddRoundSuperellipse(), and impeller::testing::TEST().

## ◆ MakeOval()

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

Definition at line 24 of file round_superellipse.h.

24 {
25 return MakeRectRadii(rect, RoundingRadii::MakeRadii(rect.GetSize() * 0.5f));
26 }
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 RoundSuperellipse impeller::RoundSuperellipse::MakeRect | ( | const Rect & | rect | ) |
| inline static constexpr

Definition at line 20 of file round_superellipse.h.

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

References MakeRectRadii().

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

## ◆ MakeRectRadii()

RoundSuperellipse impeller::RoundSuperellipse::MakeRectRadii | ( | const Rect & | rect,
|  | const RoundingRadii & | radii
| ) |  |
| static

Definition at line 12 of file round_superellipse.cc.

14 {
15 if (!in_bounds.IsFinite()) {
16 return {};
17 }
18 Rect bounds = in_bounds.GetPositive();
19 // RoundingRadii::Scaled might return an empty radii if bounds or in_radii is
20 // empty, which is expected. Pass along the bounds even if the radii is empty
21 // as it would still have a valid location and/or 1-dimensional size which
22 // might appear when stroked
23 return RoundSuperellipse(bounds, in_radii.Scaled(bounds));
24 }
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:792
impeller::RoundSuperellipse::RoundSuperellipse
RoundSuperellipse()=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(), RoundSuperellipse(), and impeller::RoundingRadii::Scaled().

Referenced by Expand(), MakeOval(), MakeRect(), MakeRectRadius(), MakeRectXY(), Shift(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ MakeRectRadius()

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

Definition at line 28 of file round_superellipse.h.

29 {
30 return MakeRectRadii(rect, RoundingRadii::MakeRadius(radius));
31 }
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 RoundSuperellipse impeller::RoundSuperellipse::MakeRectXY | ( | const Rect & | rect,
|  | Scalar | x_radius,
|  | Scalar | y_radius
| ) |  |
| inline static constexpr

Definition at line 33 of file round_superellipse.h.

35 {
36 return MakeRectRadii(rect,
37 RoundingRadii::MakeRadii(Size(x_radius, y_radius)));
38 }
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 RoundSuperellipse impeller::RoundSuperellipse::MakeRectXY | ( | const Rect & | rect,
|  | Size | corner_radii
| ) |  |
| inline static constexpr

Definition at line 40 of file round_superellipse.h.

41 {
42 return MakeRectRadii(rect, RoundingRadii::MakeRadii(corner_radii));
43 }

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

## ◆ operator!=()

constexpr bool impeller::RoundSuperellipse::operator!= | ( | const RoundSuperellipse & | r | ) | const
| inline constexpr

Definition at line 125 of file round_superellipse.h.

125 {
126 return !(*this == r);
127 }

## ◆ operator==()

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

Definition at line 121 of file round_superellipse.h.

121 {
122 return bounds_ == rr.bounds_ && radii_ == rr.radii_;
123 }

## ◆ Shift()

constexpr RoundSuperellipse impeller::RoundSuperellipse::Shift | ( | Scalar | dx,
|  | Scalar | dy
| ) |  | const
| inline constexpr

Returns a new round rectangle translated by the given offset.

Definition at line 83 of file round_superellipse.h.

83 {
84 // Just in case, use the factory rather than the internal constructor
85 // as shifting the rectangle may increase/decrease its bit precision
86 // so we should re-validate the radii to the newly located rectangle.
87 return MakeRectRadii(bounds_.Shift(dx, dy), radii_);
88 }
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().

## ◆ ToApproximateRoundRect()

RoundRect impeller::RoundSuperellipse::ToApproximateRoundRect | ( |  | ) | const

Definition at line 34 of file round_superellipse.cc.

34 {
35 // Experiments have shown that using the same corner radii for the RRect
36 // provides an approximation that is close to optimal, as achieving a perfect
37 // match is not feasible.
38 return RoundRect::MakeRectRadii(GetBounds(), GetRadii());
39 }
impeller::RoundRect::MakeRectRadii
static RoundRect MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition: round_rect.cc:9
impeller::RoundSuperellipse::GetRadii
constexpr const RoundingRadii & GetRadii() const
Definition: round_superellipse.h:49
impeller::RoundSuperellipse::GetBounds
constexpr const Rect & GetBounds() const
Definition: round_superellipse.h:48

References GetBounds(), GetRadii(), and impeller::RoundRect::MakeRectRadii().

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

- impeller/geometry/round_superellipse.h
- impeller/geometry/round_superellipse.cc