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)
 

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 35 of file rounding_radii.h.

35  {
36  return top_left.IsEmpty() && //
37  top_right.IsEmpty() && //
38  bottom_left.IsEmpty() && //
40  }
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(), Scaled(), and impeller::testing::TEST().

◆ AreAllCornersSame()

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

Definition at line 42 of file rounding_radii.h.

42  {
43  return ScalarNearlyEqual(top_left.width, top_right.width, tolerance) &&
49  }
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:35
Type height
Definition: size.h:29
Type width
Definition: size.h:28

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

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

◆ IsFinite()

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

Definition at line 28 of file rounding_radii.h.

28  {
29  return top_left.IsFinite() && //
30  top_right.IsFinite() && //
31  bottom_left.IsFinite() && //
33  }
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().

◆ MakeRadii()

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

Definition at line 24 of file rounding_radii.h.

24  {
25  return {radii, radii, radii, radii};
26  }

Referenced by impeller::RoundRect::MakeOval(), impeller::RoundRect::MakeRectXY(), and impeller::testing::TEST().

◆ 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  }
TSize< Scalar > Size
Definition: size.h:171

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

◆ operator!=()

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

Definition at line 76 of file rounding_radii.h.

76  {
77  return !(*this == rr);
78  }

◆ operator*()

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

Definition at line 60 of file rounding_radii.h.

60  {
61  return {
62  .top_left = top_left * scale,
63  .top_right = top_right * scale,
64  .bottom_left = bottom_left * scale,
65  .bottom_right = bottom_right * scale,
66  };
67  }
const Scalar scale

References bottom_left, bottom_right, scale, top_left, and top_right.

◆ operator==()

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

Definition at line 69 of file rounding_radii.h.

69  {
70  return top_left == rr.top_left && //
71  top_right == rr.top_right && //
72  bottom_left == rr.bottom_left && //
73  bottom_right == rr.bottom_right;
74  }

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:18
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(), scale, top_left, top_right, and impeller::TSize< T >::width.

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

Member Data Documentation

◆ bottom_left

◆ bottom_right

◆ top_left

◆ top_right


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