Flutter Impeller
round_superellipse_geometry.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_ENTITY_GEOMETRY_ROUND_SUPERELLIPSE_GEOMETRY_H_
6 #define FLUTTER_IMPELLER_ENTITY_GEOMETRY_ROUND_SUPERELLIPSE_GEOMETRY_H_
7 
10 
11 namespace impeller {
12 
13 /// Geometry class that can generate vertices for a rounded superellipse.
14 ///
15 /// A superellipse is an ellipse-like shape that is defined by the parameters N,
16 /// alpha, and beta:
17 ///
18 /// 1 = |x / b| ^n + |y / a| ^n
19 ///
20 /// A rounded superellipse is a square-like superellipse (a=b) with its four
21 /// corners replaced by circular arcs. It replicates the `RoundedRectangle`
22 /// shape in SwiftUI with corner style `.continuous`.
23 ///
24 /// The `bounds` defines the position and size of the shape. The `corner_radius`
25 /// corresponds to SwiftUI's `cornerRadius` parameter, which is close to, but
26 /// not exactly equals to, the radius of the corner circles.
27 class RoundSuperellipseGeometry final : public Geometry {
28  public:
29  RoundSuperellipseGeometry(const Rect& bounds, const RoundingRadii& radii);
30  RoundSuperellipseGeometry(const Rect& bounds, float corner_radius);
31 
32  ~RoundSuperellipseGeometry() override;
33 
34  // |Geometry|
35  bool CoversArea(const Matrix& transform, const Rect& rect) const override;
36 
37  // |Geometry|
38  bool IsAxisAlignedRect() const override;
39 
40  private:
41  // |Geometry|
42  GeometryResult GetPositionBuffer(const ContentContext& renderer,
43  const Entity& entity,
44  RenderPass& pass) const override;
45 
46  // |Geometry|
47  std::optional<Rect> GetCoverage(const Matrix& transform) const override;
48 
49  const Rect bounds_;
50  const RoundingRadii radii_;
51 
53 
55  delete;
56 };
57 
58 } // namespace impeller
59 
60 #endif // FLUTTER_IMPELLER_ENTITY_GEOMETRY_ROUND_SUPERELLIPSE_GEOMETRY_H_
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
bool CoversArea(const Matrix &transform, const Rect &rect) const override
Determines if this geometry, transformed by the given transform, will completely cover all surface ar...
RoundSuperellipseGeometry(const Rect &bounds, const RoundingRadii &radii)
A 4x4 matrix using column-major storage.
Definition: matrix.h:37