| 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
std::vector< Point > | CreatePolyline (Scalar scale) const
void | FillPointsForPolyline (std::vector< Point > &points, Scalar scale_factor) 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 50 of file path_component.h.

## Constructor & Destructor Documentation

## ◆ QuadraticPathComponent() [1/2]

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

Definition at line 55 of file path_component.h.

55 {}

## ◆ QuadraticPathComponent() [2/2]

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

Definition at line 57 of file path_component.h.

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

## Member Function Documentation

## ◆ CreatePolyline()

std::vector< Point > impeller::QuadraticPathComponent::CreatePolyline | ( | Scalar | scale | ) | const

Definition at line 103 of file path_component.cc.

103 {
104 std::vector<Point> points;
105 FillPointsForPolyline(points, scale);
106 return points;
107 }

References FillPointsForPolyline().

## ◆ Extrema()

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

Definition at line 151 of file path_component.cc.

151 {
152 CubicPathComponent elevated(*this);
153 return elevated.Extrema();
154 }

References impeller::CubicPathComponent::Extrema().

## ◆ FillPointsForPolyline()

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

Definition at line 109 of file path_component.cc.

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

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

Referenced by CreatePolyline().

## ◆ GetEndDirection()

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

Definition at line 166 of file path_component.cc.

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

References cp, p1, and p2.

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

## ◆ GetStartDirection()

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

Definition at line 156 of file path_component.cc.

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

References cp, p1, and p2.

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

## ◆ operator==()

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

Definition at line 81 of file path_component.h.

81 {
82 return p1 == other.p1 && cp == other.cp && p2 == other.p2;
83 }

References cp, p1, and p2.

## ◆ Solve()

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

Definition at line 84 of file path_component.cc.

84 {
85 return {
86 QuadraticSolve(time, p1.x, cp.x, p2.x), // x
87 QuadraticSolve(time, p1.y, cp.y, p2.y), // y
88 };
89 }

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

Referenced by FillPointsForPolyline().

## ◆ SolveDerivative()

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

Definition at line 91 of file path_component.cc.

91 {
92 return {
93 QuadraticSolveDerivative(time, p1.x, cp.x, p2.x), // x
94 QuadraticSolveDerivative(time, p1.y, cp.y, p2.y), // y
95 };
96 }

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 52 of file path_component.h.

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

## ◆ p1

Point impeller::QuadraticPathComponent::p1

Definition at line 51 of file path_component.h.

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

## ◆ p2

Point impeller::QuadraticPathComponent::p2

Definition at line 53 of file path_component.h.

Referenced by FillPointsForPolyline(), 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:24
impeller::Scalar
float Scalar
Definition: scalar.h:15
impeller::kDefaultCurveTolerance
static constexpr Scalar kDefaultCurveTolerance
Definition: path_component.h:25
impeller::QuadraticPathComponent::p1
Point p1
Definition: path_component.h:51
impeller::QuadraticPathComponent::cp
Point cp
Definition: path_component.h:52
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:213
impeller::QuadraticPathComponent::Solve
Point Solve(Scalar time) const
Definition: path_component.cc:84
impeller::TPoint::x
Type x
Definition: point.h:23
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:53
impeller::QuadraticPathComponent::FillPointsForPolyline
void FillPointsForPolyline(std::vector< Point > &points, Scalar scale_factor) const
Definition: path_component.cc:109
impeller::ApproximateParabolaIntegral
static Scalar ApproximateParabolaIntegral(Scalar x)
Definition: path_component.cc:98