Flutter Impeller
impeller::RoundingRadii Struct Reference

#include <rounding_radii.h>

Public Member Functions

constexpr bool IsFinite () const
 
constexpr bool AreAllCornersEmpty () const
 
constexpr bool AreAllCornersSame (Scalar tolerance=kEhCloseEnough) const
 
RoundingRadii Scaled (const Rect &bounds) const
 Returns a scaled copy of this object, ensuring that the sum of the corner radii on each side does not exceed the width or height of the given bounds. More...
 
constexpr RoundingRadii operator* (Scalar scale)
 
constexpr bool operator== (const RoundingRadii &rr) const
 
constexpr bool operator!= (const RoundingRadii &rr) const
 

Static Public Member Functions

constexpr static RoundingRadii MakeRadius (Scalar radius)
 
constexpr static RoundingRadii MakeRadii (Size radii)
 
constexpr static RoundingRadii MakeNinePatch (Scalar left, Scalar top, Scalar right, Scalar bottom)
 

Public Attributes

Size top_left
 
Size top_right
 
Size bottom_left
 
Size bottom_right
 

Detailed Description

Definition at line 14 of file rounding_radii.h.

Member Function Documentation

◆ AreAllCornersEmpty()

constexpr bool impeller::RoundingRadii::AreAllCornersEmpty ( ) const
inlineconstexpr

Definition at line 47 of file rounding_radii.h.

47  {
48  return top_left.IsEmpty() && //
49  top_right.IsEmpty() && //
50  bottom_left.IsEmpty() && //
52  }
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: size.h:123

References bottom_left, bottom_right, impeller::TSize< T >::IsEmpty(), top_left, and top_right.

Referenced by impeller::RoundRect::IsRect(), impeller::RoundSuperellipse::IsRect(), Scaled(), and impeller::testing::TEST().

◆ AreAllCornersSame()

constexpr bool impeller::RoundingRadii::AreAllCornersSame ( Scalar  tolerance = kEhCloseEnough) const
inlineconstexpr

◆ IsFinite()

constexpr bool impeller::RoundingRadii::IsFinite ( ) const
inlineconstexpr

Definition at line 40 of file rounding_radii.h.

40  {
41  return top_left.IsFinite() && //
42  top_right.IsFinite() && //
43  bottom_left.IsFinite() && //
45  }
IsFinite() const
Definition: size.h:126

References bottom_left, bottom_right, impeller::TSize< T >::IsFinite(), top_left, and top_right.

Referenced by Scaled(), and impeller::testing::TEST().

◆ MakeNinePatch()

constexpr static RoundingRadii impeller::RoundingRadii::MakeNinePatch ( Scalar  left,
Scalar  top,
Scalar  right,
Scalar  bottom 
)
inlinestaticconstexpr

Definition at line 28 of file rounding_radii.h.

31  {
32  return {
33  .top_left = Size{left, top},
34  .top_right = Size{right, top},
35  .bottom_left = Size(left, bottom),
36  .bottom_right = Size(right, bottom),
37  };
38  }
TSize< Scalar > Size
Definition: size.h:159

References top_left.

Referenced by impeller::RoundRect::MakeNinePatch().

◆ MakeRadii()

constexpr static RoundingRadii impeller::RoundingRadii::MakeRadii ( Size  radii)
inlinestaticconstexpr

◆ MakeRadius()

constexpr static RoundingRadii impeller::RoundingRadii::MakeRadius ( Scalar  radius)
inlinestaticconstexpr

Definition at line 20 of file rounding_radii.h.

20  {
21  return {Size(radius), Size(radius), Size(radius), Size(radius)};
22  }

Referenced by impeller::RoundRect::MakeRectRadius(), impeller::RoundSuperellipse::MakeRectRadius(), and impeller::testing::TEST().

◆ operator!=()

constexpr bool impeller::RoundingRadii::operator!= ( const RoundingRadii rr) const
inlineconstexpr

