| 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 RoundSuperellipsePathSource::RoundSuperellipsePathSource(
42 const RoundSuperellipse& round_superellipse)
43 : round_superellipse_(round_superellipse) {}
44
45 RoundSuperellipsePathSource::~RoundSuperellipsePathSource() = default;
46
47 FillType RoundSuperellipsePathSource::GetFillType() const {
48 return FillType::kNonZero;
49 }
50
51 Rect RoundSuperellipsePathSource::GetBounds() const {
52 return round_superellipse_.GetBounds();
53 }
54
55 bool RoundSuperellipsePathSource::IsConvex() const {
56 return true;
57 }
58
59 void RoundSuperellipsePathSource::Dispatch(PathReceiver& receiver) const {
60 auto param = RoundSuperellipseParam::MakeBoundsRadii(
61 round_superellipse_.GetBounds(), round_superellipse_.GetRadii());
62 param.Dispatch(receiver);
63 }
64
65 } // namespace impeller
impeller::PathReceiver
Collection of functions to receive path segments from the underlying path representation via the DlPa...
Definition: path_source.h:42
impeller::RoundSuperellipsePathSource::RoundSuperellipsePathSource
RoundSuperellipsePathSource(const RoundSuperellipse &round_superellipse)
Definition: round_superellipse.cc:41
impeller::RoundSuperellipsePathSource::GetBounds
Rect GetBounds() const override
Definition: round_superellipse.cc:51
impeller::RoundSuperellipsePathSource::IsConvex
bool IsConvex() const override
Definition: round_superellipse.cc:55
impeller::RoundSuperellipsePathSource::~RoundSuperellipsePathSource
~RoundSuperellipsePathSource()
impeller::RoundSuperellipsePathSource::GetFillType
FillType GetFillType() const override
Definition: round_superellipse.cc:47
impeller::RoundSuperellipsePathSource::Dispatch
void Dispatch(PathReceiver &receiver) const override
Definition: round_superellipse.cc:59
impeller
Definition: allocation.cc:12
impeller::FillType
FillType
Definition: path_source.h:13
impeller::FillType::kNonZero
@ kNonZero
round_rect.h
round_superellipse.h
round_superellipse_param.h
impeller::RoundRect
Definition: round_rect.h:16
impeller::RoundRect::MakeRectRadii
static RoundRect MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition: round_rect.cc:9
impeller::RoundSuperellipse
Definition: round_superellipse.h:18
impeller::RoundSuperellipse::RoundSuperellipse
RoundSuperellipse()=default
impeller::RoundSuperellipse::GetRadii
constexpr const RoundingRadii & GetRadii() const
Definition: round_superellipse.h:50
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:49
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:491
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:231
impeller::TRect::GetPositive
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition: rect.h:398
impeller::TRect::IsFinite
IsFinite() const
Returns true if all of the fields of this floating point rectangle are finite.
Definition: rect.h:288