Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
rounding_radii.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_IMPELLER_GEOMETRY_ROUNDING_RADII_H_
6#define FLUTTER_IMPELLER_GEOMETRY_ROUNDING_RADII_H_
7
11
12namespace impeller {
13
19
20 constexpr static RoundingRadii MakeRadius(Scalar radius) {
21 return {Size(radius), Size(radius), Size(radius), Size(radius)};
22 }
23
24 constexpr static RoundingRadii MakeRadii(Size radii) {
25 return {radii, radii, radii, radii};
26 }
27
28 constexpr static RoundingRadii MakeNinePatch(Scalar left,
29 Scalar top,
30 Scalar right,
31 Scalar bottom) {
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 }
39
40 constexpr bool IsFinite() const {
41 return top_left.IsFinite() && //
42 top_right.IsFinite() && //
43 bottom_left.IsFinite() && //
45 }
46
47 constexpr bool AreAllCornersEmpty() const {
48 return top_left.IsEmpty() && //
49 top_right.IsEmpty() && //
50 bottom_left.IsEmpty() && //
52 }
53
62
69
70 /// @brief Returns a scaled copy of this object, ensuring that the sum of the
71 /// corner radii on each side does not exceed the width or height of
72 /// the given bounds.
73 ///
74 /// See the [Skia scaling
75 /// implementation](https://github.com/google/skia/blob/main/src/core/SkRRect.cpp)
76 /// for more details.
77 RoundingRadii Scaled(const Rect& bounds) const;
78
79 constexpr inline RoundingRadii operator*(Scalar scale) {
80 return {
81 .top_left = top_left * scale,
82 .top_right = top_right * scale,
83 .bottom_left = bottom_left * scale,
84 .bottom_right = bottom_right * scale,
85 };
86 }
87
88 [[nodiscard]] constexpr bool operator==(const RoundingRadii& rr) const {
89 return top_left == rr.top_left && //
90 top_right == rr.top_right && //
91 bottom_left == rr.bottom_left && //
93 }
94};
95
96} // namespace impeller
97
98namespace std {
99
100inline std::ostream& operator<<(std::ostream& out,
101 const impeller::RoundingRadii& rr) {
102 out << "(" //
103 << "ul: " << rr.top_left << ", " //
104 << "ur: " << rr.top_right << ", " //
105 << "ll: " << rr.bottom_left << ", " //
106 << "lr: " << rr.bottom_right //
107 << ")";
108 return out;
109}
110
111} // namespace std
112
113#endif // FLUTTER_IMPELLER_GEOMETRY_ROUNDING_RADII_H_
float Scalar
Definition scalar.h:19
constexpr float kEhCloseEnough
Definition constants.h:57
TSize< Scalar > Size
Definition size.h:159
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition scalar.h:36
Definition ref_ptr.h:261
std::ostream & operator<<(std::ostream &out, const impeller::Arc &a)
Definition arc.h:141
constexpr bool operator==(const RoundingRadii &rr) const
static constexpr RoundingRadii MakeRadii(Size radii)
constexpr bool AreAllCornersEmpty() const
constexpr bool IsFinite() const
constexpr bool AreAllCornersCircular() const
static constexpr RoundingRadii MakeNinePatch(Scalar left, Scalar top, Scalar right, Scalar bottom)
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...
static constexpr RoundingRadii MakeRadius(Scalar radius)
constexpr RoundingRadii operator*(Scalar scale)
constexpr bool AreAllCornersSame(Scalar tolerance=kEhCloseEnough) const
Type height
Definition size.h:29
Type width
Definition size.h:28
IsFinite() const
Definition size.h:126
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition size.h:123