Flutter Engine
The Flutter Engine
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< PointExtrema () 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< Vector2GetStartDirection () const
 
std::optional< Vector2GetEndDirection () 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

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{}

◆ CubicPathComponent() [2/3]

impeller::CubicPathComponent::CubicPathComponent ( const QuadraticPathComponent q)
inlineexplicit

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 {
233 scale, [&points](const Point& point) { points.emplace_back(point); });
234}
static const int points[]
TPoint< Scalar > Point
Definition: point.h:322
const Scalar scale
void ToLinearPathComponents(Scalar scale, const PointProc &proc) const

◆ 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
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}
uint8_t value
static void CubicPathBoundingPopulateValues(std::vector< Scalar > &values, Scalar p1, Scalar p2, Scalar p3, Scalar p4)
Point Solve(Scalar time) const

◆ 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}

◆ 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}

◆ 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 }

◆ 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}
static Scalar CubicSolve(Scalar t, Scalar p0, Scalar p1, Scalar p2, Scalar p3)
static double time(int loops, Benchmark *bench, Target *target)
Definition: nanobench.cpp:394

◆ SolveDerivative()

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

Definition at line 222 of file path_component.cc.

222 {
223 return {
226 };
227}
static Scalar CubicSolveDerivative(Scalar t, Scalar p0, Scalar p1, Scalar p2, Scalar p3)

◆ 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}
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19

◆ 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}
float Scalar
Definition: scalar.h:18
Scalar ComputeCubicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2, Point p3)

◆ 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}

Member Data Documentation

◆ cp1

Point impeller::CubicPathComponent::cp1

Definition at line 105 of file path_component.h.

◆ cp2

Point impeller::CubicPathComponent::cp2

Definition at line 107 of file path_component.h.

◆ p1

Point impeller::CubicPathComponent::p1

Definition at line 103 of file path_component.h.

◆ p2

Point impeller::CubicPathComponent::p2

Definition at line 109 of file path_component.h.


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