| Flutter Impeller |

Public Member Functions | Public Attributes | List of all members
impeller::QuadraticPathComponent Struct Reference

`#include <path_component.h>`

## Public Member Functions
| QuadraticPathComponent ()
| QuadraticPathComponent (Point ap1, Point acp, Point ap2)
Point | Solve (Scalar time) const
Point | SolveDerivative (Scalar time) const
void | AppendPolylinePoints (Scalar scale_factor, std::vector< Point > &points) const
std::vector< Point > | Extrema () const
bool | operator== (const QuadraticPathComponent &other) const
std::optional< Vector2 > | GetStartDirection () const
std::optional< Vector2 > | GetEndDirection () const

## Public Attributes
Point | p1
Point | cp
Point | p2

## Detailed Description

Definition at line 52 of file path_component.h.

## Constructor & Destructor Documentation

## ◆ QuadraticPathComponent() [1/2]

impeller::QuadraticPathComponent::QuadraticPathComponent | ( |  | ) |
| inline

Definition at line 60 of file path_component.h.

60 {}

## ◆ QuadraticPathComponent() [2/2]

impeller::QuadraticPathComponent::QuadraticPathComponent | ( | Point | ap1,
|  | Point | acp,
|  | Point | ap2
| ) |  |
| inline

Definition at line 62 of file path_component.h.

63 : p1(ap1), cp(acp), p2(ap2) {}

## Member Function Documentation

## ◆ AppendPolylinePoints()

void impeller::QuadraticPathComponent::AppendPolylinePoints | ( | Scalar | scale_factor,
|  | std::vector< Point > & | points
| ) |  | const

Definition at line 106 of file path_component.cc.

108 {
109 auto tolerance = kDefaultCurveTolerance / scale_factor;
110 auto sqrt_tolerance = sqrt(tolerance);
111
112 auto d01 = cp - p1;
113 auto d12 = p2 - cp;
114 auto dd = d01 - d12;
115 auto cross = (p2 - p1).Cross(dd);
116 auto x0 = d01.Dot(dd) * 1 / cross;
117 auto x2 = d12.Dot(dd) * 1 / cross;
118 auto scale = std::abs(cross / (hypot(dd.x, dd.y) * (x2 - x0)));
119
120 auto a0 = ApproximateParabolaIntegral(x0);
121 auto a2 = ApproximateParabolaIntegral(x2);
122 Scalar val = 0.f;
123 if (std::isfinite(scale)) {
124 auto da = std::abs(a2 - a0);
125 auto sqrt_scale = sqrt(scale);
126 if ((x0 < 0 && x2 < 0) || (x0 >= 0 && x2 >= 0)) {
127 val = da * sqrt_scale;
128 } else {
129 // cusp case
130 auto xmin = sqrt_tolerance / sqrt_scale;
131 val = sqrt_tolerance * da / ApproximateParabolaIntegral(xmin);
132 }
133 }
134 auto u0 = ApproximateParabolaIntegral(a0);
135 auto u2 = ApproximateParabolaIntegral(a2);
136 auto uscale = 1 / (u2 - u0);
137
138 auto line_count = std::max(1., ceil(0.5 * val / sqrt_tolerance));
139 auto step = 1 / line_count;
140 for (size_t i = 1; i < line_count; i += 1) {
141 auto u = i * step;
142 auto a = a0 + (a2 - a0) * u;
143 auto t = (ApproximateParabolaIntegral(a) - u0) * uscale;
144 points.emplace_back(Solve(t));
145 }
146 points.emplace_back(p2);
147 }

References impeller::ApproximateParabolaIntegral(), cp, impeller::TPoint< T >::Dot(), impeller::kDefaultCurveTolerance, p1, p2, and Solve().

## ◆ Extrema()

std::vector< Point > impeller::QuadraticPathComponent::Extrema | ( |  | ) | const

Definition at line 149 of file path_component.cc.

149 {
150 CubicPathComponent elevated(*this);
151 return elevated.Extrema();
152 }

References impeller::CubicPathComponent::Extrema().

Referenced by impeller::Path::GetMinMaxCoveragePoints().

## ◆ GetEndDirection()

std::optional< Vector2 > impeller::QuadraticPathComponent::GetEndDirection | ( |  | ) | const

Definition at line 164 of file path_component.cc.

