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 
6 
9 
10 namespace impeller {
11 
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 
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.
39 }
40 
42  const RoundSuperellipse& round_superellipse)
43  : round_superellipse_(round_superellipse) {}
44 
46 
48  return FillType::kNonZero;
49 }
50 
52  return round_superellipse_.GetBounds();
53 }
54 
56  return true;
57 }
58 
61  round_superellipse_.GetBounds(), round_superellipse_.GetRadii());
62  param.Dispatch(receiver);
63 }
64 
65 } // namespace impeller
Collection of functions to receive path segments from the underlying path representation via the DlPa...
Definition: path_source.h:42
RoundSuperellipsePathSource(const RoundSuperellipse &round_superellipse)
void Dispatch(PathReceiver &receiver) const override
static RoundRect MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition: round_rect.cc:9
constexpr const RoundingRadii & GetRadii() const
static RoundSuperellipse MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
RoundRect ToApproximateRoundRect() const
constexpr const Rect & GetBounds() const
bool Contains(const Point &p) const
Returns true iff the provided point |p| is inside the half-open interior of this rectangle.
static RoundSuperellipseParam MakeBoundsRadii(const Rect &bounds, const RoundingRadii &radii)
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...
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
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition: rect.h:402
IsFinite() const
Returns true if all of the fields of this floating point rectangle are finite.
Definition: rect.h:292