| Flutter Impeller |

Public Types | Public Member Functions | Public Attributes | List of all members
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< Point > | Extrema () const
bool | operator== (const ConicPathComponent &other) const
std::optional< Vector2 > | GetStartDirection () const
std::optional< Vector2 > | GetEndDirection () 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

Definition at line 247 of file path_component.h.

248 : p1(ap1), cp(acp), p2(ap2), weight(weight, weight) {}
impeller::ConicPathComponent::cp
Point cp
Definition: path_component.h:230
impeller::ConicPathComponent::weight
Point weight
Definition: path_component.h:243
impeller::ConicPathComponent::p1
Point p1
Definition: path_component.h:228
impeller::ConicPathComponent::p2
Point p2
Definition: path_component.h:232

## 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 }
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
impeller::ConicPathComponent::ToLinearPathComponents
void ToLinearPathComponents(Scalar scale_factor, const PointProc &proc) const
Definition: path_component.cc:334

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 }
impeller::ComputeConicSubdivisions
Scalar ComputeConicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2, Scalar w)
Definition: wangs_formula.cc:48
scale
const Scalar scale
Definition: stroke_path_geometry.cc:319

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 }
impeller::ConicPathComponent::ToQuadraticPathComponents
std::array< QuadraticPathComponent, 2 > ToQuadraticPathComponents() const
Definition: path_component.cc:435

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 }
impeller::ConicSolve
static Scalar ConicSolve(Scalar t, Scalar p0, Scalar p1, Scalar p2, Scalar w)
Definition: path_component.cc:187
impeller::TPoint::y
Type y
Definition: point.h:31
impeller::TPoint::x
Type x
Definition: point.h:30

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 }
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::TPoint::IsFinite
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 }
impeller::ConicPathComponent::Solve
Point Solve(Scalar time) const
Definition: path_component.cc:327

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;
437 SubdivideToQuadraticPoints(points);
438
439 return {
440 QuadraticPathComponent(points[0], points[1], points[2]),
441 QuadraticPathComponent(points[2], points[3], points[4]),
442 };
443 }
impeller::ConicPathComponent::SubdivideToQuadraticPoints
void SubdivideToQuadraticPoints(std::array< Point, 5 > &points) const
Definition: path_component.cc:395

References SubdivideToQuadraticPoints().

Referenced by Extrema().

## Member Data Documentation

## ◆ cp

Point impeller::ConicPathComponent::cp

Definition at line 230 of file path_component.h.

Referenced by impeller::ComputeConicSubdivisions(), GetEndDirection(), GetStartDirection(), operator==(), Solve(), SubdivideToQuadraticPoints(), and impeller::testing::TEST().

## ◆ p1

Point impeller::ConicPathComponent::p1

Definition at line 228 of file path_component.h.

Referenced by impeller::ComputeConicSubdivisions(), GetEndDirection(), GetStartDirection(), operator==(), impeller::PathBuilder::Shift(), Solve(), SubdivideToQuadraticPoints(), impeller::testing::TEST(), impeller::testing::TEST_P(), and impeller::Path::WritePolyline().

## ◆ p2

Point impeller::ConicPathComponent::p2

Definition at line 232 of file path_component.h.

Referenced by impeller::ComputeConicSubdivisions(), GetEndDirection(), GetStartDirection(), operator==(), Solve(), SubdivideToQuadraticPoints(), impeller::testing::TEST(), impeller::testing::TEST_P(), and ToLinearPathComponents().

## ◆ weight

Point impeller::ConicPathComponent::weight

Definition at line 243 of file path_component.h.

Referenced by impeller::ComputeConicSubdivisions(), operator==(), Solve(), SubdivideToQuadraticPoints(), and impeller::testing::TEST().

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

- impeller/geometry/path_component.h
- impeller/geometry/path_component.cc