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

Member Typedef Documentation

◆ PointProc

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

Definition at line 155 of file path_component.h.

Constructor & Destructor Documentation

◆ QuadraticPathComponent() [1/2]

impeller::QuadraticPathComponent::QuadraticPathComponent ( )
inline

Definition at line 143 of file path_component.h.

143 {}

◆ QuadraticPathComponent() [2/2]

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

Member Function Documentation

◆ AppendPolylinePoints()

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

Definition at line 279 of file path_component.cc.

281  {
282  ToLinearPathComponents(scale_factor, [&points](const Point& point) {
283  points.emplace_back(point);
284  });
285 }
TPoint< Scalar > Point
Definition: point.h:327
void ToLinearPathComponents(Scalar scale_factor, const PointProc &proc) const

References ToLinearPathComponents().

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

◆ CountLinearPathComponents()

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

Definition at line 298 of file path_component.cc.

298  {
299  return std::ceilf(ComputeQuadradicSubdivisions(scale, *this)) + 2;
300 }
Scalar ComputeQuadradicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2)
const Scalar scale

References impeller::ComputeQuadradicSubdivisions(), and scale.

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

◆ Extrema()

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

Definition at line 302 of file path_component.cc.

302  {
303  CubicPathComponent elevated(*this);
304  return elevated.Extrema();
305 }

References impeller::CubicPathComponent::Extrema().

◆ GetEndDirection()

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

Definition at line 317 of file path_component.cc.

317  {
318  if (p2 != cp) {
319  return (p2 - cp).Normalize();
320  }
321  if (p2 != p1) {
322  return (p2 - p1).Normalize();
323  }
324  return std::nullopt;
325 }

References cp, p1, and p2.

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

◆ GetStartDirection()

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

Definition at line 307 of file path_component.cc.

307  {
308  if (p1 != cp) {
309  return (p1 - cp).Normalize();
310  }
311  if (p1 != p2) {
312  return (p1 - p2).Normalize();
313  }
314  return std::nullopt;
315 }

References cp, p1, and p2.

◆ operator==()

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

Definition at line 165 of file path_component.h.

165  {
166  return p1 == other.p1 && cp == other.cp && p2 == other.p2;
167  }

References cp, p1, and p2.

◆ Solve()

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

Definition at line 255 of file path_component.cc.

255  {
256  return {
257  QuadraticSolve(time, p1.x, cp.x, p2.x), // x
258  QuadraticSolve(time, p1.y, cp.y, p2.y), // y
259  };
260 }
static Scalar QuadraticSolve(Scalar t, Scalar p0, Scalar p1, Scalar p2)

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

262  {
263  return {
264  QuadraticSolveDerivative(time, p1.x, cp.x, p2.x), // x
265  QuadraticSolveDerivative(time, p1.y, cp.y, p2.y), // y
266  };
267 }
static Scalar QuadraticSolveDerivative(Scalar t, Scalar p0, Scalar p1, Scalar p2)

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

271  {
272  Scalar line_count = std::ceilf(ComputeQuadradicSubdivisions(scale, *this));
273  for (size_t i = 1; i < line_count; i += 1) {
274  writer.Write(Solve(i / line_count));
275  }
276  writer.Write(p2);
277 }
float Scalar
Definition: scalar.h:18
Point Solve(Scalar time) const

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

289  {
290  Scalar line_count =
291  std::ceilf(ComputeQuadradicSubdivisions(scale_factor, *this));
292  for (size_t i = 1; i < line_count; i += 1) {
293  proc(Solve(i / line_count));
294  }
295  proc(p2);
296 }

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: