Flutter Impeller
impeller::QuadraticPathComponent Struct Reference

#include <path_component.h>

Public Types

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

Public Member Functions

 QuadraticPathComponent ()
 
 QuadraticPathComponent (Point ap1, Point acp, Point ap2)
 
Point Solve (Scalar time) const
 
Point SolveDerivative (Scalar time) const
 
void AppendPolylinePoints (Scalar scale_factor, std::vector< Point > &points) const
 
void ToLinearPathComponents (Scalar scale_factor, const PointProc &proc) const
 
void ToLinearPathComponents (Scalar scale, VertexWriter &writer) const
 
std::vector< PointExtrema () const
 
bool operator== (const QuadraticPathComponent &other) const
 
std::optional< Vector2GetStartDirection () const
 
std::optional< Vector2GetEndDirection () const
 

Public Attributes

Point p1
 
Point cp
 
Point p2
 

Detailed Description

Definition at line 62 of file path_component.h.

Member Typedef Documentation

◆ PointProc

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

Definition at line 82 of file path_component.h.

Constructor & Destructor Documentation

◆ QuadraticPathComponent() [1/2]

impeller::QuadraticPathComponent::QuadraticPathComponent ( )
inline

Definition at line 70 of file path_component.h.

70 {}

◆ QuadraticPathComponent() [2/2]

impeller::QuadraticPathComponent::QuadraticPathComponent ( Point  ap1,
Point  acp,
Point  ap2 
)
inline

Definition at line 72 of file path_component.h.

73  : p1(ap1), cp(acp), p2(ap2) {}

Member Function Documentation

◆ AppendPolylinePoints()

void impeller::QuadraticPathComponent::AppendPolylinePoints ( Scalar  scale_factor,
std::vector< Point > &  points 
) const

Definition at line 171 of file path_component.cc.

173  {
174  ToLinearPathComponents(scale_factor, [&points](const Point& point) {
175  points.emplace_back(point);
176  });
177 }

References ToLinearPathComponents().

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

◆ Extrema()

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

Definition at line 190 of file path_component.cc.

190  {
191  CubicPathComponent elevated(*this);
192  return elevated.Extrema();
193 }

References impeller::CubicPathComponent::Extrema().

◆ GetEndDirection()

std::optional< Vector2 > impeller::QuadraticPathComponent::GetEndDirection ( ) const

Definition at line 205 of file path_component.cc.

205  {
206  if (p2 != cp) {
207  return (p2 - cp).Normalize();
208  }
209  if (p2 != p1) {
210  return (p2 - p1).Normalize();
211  }
212  return std::nullopt;
213 }

References cp, p1, and p2.

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

◆ GetStartDirection()

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

Definition at line 195 of file path_component.cc.

195  {
196  if (p1 != cp) {
197  return (p1 - cp).Normalize();
198  }
199  if (p1 != p2) {
200  return (p1 - p2).Normalize();
201  }
202  return std::nullopt;
203 }

References cp, p1, and p2.

◆ operator==()

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

Definition at line 90 of file path_component.h.

90  {
91  return p1 == other.p1 && cp == other.cp && p2 == other.p2;
92  }

References cp, p1, and p2.

◆ Solve()

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

Definition at line 147 of file path_component.cc.

147  {
148  return {
149  QuadraticSolve(time, p1.x, cp.x, p2.x), // x
150  QuadraticSolve(time, p1.y, cp.y, p2.y), // y
151  };
152 }

References cp, p1, p2, impeller::QuadraticSolve(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by ToLinearPathComponents().

◆ SolveDerivative()

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

Definition at line 154 of file path_component.cc.

154  {
155  return {
156  QuadraticSolveDerivative(time, p1.x, cp.x, p2.x), // x
157  QuadraticSolveDerivative(time, p1.y, cp.y, p2.y), // y
158  };
159 }

References cp, p1, p2, impeller::QuadraticSolveDerivative(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

◆ ToLinearPathComponents() [1/2]

void impeller::QuadraticPathComponent::ToLinearPathComponents ( Scalar  scale,
VertexWriter writer 
) const

Definition at line 161 of file path_component.cc.

163  {
164  Scalar line_count = std::ceilf(ComputeQuadradicSubdivisions(scale, *this));
165  for (size_t i = 1; i < line_count; i += 1) {
166  writer.Write(Solve(i / line_count));
167  }
168  writer.Write(p2);
169 }

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

◆ ToLinearPathComponents() [2/2]

void impeller::QuadraticPathComponent::ToLinearPathComponents ( Scalar  scale_factor,
const PointProc proc 
) const

Definition at line 179 of file path_component.cc.

181  {
182  Scalar line_count =
183  std::ceilf(ComputeQuadradicSubdivisions(scale_factor, *this));
184  for (size_t i = 1; i < line_count; i += 1) {
185  proc(Solve(i / line_count));
186  }
187  proc(p2);
188 }

References impeller::ComputeQuadradicSubdivisions(), p2, and Solve().

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

Member Data Documentation

◆ cp

◆ p1

◆ p2


The documentation for this struct was generated from the following files:
impeller::ComputeQuadradicSubdivisions
Scalar ComputeQuadradicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2)
Definition: wangs_formula.cc:34
impeller::TPoint::y
Type y
Definition: point.h:31
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::QuadraticPathComponent::p1
Point p1
Definition: path_component.h:64
impeller::QuadraticPathComponent::cp
Point cp
Definition: path_component.h:66
impeller::QuadraticSolve
static Scalar QuadraticSolve(Scalar t, Scalar p0, Scalar p1, Scalar p2)
Definition: path_component.cc:79
impeller::QuadraticPathComponent::ToLinearPathComponents
void ToLinearPathComponents(Scalar scale_factor, const PointProc &proc) const
Definition: path_component.cc:179
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
impeller::QuadraticPathComponent::Solve
Point Solve(Scalar time) const
Definition: path_component.cc:147
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::QuadraticSolveDerivative
static Scalar QuadraticSolveDerivative(Scalar t, Scalar p0, Scalar p1, Scalar p2)
Definition: path_component.cc:85
impeller::QuadraticPathComponent::p2
Point p2
Definition: path_component.h:68
scale
const Scalar scale
Definition: stroke_path_geometry.cc:301