Flutter Impeller
impeller::RoundSuperellipse Struct Reference

#include <round_superellipse.h>

Public Member Functions

 RoundSuperellipse ()=default
 
constexpr const RectGetBounds () const
 
constexpr const RoundingRadiiGetRadii () 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 }
static RoundSuperellipseParam MakeBoundsRadii(const Rect &bounds, const RoundingRadii &radii)
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
inlineconstexpr

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  }
static RoundSuperellipse MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
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
inlineconstexpr

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
inlineconstexpr

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
inlineconstexpr

◆ GetRadii()

constexpr const RoundingRadii& impeller::RoundSuperellipse::GetRadii ( ) const
inlineconstexpr

◆ IsEmpty()

constexpr bool impeller::RoundSuperellipse::IsEmpty ( ) const
inlineconstexpr

Definition at line 59 of file round_superellipse.h.

59 { return bounds_.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
inlineconstexpr

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

Definition at line 65 of file round_superellipse.h.

65  {
66  return !bounds_.IsEmpty() && radii_.AreAllCornersSame() &&
68  bounds_.GetWidth() * 0.5f) &&
70  bounds_.GetHeight() * 0.5f);
71  }
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:35
constexpr bool AreAllCornersSame(Scalar tolerance=kEhCloseEnough) const
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:351
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:345
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::PathBuilder::AddRoundSuperellipse(), and impeller::testing::TEST().

◆ IsRect()

constexpr bool impeller::RoundSuperellipse::IsRect ( ) const
inlineconstexpr

Definition at line 61 of file round_superellipse.h.

61  {
62  return !bounds_.IsEmpty() && radii_.AreAllCornersEmpty();
63  }
constexpr bool AreAllCornersEmpty() const

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

Definition at line 24 of file round_superellipse.h.

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

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

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 }
TRect< Scalar > Rect
Definition: rect.h:792
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 
)
inlinestaticconstexpr

Definition at line 28 of file round_superellipse.h.

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

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

Definition at line 33 of file round_superellipse.h.

35  {
36  return MakeRectRadii(rect,
37  RoundingRadii::MakeRadii(Size(x_radius, y_radius)));
38  }
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 
)
inlinestaticconstexpr

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
inlineconstexpr

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
inlineconstexpr

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
inlineconstexpr

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  }
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.
39 }
static RoundRect MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition: round_rect.cc:9
constexpr const RoundingRadii & GetRadii() const
constexpr const Rect & GetBounds() const

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


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