| Flutter Impeller |

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

`#include <path_component.h>`

## Public Types
using | PointProc = std::function< void(const Point &point)>

## Public Member Functions
| CubicPathComponent ()
| CubicPathComponent (const QuadraticPathComponent &q)
| CubicPathComponent (Point ap1, Point acp1, Point acp2, Point ap2)
Point | Solve (Scalar time) const
Point | SolveDerivative (Scalar time) const
void | AppendPolylinePoints (Scalar scale, std::vector< Point > &points) const
std::vector< Point > | Extrema () const
void | ToLinearPathComponents (Scalar scale, const PointProc &proc) const
void | ToLinearPathComponents (Scalar scale, VertexWriter &writer) const
CubicPathComponent | Subsegment (Scalar t0, Scalar t1) const
bool | operator== (const CubicPathComponent &other) const
std::optional< Vector2 > | GetStartDirection () const
std::optional< Vector2 > | GetEndDirection () const

## Public Attributes
Point | p1
Point | cp1
Point | cp2
Point | p2

## Detailed Description

Definition at line 101 of file path_component.h.

## Member Typedef Documentation

## ◆ PointProc

using impeller::CubicPathComponent::PointProc = std::function<void(const Point& point)>

Definition at line 130 of file path_component.h.

## Constructor & Destructor Documentation

## ◆ CubicPathComponent() [1/3]

impeller::CubicPathComponent::CubicPathComponent | ( |  | ) |
| inline

Definition at line 111 of file path_component.h.

111 {}

Referenced by Subsegment().

## ◆ CubicPathComponent() [2/3]

impeller::CubicPathComponent::CubicPathComponent | ( | const QuadraticPathComponent & | q | ) |
| inline explicit

Definition at line 113 of file path_component.h.

114 : p1(q.p1),
115 cp1(q.p1 + (q.cp - q.p1) * (2.0 / 3.0)),
116 cp2(q.p2 + (q.cp - q.p2) * (2.0 / 3.0)),
117 p2(q.p2) {}

## ◆ CubicPathComponent() [3/3]

impeller::CubicPathComponent::CubicPathComponent | ( | Point | ap1,
|  | Point | acp1,
|  | Point | acp2,
|  | Point | ap2
| ) |  |
| inline

Definition at line 119 of file path_component.h.

120 : p1(ap1), cp1(acp1), cp2(acp2), p2(ap2) {}

## Member Function Documentation

## ◆ AppendPolylinePoints()

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

Definition at line 229 of file path_component.cc.

231 {
232 ToLinearPathComponents(
233 scale, [&points](const Point& point) { points.emplace_back(point); });
234 }

References scale, and ToLinearPathComponents().

## ◆ Extrema()

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

Definition at line 332 of file path_component.cc.

332 {
333 /*
334 * As described in: https://pomax.github.io/bezierinfo/#extremities
335 */
336 std::vector<Scalar> values;
337
338 CubicPathBoundingPopulateValues(values, p1.x, cp1.x, cp2.x, p2.x);
339 CubicPathBoundingPopulateValues(values, p1.y, cp1.y, cp2.y, p2.y);
340
341 std::vector<Point> points = {p1, p2};
342
343 for (const auto& value : values) {
344 points.emplace_back(Solve(value));
345 }
346
347 return points;
348 }

