Flutter Impeller
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
 
size_t CountLinearPathComponents (Scalar scale) 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 174 of file path_component.h.

Member Typedef Documentation

◆ PointProc

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

Definition at line 203 of file path_component.h.

Constructor & Destructor Documentation

◆ CubicPathComponent() [1/3]

impeller::CubicPathComponent::CubicPathComponent ( )
inline

Definition at line 184 of file path_component.h.

184 {}

Referenced by Subsegment().

◆ CubicPathComponent() [2/3]

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

Definition at line 186 of file path_component.h.

187  : p1(q.p1),
188  cp1(q.p1 + (q.cp - q.p1) * (2.0 / 3.0)),
189  cp2(q.p2 + (q.cp - q.p2) * (2.0 / 3.0)),
190  p2(q.p2) {}

◆ CubicPathComponent() [3/3]

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

Definition at line 192 of file path_component.h.

193  : 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 326 of file path_component.cc.

328  {
330  scale, [&points](const Point& point) { points.emplace_back(point); });
331 }
TPoint< Scalar > Point
Definition: point.h:327
const Scalar scale
void ToLinearPathComponents(Scalar scale, const PointProc &proc) const

References scale, and ToLinearPathComponents().

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

◆ CountLinearPathComponents()

size_t impeller::CubicPathComponent::CountLinearPathComponents ( Scalar  scale) const

Definition at line 342 of file path_component.cc.

342  {
343  return std::ceilf(ComputeCubicSubdivisions(scale, *this)) + 2;
344 }
Scalar ComputeCubicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2, Point p3)

References impeller::ComputeCubicSubdivisions(), and scale.

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

◆ Extrema()

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

Definition at line 433 of file path_component.cc.

433  {
434  /*
435  * As described in: https://pomax.github.io/bezierinfo/#extremities
436  */
437  std::vector<Scalar> values;
438 
441 
442  std::vector<Point> points = {p1, p2};
443 
444  for (const auto& value : values) {
445  points.emplace_back(Solve(value));
446  }
447 
448  return points;
449 }
int32_t value
static void CubicPathBoundingPopulateValues(std::vector< Scalar > &values, Scalar p1, Scalar p2, Scalar p3, Scalar p4)
Point Solve(Scalar time) const

References cp1, cp2, impeller::CubicPathBoundingPopulateValues(), p1, p2, Solve(), value, 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 464 of file path_component.cc.

464  {
465  if (p2 != cp2) {
466  return (p2 - cp2).Normalize();
467  }
468  if (p2 != cp1) {
469  return (p2 - cp1).Normalize();
470  }
471  if (p2 != p1) {
472  return (p2 - p1).Normalize();
473  }
474  return std::nullopt;
475 }

References cp1, cp2, p1, and p2.

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

◆ GetStartDirection()

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

Definition at line 451 of file path_component.cc.

451  {
452  if (p1 != cp1) {
453  return (p1 - cp1).Normalize();
454  }
455  if (p1 != cp2) {
456  return (p1 - cp2).Normalize();
457  }
458  if (p1 != p2) {
459  return (p1 - p2).Normalize();
460  }
461  return std::nullopt;
462 }

References cp1, cp2, p1, and p2.

◆ operator==()

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

Definition at line 213 of file path_component.h.

213  {
214  return p1 == other.p1 && cp1 == other.cp1 && cp2 == other.cp2 &&
215  p2 == other.p2;
216  }

References cp1, cp2, p1, and p2.

◆ Solve()

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

Definition at line 312 of file path_component.cc.

312  {
313  return {
314  CubicSolve(time, p1.x, cp1.x, cp2.x, p2.x), // x
315  CubicSolve(time, p1.y, cp1.y, cp2.y, p2.y), // y
316  };
317 }
static Scalar CubicSolve(Scalar t, Scalar p0, Scalar p1, Scalar p2, Scalar p3)

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 319 of file path_component.cc.

319  {
320  return {
321  CubicSolveDerivative(time, p1.x, cp1.x, cp2.x, p2.x), // x
322  CubicSolveDerivative(time, p1.y, cp1.y, cp2.y, p2.y), // y
323  };
324 }
static Scalar CubicSolveDerivative(Scalar t, Scalar p0, Scalar p1, Scalar p2, Scalar p3)

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 351 of file path_component.cc.

351  {
352  auto p0 = Solve(t0);
353  auto p3 = Solve(t1);
354  auto d = Lower();
355  auto scale = (t1 - t0) * (1.0 / 3.0);
356  auto p1 = p0 + scale * d.Solve(t0);
357  auto p2 = p3 - scale * d.Solve(t1);
358  return CubicPathComponent(p0, p1, p2, p3);
359 }

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

◆ ToLinearPathComponents() [1/2]

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

Definition at line 361 of file path_component.cc.

362  {
363  Scalar line_count = std::ceilf(ComputeCubicSubdivisions(scale, *this));
364  for (size_t i = 1; i < line_count; i++) {
365  proc(Solve(i / line_count));
366  }
367  proc(p2);
368 }
float Scalar
Definition: scalar.h:18

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 333 of file path_component.cc.

334  {
335  Scalar line_count = std::ceilf(ComputeCubicSubdivisions(scale, *this));
336  for (size_t i = 1; i < line_count; i++) {
337  writer.Write(Solve(i / line_count));
338  }
339  writer.Write(p2);
340 }

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

Member Data Documentation

◆ cp1

◆ cp2

◆ p1

◆ p2


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