Definition at line 88 of file rounding_radii.h.

88  {
89  return !(*this == rr);
90  }

◆ operator*()

constexpr RoundingRadii impeller::RoundingRadii::operator* ( Scalar  scale)
inlineconstexpr

Definition at line 72 of file rounding_radii.h.

72  {
73  return {
74  .top_left = top_left * scale,
75  .top_right = top_right * scale,
76  .bottom_left = bottom_left * scale,
77  .bottom_right = bottom_right * scale,
78  };
79  }

References bottom_left, bottom_right, top_left, and top_right.

◆ operator==()

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

Definition at line 81 of file rounding_radii.h.

81  {
82  return top_left == rr.top_left && //
83  top_right == rr.top_right && //
84  bottom_left == rr.bottom_left && //
85  bottom_right == rr.bottom_right;
86  }

References bottom_left, bottom_right, top_left, and top_right.

◆ Scaled()

RoundingRadii impeller::RoundingRadii::Scaled ( const Rect bounds) const

Returns a scaled copy of this object, ensuring that the sum of the corner radii on each side does not exceed the width or height of the given bounds.

See the Skia scaling implementation for more details.

Definition at line 26 of file rounding_radii.cc.

26  {
27  Rect bounds = in_bounds.GetPositive();
28  if (bounds.IsEmpty() || //
29  AreAllCornersEmpty() || !IsFinite()) {
30  // Normalize empty radii.
31  return RoundingRadii();
32  }
33 
34  // Copy the incoming radii so that we can work on normalizing them to the
35  // particular rectangle they are paired with without disturbing the caller.
36  RoundingRadii radii = *this;
37 
38  // If any corner is flat or has a negative value, normalize it to zeros
39  // We do this first so that the unnecessary non-flat part of that radius
40  // does not contribute to the global scaling below.
41  NormalizeEmptyToZero(radii.top_left);
42  NormalizeEmptyToZero(radii.top_right);
43  NormalizeEmptyToZero(radii.bottom_left);
44  NormalizeEmptyToZero(radii.bottom_right);
45 
46  // Now determine a global scale to apply to all of the radii to ensure
47  // that none of the adjacent pairs of radius values sum to larger than
48  // the corresponding dimension of the rectangle.
49  Size size = bounds.GetSize();
50  Scalar scale = 1.0f;
51  // clang-format off
52  AdjustScale(radii.top_left.width, radii.top_right.width, size.width,
53  scale);
54  AdjustScale(radii.bottom_left.width, radii.bottom_right.width, size.width,
55  scale);
56  AdjustScale(radii.top_left.height, radii.bottom_left.height, size.height,
57  scale);
58  AdjustScale(radii.top_right.height, radii.bottom_right.height, size.height,
59  scale);
60  // clang-format on
61  if (scale < 1.0f) {
62  radii = radii * scale;
63  }
64 
65  return radii;
66 }
float Scalar
Definition: scalar.h:19
TRect< Scalar > Rect
Definition: rect.h:792
static void AdjustScale(Scalar &radius1, Scalar &radius2, Scalar dimension, Scalar &scale)
static void NormalizeEmptyToZero(Size &radii)
constexpr bool AreAllCornersEmpty() const
constexpr bool IsFinite() const
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition: rect.h:402

References impeller::AdjustScale(), AreAllCornersEmpty(), bottom_left, bottom_right, impeller::TRect< T >::GetPositive(), impeller::TRect< T >::GetSize(), impeller::TSize< T >::height, impeller::TRect< T >::IsEmpty(), IsFinite(), impeller::NormalizeEmptyToZero(), top_left, top_right, and impeller::TSize< T >::width.

Referenced by impeller::RoundRect::MakeRectRadii(), and impeller::RoundSuperellipse::MakeRectRadii().

Member Data Documentation

◆ bottom_left

◆ bottom_right

◆ top_left

◆ top_right


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