| Flutter Impeller |

Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
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
| inline constexpr

Definition at line 35 of file rounding_radii.h.

35 {
36 return top_left.IsEmpty() && //
37 top_right.IsEmpty() && //
38 bottom_left.IsEmpty() && //
39 bottom_right.IsEmpty();
40 }

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
| inline constexpr

Definition at line 42 of file rounding_radii.h.

42 {
43 return ScalarNearlyEqual(top_left.width, top_right.width, tolerance) &&
44 ScalarNearlyEqual(top_left.width, bottom_right.width, tolerance) &&
45 ScalarNearlyEqual(top_left.width, bottom_left.width, tolerance) &&
46 ScalarNearlyEqual(top_left.height, top_right.height, tolerance) &&
47 ScalarNearlyEqual(top_left.height, bottom_right.height, tolerance) &&
48 ScalarNearlyEqual(top_left.height, bottom_left.height, tolerance);
49 }

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
| inline constexpr

Definition at line 28 of file rounding_radii.h.

28 {
29 return top_left.IsFinite() && //
30 top_right.IsFinite() && //
31 bottom_left.IsFinite() && //
32 bottom_right.IsFinite();
33 }

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 | ) |
| inline static constexpr

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 | ) |
| inline static constexpr

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(), and impeller::testing::TEST().

## ◆ operator!=()

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

Definition at line 76 of file rounding_radii.h.

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

## ◆ operator*()

constexpr RoundingRadii impeller::RoundingRadii::operator* | ( | Scalar | scale | ) |
| inline constexpr

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 }

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

## ◆ operator==()

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

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 }

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

Size impeller::RoundingRadii::bottom_left

Definition at line 17 of file rounding_radii.h.

Referenced by AreAllCornersEmpty(), AreAllCornersSame(), impeller::RoundRect::Contains(), impeller::RoundSuperellipseGeometry::CoversArea(), IsFinite(), impeller::RoundRect::IsFinite(), operator*(), std::operator<<(), operator==(), Scaled(), impeller::testing::TEST(), and impeller::interop::ToSkiaType().

## ◆ bottom_right

Size impeller::RoundingRadii::bottom_right

Definition at line 18 of file rounding_radii.h.

Referenced by AreAllCornersEmpty(), AreAllCornersSame(), impeller::RoundRect::Contains(), impeller::RoundSuperellipseGeometry::CoversArea(), IsFinite(), impeller::RoundRect::IsFinite(), operator*(), std::operator<<(), operator==(), Scaled(), impeller::testing::TEST(), and impeller::interop::ToSkiaType().

## ◆ top_left

Size impeller::RoundingRadii::top_left

Definition at line 15 of file rounding_radii.h.

Referenced by AreAllCornersEmpty(), AreAllCornersSame(), impeller::RoundRect::Contains(), impeller::RoundSuperellipseGeometry::CoversArea(), IsFinite(), impeller::RoundRect::IsFinite(), impeller::RoundRect::IsOval(), operator*(), std::operator<<(), operator==(), Scaled(), impeller::testing::TEST(), impeller::testing::TEST_P(), impeller::interop::ToImpellerType(), and impeller::interop::ToSkiaType().

## ◆ top_right

Size impeller::RoundingRadii::top_right

Definition at line 16 of file rounding_radii.h.

Referenced by AreAllCornersEmpty(), AreAllCornersSame(), impeller::RoundRect::Contains(), impeller::RoundSuperellipseGeometry::CoversArea(), IsFinite(), impeller::RoundRect::IsFinite(), operator*(), std::operator<<(), operator==(), Scaled(), impeller::testing::TEST(), and impeller::interop::ToSkiaType().

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

- impeller/geometry/rounding_radii.h
- impeller/geometry/rounding_radii.cc

impeller::RoundingRadii::AreAllCornersEmpty
constexpr bool AreAllCornersEmpty() const
Definition: rounding_radii.h:35
impeller::RoundingRadii::top_left
Size top_left
Definition: rounding_radii.h:15
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::TSize::IsFinite
IsFinite() const
Definition: size.h:126
impeller::AdjustScale
static void AdjustScale(Scalar &radius1, Scalar &radius2, Scalar dimension, Scalar &scale)
Definition: rounding_radii.cc:15
impeller::RoundingRadii::bottom_right
Size bottom_right
Definition: rounding_radii.h:18
impeller::NormalizeEmptyToZero
static void NormalizeEmptyToZero(Size &radii)
Definition: rounding_radii.cc:9
impeller::Size
TSize< Scalar > Size
Definition: size.h:171
impeller::RoundingRadii::bottom_left
Size bottom_left
Definition: rounding_radii.h:17
impeller::RoundingRadii::top_right
Size top_right
Definition: rounding_radii.h:16
impeller::RoundingRadii::IsFinite
constexpr bool IsFinite() const
Definition: rounding_radii.h:28
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:792
impeller::TSize::width
Type width
Definition: size.h:28
scale
const Scalar scale
Definition: stroke_path_geometry.cc:316
impeller::ScalarNearlyEqual
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:35
impeller::TSize::height
Type height
Definition: size.h:29
impeller::TSize::IsEmpty
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: size.h:123
impeller::TRect::GetPositive
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition: rect.h:402