Flutter Impeller
impeller::ConicPathComponent Struct Reference

#include <path_component.h>

Public Types

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

Public Member Functions

 ConicPathComponent ()
 
 ConicPathComponent (Point ap1, Point acp, Point ap2, Scalar weight)
 
Point Solve (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 ConicPathComponent &other) const
 
std::optional< Vector2GetStartDirection () const
 
std::optional< Vector2GetEndDirection () const
 
std::array< QuadraticPathComponent, 2 > ToQuadraticPathComponents () const
 
void SubdivideToQuadraticPoints (std::array< Point, 5 > &points) const
 

Public Attributes

Point p1
 
Point cp
 
Point p2
 
Point weight
 

Detailed Description

Definition at line 226 of file path_component.h.

Member Typedef Documentation

◆ PointProc

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

Definition at line 255 of file path_component.h.

Constructor & Destructor Documentation

◆ ConicPathComponent() [1/2]

impeller::ConicPathComponent::ConicPathComponent ( )
inline

Definition at line 245 of file path_component.h.

245 {}

◆ ConicPathComponent() [2/2]

impeller::ConicPathComponent::ConicPathComponent ( Point  ap1,
Point  acp,
Point  ap2,
Scalar  weight 
)
inline

Member Function Documentation

◆ AppendPolylinePoints()

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

Definition at line 343 of file path_component.cc.

345  {
346  ToLinearPathComponents(scale_factor, [&points](const Point& point) {
347  if (point != points.back()) {
348  points.emplace_back(point);
349  }
350  });
351 }
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::ConicPathComponent::CountLinearPathComponents ( Scalar  scale) const

Definition at line 362 of file path_component.cc.

362  {
363  return std::ceilf(ComputeConicSubdivisions(scale, *this)) + 2;
364 }
Scalar ComputeConicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2, Scalar w)
const Scalar scale

References impeller::ComputeConicSubdivisions(), and scale.

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

◆ Extrema()

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

Definition at line 366 of file path_component.cc.

366  {
367  std::vector<Point> points;
368  for (auto quad : ToQuadraticPathComponents()) {
369  auto quad_extrema = quad.Extrema();
370  points.insert(points.end(), quad_extrema.begin(), quad_extrema.end());
371  }
372  return points;
373 }
std::array< QuadraticPathComponent, 2 > ToQuadraticPathComponents() const

References ToQuadraticPathComponents().

◆ GetEndDirection()

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

Definition at line 385 of file path_component.cc.

385  {
386  if (p2 != cp) {
387  return (p2 - cp).Normalize();
388  }
389  if (p2 != p1) {
390  return (p2 - p1).Normalize();
391  }
392  return std::nullopt;
393 }

References cp, p1, and p2.

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

◆ GetStartDirection()

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

Definition at line 375 of file path_component.cc.

375  {
376  if (p1 != cp) {
377  return (p1 - cp).Normalize();
378  }
379  if (p1 != p2) {
380  return (p1 - p2).Normalize();
381  }
382  return std::nullopt;
383 }

References cp, p1, and p2.

◆ operator==()

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

Definition at line 265 of file path_component.h.

265  {
266  return p1 == other.p1 && cp == other.cp && p2 == other.p2 &&
267  weight == other.weight;
268  }

References cp, p1, p2, and weight.

◆ Solve()

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

Definition at line 327 of file path_component.cc.

327  {
328  return {
329  ConicSolve(time, p1.x, cp.x, p2.x, weight.x), // x
330  ConicSolve(time, p1.y, cp.y, p2.y, weight.y), // y
331  };
332 }
static Scalar ConicSolve(Scalar t, Scalar p0, Scalar p1, Scalar p2, Scalar w)

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

Referenced by impeller::testing::TEST_P(), and ToLinearPathComponents().

◆ SubdivideToQuadraticPoints()

void impeller::ConicPathComponent::SubdivideToQuadraticPoints ( std::array< Point, 5 > &  points) const

Definition at line 395 of file path_component.cc.

396  {
397  FML_DCHECK(weight.IsFinite() && weight.x > 0 && weight.y > 0);
398 
399  // Observe that scale will always be smaller than 1 because weight > 0.
400  const Scalar scale = 1.0f / (1.0f + weight.x);
401 
402  // The subdivided control points below are the sums of the following three
403  // terms. Because the terms are multiplied by something <1, and the resulting
404  // control points lie within the control points of the original then the
405  // terms and the sums below will not overflow. Note that weight * scale
406  // approaches 1 as weight becomes very large.
407  Point tp1 = p1 * scale;
408  Point tcp = cp * (weight.x * scale);
409  Point tp2 = p2 * scale;
410 
411  // Calculate the subdivided control points
412  Point sub_cp1 = tp1 + tcp;
413  Point sub_cp2 = tcp + tp2;
414 
415  // The middle point shared by the 2 sub-divisions, the interpolation of
416  // the original curve at its halfway point.
417  Point sub_mid = (tp1 + tcp + tcp + tp2) * 0.5f;
418 
419  FML_DCHECK(sub_cp1.IsFinite() && sub_mid.IsFinite() && sub_cp2.IsFinite());
420 
421  points[0] = p1;
422  points[1] = sub_cp1;
423  points[2] = sub_mid;
424  points[3] = sub_cp2;
425  points[4] = p2;
426 
427  // Update w.
428  // Currently this method only subdivides a single time directly to 2
429  // quadratics, but if we eventually want to keep the weights for further
430  // subdivision, this was the code that did it in Skia:
431  // sub_w1 = sub_w2 = SkScalarSqrt(SK_ScalarHalf + w * SK_ScalarHalf)
432 }
float Scalar
Definition: scalar.h:18
IsFinite() const
Definition: point.h:243

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

Referenced by ToQuadraticPathComponents().

◆ ToLinearPathComponents() [1/2]

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

Definition at line 353 of file path_component.cc.

354  {
355  Scalar line_count = std::ceilf(ComputeConicSubdivisions(scale, *this));
356  for (size_t i = 1; i < line_count; i += 1) {
357  writer.Write(Solve(i / line_count));
358  }
359  writer.Write(p2);
360 }
Point Solve(Scalar time) const

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

◆ ToLinearPathComponents() [2/2]

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

Definition at line 334 of file path_component.cc.

335  {
336  Scalar line_count = std::ceilf(ComputeConicSubdivisions(scale_factor, *this));
337  for (size_t i = 1; i < line_count; i += 1) {
338  proc(Solve(i / line_count));
339  }
340  proc(p2);
341 }

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

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

◆ ToQuadraticPathComponents()

std::array< QuadraticPathComponent, 2 > impeller::ConicPathComponent::ToQuadraticPathComponents ( ) const

Definition at line 435 of file path_component.cc.

435  {
436  std::array<Point, 5> points;
438 
439  return {
440  QuadraticPathComponent(points[0], points[1], points[2]),
441  QuadraticPathComponent(points[2], points[3], points[4]),
442  };
443 }
void SubdivideToQuadraticPoints(std::array< Point, 5 > &points) const

References SubdivideToQuadraticPoints().

Referenced by Extrema().

Member Data Documentation

◆ cp

◆ p1

◆ p2

◆ weight

Point impeller::ConicPathComponent::weight

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