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...
 
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
 
constexpr bool operator!= (const RoundSuperellipse &r) 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 }
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]

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

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
inlineconstexpr

◆ GetRadii()

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

◆ IsEmpty()

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

Definition at line 60 of file round_superellipse.h.

60 { 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 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  }
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 66 of file round_superellipse.h.

66  {
67  return !bounds_.IsEmpty() && radii_.AreAllCornersSame() &&
69  bounds_.GetWidth() * 0.5f) &&
71  bounds_.GetHeight() * 0.5f);
72  }
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:36
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::testing::TEST().

◆ IsRect()

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

Definition at line 62 of file round_superellipse.h.

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

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

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

◆ MakeOval()

static RoundSuperellipse impeller::RoundSuperellipse::MakeOval ( const Rect rect)
inlinestatic

Definition at line 25 of file round_superellipse.h.

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

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

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

◆ MakeRect()

static RoundSuperellipse impeller::RoundSuperellipse::MakeRect ( const Rect rect)
inlinestatic

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

static RoundSuperellipse impeller::RoundSuperellipse::MakeRectRadius ( const Rect rect,
Scalar  radius 
)
inlinestatic

Definition at line 29 of file round_superellipse.h.

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

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

Definition at line 34 of file round_superellipse.h.

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

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 r) const
inlineconstexpr

Definition at line 126 of file round_superellipse.h.

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

◆ operator==()

constexpr bool impeller::RoundSuperellipse::operator== ( const RoundSuperellipse rr) const
inlineconstexpr

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