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

Member Typedef Documentation

◆ PointProc

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

Definition at line 309 of file path_component.h.

Constructor & Destructor Documentation

◆ CubicPathComponent() [1/3]

impeller::CubicPathComponent::CubicPathComponent ( )
inline

Definition at line 290 of file path_component.h.

290 {}

Referenced by Subsegment().

◆ CubicPathComponent() [2/3]

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

Definition at line 292 of file path_component.h.

293  : p1(q.p1),
294  cp1(q.p1 + (q.cp - q.p1) * (2.0 / 3.0)),
295  cp2(q.p2 + (q.cp - q.p2) * (2.0 / 3.0)),
296  p2(q.p2) {}

◆ CubicPathComponent() [3/3]

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

Definition at line 298 of file path_component.h.

299  : 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 459 of file path_component.cc.

461  {
463  scale, [&points](const Point& point) { points.emplace_back(point); });
464 }
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 475 of file path_component.cc.

475  {
476  return std::ceilf(ComputeCubicSubdivisions(scale, *this)) + 2;
477 }
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 566 of file path_component.cc.

566  {
567  /*
568  * As described in: https://pomax.github.io/bezierinfo/#extremities
569  */
570  std::vector<Scalar> values;
571 
574 
575  std::vector<Point> points = {p1, p2};
576 
577  for (const auto& value : values) {
578  points.emplace_back(Solve(value));
579  }
580 
581  return points;
582 }
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 597 of file path_component.cc.

597  {
598  if (p2 != cp2) {
599  return (p2 - cp2).Normalize();
600  }
601  if (p2 != cp1) {
602  return (p2 - cp1).Normalize();
603  }
604  if (p2 != p1) {
605  return (p2 - p1).Normalize();
606  }
607  return std::nullopt;
608 }

References cp1, cp2, p1, and p2.

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

◆ GetStartDirection()

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

Definition at line 584 of file path_component.cc.

584  {
585  if (p1 != cp1) {
586  return (p1 - cp1).Normalize();
587  }
588  if (p1 != cp2) {
589  return (p1 - cp2).Normalize();
590  }
591  if (p1 != p2) {
592  return (p1 - p2).Normalize();
593  }
594  return std::nullopt;
595 }

References cp1, cp2, p1, and p2.

◆ operator==()

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

Definition at line 319 of file path_component.h.

319  {
320  return p1 == other.p1 && cp1 == other.cp1 && cp2 == other.cp2 &&
321  p2 == other.p2;
322  }

References cp1, cp2, p1, and p2.

◆ Solve()

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

Definition at line 445 of file path_component.cc.

445  {
446  return {
447  CubicSolve(time, p1.x, cp1.x, cp2.x, p2.x), // x
448  CubicSolve(time, p1.y, cp1.y, cp2.y, p2.y), // y
449  };
450 }
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 452 of file path_component.cc.

452  {
453  return {
454  CubicSolveDerivative(time, p1.x, cp1.x, cp2.x, p2.x), // x
455  CubicSolveDerivative(time, p1.y, cp1.y, cp2.y, p2.y), // y
456  };
457 }
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 484 of file path_component.cc.

484  {
485  auto p0 = Solve(t0);
486  auto p3 = Solve(t1);
487  auto d = Lower();
488  auto scale = (t1 - t0) * (1.0 / 3.0);
489  auto p1 = p0 + scale * d.Solve(t0);
490  auto p2 = p3 - scale * d.Solve(t1);
491  return CubicPathComponent(p0, p1, p2, p3);
492 }

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

◆ ToLinearPathComponents() [1/2]

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

Definition at line 494 of file path_component.cc.

495  {
496  Scalar line_count = std::ceilf(ComputeCubicSubdivisions(scale, *this));
497  for (size_t i = 1; i < line_count; i++) {
498  proc(Solve(i / line_count));
499  }
500  proc(p2);
501 }
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 466 of file path_component.cc.

467  {
468  Scalar line_count = std::ceilf(ComputeCubicSubdivisions(scale, *this));
469  for (size_t i = 1; i < line_count; i++) {
470  writer.Write(Solve(i / line_count));
471  }
472  writer.Write(p2);
473 }

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: