| Flutter Impeller |

round_superellipse.cc
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 #include "flutter/impeller/geometry/round_superellipse.h"
6
7 #include "flutter/impeller/geometry/round_rect.h"
8 #include "flutter/impeller/geometry/round_superellipse_param.h"
9
10 namespace impeller {
11
12 RoundSuperellipse RoundSuperellipse::MakeRectRadii(
13 const Rect& in_bounds,
14 const RoundingRadii& in_radii) {
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 }
25
26 [[nodiscard]] bool RoundSuperellipse::Contains(const Point& p) const {
27 if (!bounds_.Contains(p)) {
28 return false;
29 }
30 auto param = RoundSuperellipseParam::MakeBoundsRadii(bounds_, radii_);
31 return param.Contains(p);
32 }
33
34 RoundRect RoundSuperellipse::ToApproximateRoundRect() const {
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.
38 return RoundRect::MakeRectRadii(GetBounds(), GetRadii());
39 }
40
41 } // namespace impeller
impeller
Definition: allocation.cc:12
round_rect.h
round_superellipse.h
round_superellipse_param.h
impeller::RoundRect
Definition: round_rect.h:15
impeller::RoundRect::MakeRectRadii
static RoundRect MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition: round_rect.cc:9
impeller::RoundSuperellipse
Definition: round_superellipse.h:17
impeller::RoundSuperellipse::RoundSuperellipse
RoundSuperellipse()=default
impeller::RoundSuperellipse::GetRadii
constexpr const RoundingRadii & GetRadii() const
Definition: round_superellipse.h:49
impeller::RoundSuperellipse::MakeRectRadii
static RoundSuperellipse MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition: round_superellipse.cc:12
impeller::RoundSuperellipse::ToApproximateRoundRect
RoundRect ToApproximateRoundRect() const
Definition: round_superellipse.cc:34
impeller::RoundSuperellipse::GetBounds
constexpr const Rect & GetBounds() const
Definition: round_superellipse.h:48
impeller::RoundSuperellipse::Contains
bool Contains(const Point &p) const
Returns true iff the provided point |p| is inside the half-open interior of this rectangle.
Definition: round_superellipse.cc:26
impeller::RoundSuperellipseParam::MakeBoundsRadii
static RoundSuperellipseParam MakeBoundsRadii(const Rect &bounds, const RoundingRadii &radii)
Definition: round_superellipse_param.cc:463
impeller::RoundingRadii
Definition: rounding_radii.h:14
impeller::RoundingRadii::Scaled
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...
Definition: rounding_radii.cc:26
impeller::TPoint< Scalar >
impeller::TRect< Scalar >
impeller::TRect::Contains
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
impeller::TRect::GetPositive
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition: rect.h:402
impeller::TRect::IsFinite
IsFinite() const
Returns true if all of the fields of this floating point rectangle are finite.
Definition: rect.h:292