Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
 
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 79 of file path_component.h.

Member Typedef Documentation

◆ PointProc

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

Definition at line 108 of file path_component.h.

Constructor & Destructor Documentation

◆ CubicPathComponent() [1/3]

impeller::CubicPathComponent::CubicPathComponent ( )
inline

Definition at line 89 of file path_component.h.

89{}

◆ CubicPathComponent() [2/3]

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

Definition at line 91 of file path_component.h.

92 : p1(q.p1),
93 cp1(q.p1 + (q.cp - q.p1) * (2.0 / 3.0)),
94 cp2(q.p2 + (q.cp - q.p2) * (2.0 / 3.0)),
95 p2(q.p2) {}

◆ CubicPathComponent() [3/3]

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

Definition at line 97 of file path_component.h.

98 : 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 161 of file path_component.cc.

163 {
165 scale, [&points](const Point& point) { points.emplace_back(point); });
166}
static const int points[]
TPoint< Scalar > Point
Definition point.h:316
const Scalar scale
void ToLinearPathComponents(Scalar scale, const PointProc &proc) const

◆ Extrema()

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

Definition at line 255 of file path_component.cc.

255 {
256 /*
257 * As described in: https://pomax.github.io/bezierinfo/#extremities
258 */
259 std::vector<Scalar> values;
260
263
264 std::vector<Point> points = {p1, p2};
265
266 for (const auto& value : values) {
267 points.emplace_back(Solve(value));
268 }
269
270 return points;
271}
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 286 of file path_component.cc.

286 {
287 if (p2 != cp2) {
288 return (p2 - cp2).Normalize();
289 }
290 if (p2 != cp1) {
291 return (p2 - cp1).Normalize();
292 }
293 if (p2 != p1) {
294 return (p2 - p1).Normalize();
295 }
296 return std::nullopt;
297}

◆ GetStartDirection()

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

Definition at line 273 of file path_component.cc.

273 {
274 if (p1 != cp1) {
275 return (p1 - cp1).Normalize();
276 }
277 if (p1 != cp2) {
278 return (p1 - cp2).Normalize();
279 }
280 if (p1 != p2) {
281 return (p1 - p2).Normalize();
282 }
283 return std::nullopt;
284}

◆ operator==()

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

Definition at line 114 of file path_component.h.

114 {
115 return p1 == other.p1 && cp1 == other.cp1 && cp2 == other.cp2 &&
116 p2 == other.p2;
117 }

◆ Solve()

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

Definition at line 147 of file path_component.cc.

147 {
148 return {
149 CubicSolve(time, p1.x, cp1.x, cp2.x, p2.x), // x
150 CubicSolve(time, p1.y, cp1.y, cp2.y, p2.y), // y
151 };
152}
static Scalar CubicSolve(Scalar t, Scalar p0, Scalar p1, Scalar p2, Scalar p3)

◆ SolveDerivative()

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

Definition at line 154 of file path_component.cc.

154 {
155 return {
156 CubicSolveDerivative(time, p1.x, cp1.x, cp2.x, p2.x), // x
157 CubicSolveDerivative(time, p1.y, cp1.y, cp2.y, p2.y), // y
158 };
159}
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 173 of file path_component.cc.

173 {
174 auto p0 = Solve(t0);
175 auto p3 = Solve(t1);
176 auto d = Lower();
177 auto scale = (t1 - t0) * (1.0 / 3.0);
178 auto p1 = p0 + scale * d.Solve(t0);
179 auto p2 = p3 - scale * d.Solve(t1);
180 return CubicPathComponent(p0, p1, p2, p3);
181}
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19

◆ ToLinearPathComponents()

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

Definition at line 183 of file path_component.cc.

184 {
185 Scalar line_count = std::ceilf(ComputeCubicSubdivisions(scale, *this));
186 for (size_t i = 1; i < line_count; i++) {
187 proc(Solve(i / line_count));
188 }
189 proc(p2);
190}
float Scalar
Definition scalar.h:18
Scalar ComputeCubicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2, Point p3)

Member Data Documentation

◆ cp1

Point impeller::CubicPathComponent::cp1

Definition at line 83 of file path_component.h.

◆ cp2

Point impeller::CubicPathComponent::cp2

Definition at line 85 of file path_component.h.

◆ p1

Point impeller::CubicPathComponent::p1

Definition at line 81 of file path_component.h.

◆ p2

Point impeller::CubicPathComponent::p2

Definition at line 87 of file path_component.h.


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