Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
Loading...
Searching...
No Matches
round_superellipse_param.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_GEOMETRY_ROUND_SUPERELLIPSE_PARAM_H_
6
#define FLUTTER_IMPELLER_GEOMETRY_ROUND_SUPERELLIPSE_PARAM_H_
7
8
#include "
flutter/impeller/geometry/path_source.h
"
9
#include "
flutter/impeller/geometry/point.h
"
10
#include "
flutter/impeller/geometry/rect.h
"
11
#include "
flutter/impeller/geometry/rounding_radii.h
"
12
#include "
flutter/impeller/geometry/size.h
"
13
14
namespace
impeller
{
15
16
// A utility struct that expands input parameters for a rounded superellipse to
17
// drawing variables.
18
struct
RoundSuperellipseParam
{
19
// Parameters for drawing a square-like rounded superellipse.
20
//
21
// This structure is used to define an octant of an arbitrary rounded
22
// superellipse.
23
//
24
// A `se_n` of 0 means that the radius is 0, and this octant is a square
25
// of size `se_a` at `offset` and all other fields are ignored.
26
struct
Octant
{
27
// The offset of the square-like rounded superellipse's center from the
28
// origin.
29
//
30
// All other coordinates in this structure are relative to this point.
31
Point
offset
;
32
33
// The semi-axis length of the superellipse.
34
Scalar
se_a
;
35
// The degree of the superellipse.
36
//
37
// If this value is 0, then this octant is a square of size `se_a`.
38
Scalar
se_n
;
39
// The range of the parameter "theta" used to define the superellipse curve.
40
//
41
// The "theta" is not the angle of the curve but the implicit parameter
42
// used in the curve's parametric equation.
43
Scalar
se_max_theta
;
44
45
// The coordinate of the top left end of the circular arc, relative to the
46
// `offset` point.
47
Point
circle_start
;
48
// The center of the circular arc, relative to the `offset` point.
49
Point
circle_center
;
50
// The angular span of the circular arc, measured in radians.
51
Radians
circle_max_angle
;
52
53
Scalar
circle_radius
;
54
};
55
56
// Parameters for drawing a rounded superellipse with equal radius size for
57
// all corners.
58
//
59
// This structure is used to define a quadrant of an arbitrary rounded
60
// superellipse.
61
struct
Quadrant
{
62
// The offset of the rounded superellipse's center from the origin.
63
//
64
// All other coordinates in this structure are relative to this point.
65
Point
offset
;
66
67
// The scaling factor used to transform a normalized rounded superellipse
68
// back to its original, unnormalized shape.
69
//
70
// Normalization refers to adjusting the original curve, which may have
71
// asymmetrical corner sizes, into a symmetrical one by reducing the longer
72
// radius to match the shorter one. For instance, to draw a rounded
73
// superellipse with size (200, 300) and radii (20, 10), the function first
74
// draws a normalized RSE with size (100, 300) and radii (10, 10), then
75
// scales it by (2x, 1x) to restore the original proportions.
76
//
77
// Normalization also flips the curve to the first quadrant (positive x and
78
// y) if it originally resides in another quadrant. This affects the signs
79
// of `signed_scale`.
80
Point
signed_scale
;
81
82
// The parameters for the two octants that make up this quadrant after
83
// normalization.
84
Octant
top
;
85
Octant
right
;
86
};
87
88
// The parameters for the four quadrants that make up the full contour.
89
//
90
// If `all_corners_same` is true, then only `top_right` is popularized.
91
Quadrant
top_right
;
92
Quadrant
bottom_right
;
93
Quadrant
bottom_left
;
94
Quadrant
top_left
;
95
96
// If true, all corners are the same and only `top_right` is popularized.
97
bool
all_corners_same
;
98
99
// Create a param for a rounded superellipse with the specific bounds and
100
// radii.
101
[[nodiscard]]
static
RoundSuperellipseParam
MakeBoundsRadii
(
102
const
Rect
& bounds,
103
const
RoundingRadii
& radii);
104
105
[[nodiscard]]
static
RoundSuperellipseParam
MakeBoundsRadius
(
106
const
Rect
& bounds,
107
Scalar
radius);
108
109
// Returns whether this rounded superellipse contains the point.
110
//
111
// This method does not perform any prescreening such as comparing the point
112
// with the bounds, which is recommended for callers.
113
bool
Contains
(
const
Point
& point)
const
;
114
115
// Dispatch the path operations of this rounded superellipse to the receiver.
116
void
Dispatch
(
PathReceiver
& receiver)
const
;
117
118
// A factor used to calculate the "gap", defined as the distance from the
119
// midpoint of the curved corners to the nearest sides of the bounding box.
120
//
121
// When the corner radius is symmetrical on both dimensions, the midpoint of
122
// the corner is where the circular arc intersects its quadrant bisector. When
123
// the corner radius is asymmetrical, since the corner can be considered
124
// "elongated" from a symmetrical corner, the midpoint is transformed in the
125
// same way.
126
//
127
// Experiments indicate that the gap is linear with respect to the corner
128
// radius on that dimension.
129
static
constexpr
Scalar
kGapFactor
= 0.29289321881f;
// 1-cos(pi/4)
130
};
131
132
}
// namespace impeller
133
134
#endif
// FLUTTER_IMPELLER_GEOMETRY_ROUND_SUPERELLIPSE_PARAM_H_
impeller::PathReceiver
Collection of functions to receive path segments from the underlying path representation via the DlPa...
Definition
path_source.h:42
point.h
rect.h
size.h
impeller
Definition
texture.h:16
impeller::Scalar
float Scalar
Definition
scalar.h:19
path_source.h
rounding_radii.h
impeller::Radians
Definition
scalar.h:44
impeller::RoundSuperellipseParam::Octant
Definition
round_superellipse_param.h:26
impeller::RoundSuperellipseParam::Octant::se_max_theta
Scalar se_max_theta
Definition
round_superellipse_param.h:43
impeller::RoundSuperellipseParam::Octant::circle_center
Point circle_center
Definition
round_superellipse_param.h:49
impeller::RoundSuperellipseParam::Octant::offset
Point offset
Definition
round_superellipse_param.h:31
impeller::RoundSuperellipseParam::Octant::se_a
Scalar se_a
Definition
round_superellipse_param.h:34
impeller::RoundSuperellipseParam::Octant::circle_max_angle
Radians circle_max_angle
Definition
round_superellipse_param.h:51
impeller::RoundSuperellipseParam::Octant::se_n
Scalar se_n
Definition
round_superellipse_param.h:38
impeller::RoundSuperellipseParam::Octant::circle_start
Point circle_start
Definition
round_superellipse_param.h:47
impeller::RoundSuperellipseParam::Octant::circle_radius
Scalar circle_radius
Definition
round_superellipse_param.h:53
impeller::RoundSuperellipseParam::Quadrant
Definition
round_superellipse_param.h:61
impeller::RoundSuperellipseParam::Quadrant::signed_scale
Point signed_scale
Definition
round_superellipse_param.h:80
impeller::RoundSuperellipseParam::Quadrant::right
Octant right
Definition
round_superellipse_param.h:85
impeller::RoundSuperellipseParam::Quadrant::top
Octant top
Definition
round_superellipse_param.h:84
impeller::RoundSuperellipseParam::Quadrant::offset
Point offset
Definition
round_superellipse_param.h:65
impeller::RoundSuperellipseParam
Definition
round_superellipse_param.h:18
impeller::RoundSuperellipseParam::top_left
Quadrant top_left
Definition
round_superellipse_param.h:94
impeller::RoundSuperellipseParam::MakeBoundsRadii
static RoundSuperellipseParam MakeBoundsRadii(const Rect &bounds, const RoundingRadii &radii)
Definition
round_superellipse_param.cc:576
impeller::RoundSuperellipseParam::Dispatch
void Dispatch(PathReceiver &receiver) const
Definition
round_superellipse_param.cc:615
impeller::RoundSuperellipseParam::Contains
bool Contains(const Point &point) const
Definition
round_superellipse_param.cc:639
impeller::RoundSuperellipseParam::bottom_left
Quadrant bottom_left
Definition
round_superellipse_param.h:93
impeller::RoundSuperellipseParam::kGapFactor
static constexpr Scalar kGapFactor
Definition
round_superellipse_param.h:129
impeller::RoundSuperellipseParam::all_corners_same
bool all_corners_same
Definition
round_superellipse_param.h:97
impeller::RoundSuperellipseParam::top_right
Quadrant top_right
Definition
round_superellipse_param.h:91
impeller::RoundSuperellipseParam::MakeBoundsRadius
static RoundSuperellipseParam MakeBoundsRadius(const Rect &bounds, Scalar radius)
Definition
round_superellipse_param.cc:566
impeller::RoundSuperellipseParam::bottom_right
Quadrant bottom_right
Definition
round_superellipse_param.h:92
impeller::RoundingRadii
Definition
rounding_radii.h:14
impeller::TPoint< Scalar >
impeller::TRect< Scalar >
impeller
geometry
round_superellipse_param.h
Generated on Mon May 25 2026 06:07:35 for Flutter Engine Uber Docs by
1.9.8