References cp1, cp2, impeller::CubicPathBoundingPopulateValues(), p1, p2, Solve(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by impeller::QuadraticPathComponent::Extrema(), and impeller::testing::TEST().

## ◆ GetEndDirection()

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

Definition at line 363 of file path_component.cc.

363 {
364 if (p2 != cp2) {
365 return (p2 - cp2).Normalize();
366 }
367 if (p2 != cp1) {
368 return (p2 - cp1).Normalize();
369 }
370 if (p2 != p1) {
371 return (p2 - p1).Normalize();
372 }
373 return std::nullopt;
374 }

References cp1, cp2, p1, and p2.

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

## ◆ GetStartDirection()

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

Definition at line 350 of file path_component.cc.

350 {
351 if (p1 != cp1) {
352 return (p1 - cp1).Normalize();
353 }
354 if (p1 != cp2) {
355 return (p1 - cp2).Normalize();
356 }
357 if (p1 != p2) {
358 return (p1 - p2).Normalize();
359 }
360 return std::nullopt;
361 }

References cp1, cp2, p1, and p2.

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

## ◆ operator==()

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

Definition at line 138 of file path_component.h.

138 {
139 return p1 == other.p1 && cp1 == other.cp1 && cp2 == other.cp2 &&
140 p2 == other.p2;
141 }

References cp1, cp2, p1, and p2.

## ◆ Solve()

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

Definition at line 215 of file path_component.cc.

215 {
216 return {
217 CubicSolve(time, p1.x, cp1.x, cp2.x, p2.x), // x
218 CubicSolve(time, p1.y, cp1.y, cp2.y, p2.y), // y
219 };
220 }

References cp1, cp2, impeller::CubicSolve(), p1, p2, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by Extrema(), Subsegment(), and ToLinearPathComponents().

## ◆ SolveDerivative()

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

Definition at line 222 of file path_component.cc.

222 {
223 return {
224 CubicSolveDerivative(time, p1.x, cp1.x, cp2.x, p2.x), // x
225 CubicSolveDerivative(time, p1.y, cp1.y, cp2.y, p2.y), // y
226 };
227 }

References cp1, cp2, impeller::CubicSolveDerivative(), p1, p2, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## ◆ Subsegment()

CubicPathComponent impeller::CubicPathComponent::Subsegment | ( | Scalar | t0,
|  | Scalar | t1
| ) |  | const

Definition at line 250 of file path_component.cc.

250 {
251 auto p0 = Solve(t0);
252 auto p3 = Solve(t1);
253 auto d = Lower();
254 auto scale = (t1 - t0) * (1.0 / 3.0);
255 auto p1 = p0 + scale * d.Solve(t0);
256 auto p2 = p3 - scale * d.Solve(t1);
257 return CubicPathComponent(p0, p1, p2, p3);
258 }

References CubicPathComponent(), p1, p2, scale, and Solve().

## ◆ ToLinearPathComponents() [1/2]

void impeller::CubicPathComponent::ToLinearPathComponents | ( | Scalar | scale,
|  | const PointProc & | proc
| ) |  | const

Definition at line 260 of file path_component.cc.

261 {
262 Scalar line_count = std::ceilf(ComputeCubicSubdivisions(scale, *this));
263 for (size_t i = 1; i < line_count; i++) {
264 proc(Solve(i / line_count));
265 }
266 proc(p2);
267 }

References impeller::ComputeCubicSubdivisions(), p2, scale, and Solve().

Referenced by AppendPolylinePoints(), and impeller::Path::WritePolyline().

## ◆ ToLinearPathComponents() [2/2]

void impeller::CubicPathComponent::ToLinearPathComponents | ( | Scalar | scale,
|  | VertexWriter & | writer
| ) |  | const

Definition at line 236 of file path_component.cc.

237 {
238 Scalar line_count = std::ceilf(ComputeCubicSubdivisions(scale, *this));
239 for (size_t i = 1; i < line_count; i++) {
240 writer.Write(Solve(i / line_count));
241 }
242 writer.Write(p2);
243 }

References impeller::ComputeCubicSubdivisions(), p2, scale, Solve(), and impeller::VertexWriter::Write().

## Member Data Documentation

## ◆ cp1

Point impeller::CubicPathComponent::cp1

Definition at line 105 of file path_component.h.

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

## ◆ cp2

Point impeller::CubicPathComponent::cp2

Definition at line 107 of file path_component.h.

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

## ◆ p1

Point impeller::CubicPathComponent::p1

Definition at line 103 of file path_component.h.

Referenced by impeller::ComputeCubicSubdivisions(), Extrema(), GetEndDirection(), GetStartDirection(), operator==(), Solve(), SolveDerivative(), Subsegment(), impeller::testing::TEST(), and impeller::Path::WritePolyline().

## ◆ p2

Point impeller::CubicPathComponent::p2

Definition at line 109 of file path_component.h.

Referenced by impeller::ComputeCubicSubdivisions(), Extrema(), GetEndDirection(), GetStartDirection(), operator==(), Solve(), SolveDerivative(), Subsegment(), impeller::testing::TEST(), and ToLinearPathComponents().

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:31
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::CubicPathComponent::p1
Point p1
Definition: path_component.h:103
impeller::CubicPathComponent::cp2
Point cp2
Definition: path_component.h:107
impeller::CubicPathComponent::Solve
Point Solve(Scalar time) const
Definition: path_component.cc:215
impeller::CubicPathBoundingPopulateValues
static void CubicPathBoundingPopulateValues(std::vector< Scalar > &values, Scalar p1, Scalar p2, Scalar p3, Scalar p4)
Definition: path_component.cc:277
impeller::CubicSolveDerivative
static Scalar CubicSolveDerivative(Scalar t, Scalar p0, Scalar p1, Scalar p2, Scalar p3)
Definition: path_component.cc:104
impeller::CubicPathComponent::cp1
Point cp1
Definition: path_component.h:105
impeller::Point
TPoint< Scalar > Point
Definition: point.h:322
impeller::CubicSolve
static Scalar CubicSolve(Scalar t, Scalar p0, Scalar p1, Scalar p2, Scalar p3)
Definition: path_component.cc:93
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::CubicPathComponent::CubicPathComponent
CubicPathComponent()
Definition: path_component.h:111
impeller::CubicPathComponent::ToLinearPathComponents
void ToLinearPathComponents(Scalar scale, const PointProc &proc) const
Definition: path_component.cc:260
impeller::ComputeCubicSubdivisions
Scalar ComputeCubicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2, Point p3)
Definition: wangs_formula.cc:23
scale
const Scalar scale
Definition: stroke_path_geometry.cc:308
impeller::CubicPathComponent::p2
Point p2
Definition: path_component.h:109