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 rounded superellipse is a shape similar to a typical rounded rectangle
16 /// (`RoundRect`), but with smoother transitions between the straight sides and
17 /// the rounded corners. It resembles the `RoundedRectangle` shape in SwiftUI
18 /// with the `.continuous` corner style. Technically, it is created by replacing
19 /// the four corners of a superellipse (also known as a Lamé curve) with
20 /// circular arcs.
21 ///
22 /// The `bounds` defines the position and size of the shape. The `corner_radius`
23 /// corresponds to SwiftUI's `cornerRadius` parameter, which is close to, but
24 /// not exactly equals to, the radius of the corner circles.
25 class RoundSuperellipseGeometry final : public Geometry {
26  public:
27  RoundSuperellipseGeometry(const Rect& bounds, const RoundingRadii& radii);
28  RoundSuperellipseGeometry(const Rect& bounds, float corner_radius);
29 
30  ~RoundSuperellipseGeometry() override;
31 
32  // |Geometry|
33  bool CoversArea(const Matrix& transform, const Rect& rect) const override;
34 
35  // |Geometry|
36  bool IsAxisAlignedRect() const override;
37 
38  private:
39  // |Geometry|
40  GeometryResult GetPositionBuffer(const ContentContext& renderer,
41  const Entity& entity,
42  RenderPass& pass) const override;
43 
44  // |Geometry|
45  std::optional<Rect> GetCoverage(const Matrix& transform) const override;
46 
47  const Rect bounds_;
48  const RoundingRadii radii_;
49 
51 
53  delete;
54 };
55 
56 } // namespace impeller
57 
58 #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