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

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

## Detailed Description

Definition at line 18 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:491
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:231

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

## ◆ Expand() [1/3]

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

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

Definition at line 115 of file round_superellipse.h.

115 {
116 // Use the factory rather than the internal constructor as the changing
117 // size of the rectangle requires that we re-validate the radii to the
118 // newly sized rectangle.
119 return MakeRectRadii(bounds_.Expand(amount), radii_);
120 }
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:618

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

## ◆ Expand() [2/3]

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

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

Definition at line 105 of file round_superellipse.h.

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

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

## ◆ Expand() [3/3]

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

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

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 49 of file round_superellipse.h.

49 { return bounds_; }

Referenced by impeller::RoundSuperellipsePathSource::Dispatch(), impeller::Canvas::DrawRoundSuperellipse(), impeller::RoundSuperellipsePathSource::GetBounds(), std::operator<<(), impeller::testing::TEST(), and ToApproximateRoundRect().

## ◆ GetRadii()

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

Definition at line 50 of file round_superellipse.h.

50 { return radii_; }

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

## ◆ IsEmpty()

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

Definition at line 60 of file round_superellipse.h.

60 { 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:297

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

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

## ◆ IsFinite()

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

Definition at line 52 of file round_superellipse.h.

52 {
53 return bounds_.IsFinite() && //
54 radii_.top_left.IsFinite() && //
55 radii_.top_right.IsFinite() && //
56 radii_.bottom_left.IsFinite() && //
57 radii_.bottom_right.IsFinite();
58 }
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:288
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 66 of file round_superellipse.h.

66 {
67 return !bounds_.IsEmpty() && radii_.AreAllCornersSame() &&
68 ScalarNearlyEqual(radii_.top_left.width,
69 bounds_.GetWidth() * 0.5f) &&
70 ScalarNearlyEqual(radii_.top_left.height,
71 bounds_.GetHeight() * 0.5f);
72 }
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:347
impeller::TRect::GetWidth
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:341
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::RoundSuperellipse::IsRect | ( |  | ) | const
| inline constexpr

Definition at line 62 of file round_superellipse.h.

62 {
63 return !bounds_.IsEmpty() && radii_.AreAllCornersEmpty();
64 }
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().

## ◆ MakeOval()

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

Definition at line 25 of file round_superellipse.h.

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

Definition at line 21 of file round_superellipse.h.

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

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:788
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:398

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

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

Definition at line 29 of file round_superellipse.h.

30 {
31 return MakeRectRadii(rect, RoundingRadii::MakeRadius(radius));
32 }
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(), and impeller::testing::TEST_P().

## ◆ MakeRectXY() [1/2]

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

Definition at line 34 of file round_superellipse.h.

36 {
37 return MakeRectRadii(rect,
38 RoundingRadii::MakeRadii(Size(x_radius, y_radius)));
39 }
impeller::Size
TSize< Scalar > Size
Definition: size.h:159

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

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

## ◆ MakeRectXY() [2/2]

static RoundSuperellipse impeller::RoundSuperellipse::MakeRectXY | ( | const Rect & | rect,
|  | Size | corner_radii
| ) |  |
| inline static

Definition at line 41 of file round_superellipse.h.

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

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

## ◆ operator==()

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

Definition at line 122 of file round_superellipse.h.

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

## ◆ Shift()

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

Returns a new round rectangle translated by the given offset.

Definition at line 84 of file round_superellipse.h.

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

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:50
impeller::RoundSuperellipse::GetBounds
constexpr const Rect & GetBounds() const
Definition: round_superellipse.h:49

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