164 {
165 if (p2 != cp) {
166 return (p2 - cp).Normalize();
167 }
168 if (p2 != p1) {
169 return (p2 - p1).Normalize();
170 }
171 return std::nullopt;
172 }

References cp, p1, and p2.

Referenced by impeller::PathComponentEndDirectionVisitor::operator()().

## ◆ GetStartDirection()

std::optional< Vector2 > impeller::QuadraticPathComponent::GetStartDirection | ( |  | ) | const

Definition at line 154 of file path_component.cc.

154 {
155 if (p1 != cp) {
156 return (p1 - cp).Normalize();
157 }
158 if (p1 != p2) {
159 return (p1 - p2).Normalize();
160 }
161 return std::nullopt;
162 }

References cp, p1, and p2.

Referenced by impeller::PathComponentStartDirectionVisitor::operator()().

## ◆ operator==()

bool impeller::QuadraticPathComponent::operator== | ( | const QuadraticPathComponent & | other | ) | const
| inline

Definition at line 84 of file path_component.h.

84 {
85 return p1 == other.p1 && cp == other.cp && p2 == other.p2;
86 }

References cp, p1, and p2.

## ◆ Solve()

Point impeller::QuadraticPathComponent::Solve | ( | Scalar | time | ) | const

Definition at line 87 of file path_component.cc.

87 {
88 return {
89 QuadraticSolve(time, p1.x, cp.x, p2.x), // x
90 QuadraticSolve(time, p1.y, cp.y, p2.y), // y
91 };
92 }

References cp, p1, p2, impeller::QuadraticSolve(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by AppendPolylinePoints().

## ◆ SolveDerivative()

Point impeller::QuadraticPathComponent::SolveDerivative | ( | Scalar | time | ) | const

Definition at line 94 of file path_component.cc.

94 {
95 return {
96 QuadraticSolveDerivative(time, p1.x, cp.x, p2.x), // x
97 QuadraticSolveDerivative(time, p1.y, cp.y, p2.y), // y
98 };
99 }

References cp, p1, p2, impeller::QuadraticSolveDerivative(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## Member Data Documentation

## ◆ cp

Point impeller::QuadraticPathComponent::cp

Definition at line 56 of file path_component.h.

Referenced by AppendPolylinePoints(), GetEndDirection(), GetStartDirection(), operator==(), Solve(), SolveDerivative(), and impeller::testing::TEST().

## ◆ p1

Point impeller::QuadraticPathComponent::p1

Definition at line 54 of file path_component.h.

Referenced by AppendPolylinePoints(), GetEndDirection(), GetStartDirection(), operator==(), Solve(), SolveDerivative(), and impeller::testing::TEST().

## ◆ p2

Point impeller::QuadraticPathComponent::p2

Definition at line 58 of file path_component.h.

Referenced by AppendPolylinePoints(), GetEndDirection(), GetStartDirection(), operator==(), Solve(), SolveDerivative(), and impeller::testing::TEST().

The documentation for this struct was generated from the following files:

- impeller/geometry/path_component.h
- impeller/geometry/path_component.cc

impeller::TPoint::y
Type y
Definition: point.h:26
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::kDefaultCurveTolerance
static constexpr Scalar kDefaultCurveTolerance
Definition: path_component.h:26
impeller::QuadraticPathComponent::p1
Point p1
Definition: path_component.h:54
impeller::QuadraticPathComponent::cp
Point cp
Definition: path_component.h:56
impeller::QuadraticSolve
static Scalar QuadraticSolve(Scalar t, Scalar p0, Scalar p1, Scalar p2)
Definition: path_component.cc:19
impeller::TPoint::Dot
constexpr Type Dot(const TPoint &p) const
Definition: point.h:215
impeller::QuadraticPathComponent::Solve
Point Solve(Scalar time) const
Definition: path_component.cc:87
impeller::TPoint::x
Type x
Definition: point.h:25
impeller::QuadraticSolveDerivative
static Scalar QuadraticSolveDerivative(Scalar t, Scalar p0, Scalar p1, Scalar p2)
Definition: path_component.cc:25
impeller::QuadraticPathComponent::p2
Point p2
Definition: path_component.h:58
impeller::ApproximateParabolaIntegral
static Scalar ApproximateParabolaIntegral(Scalar x)
Definition: path_component.cc:101