| Flutter Impeller |

Public Member Functions | Static Public Attributes | List of all members
impeller::PathBuilder Class Reference

`#include <path_builder.h>`

## Public Member Functions
| PathBuilder ()
| ~PathBuilder ()
Path | CopyPath (FillType fill=FillType::kNonZero)
Path | TakePath (FillType fill=FillType::kNonZero)
void | Reserve (size_t point_size, size_t verb_size)
| Reserve [point_size] points and [verb_size] verbs in the underlying path buffer. More...
PathBuilder & | SetConvexity (Convexity value)
PathBuilder & | MoveTo (Point point, bool relative=false)
PathBuilder & | Close ()
PathBuilder & | LineTo (Point point, bool relative=false)
| Insert a line from the current position to `point`. More...
PathBuilder & | HorizontalLineTo (Scalar x, bool relative=false)
PathBuilder & | VerticalLineTo (Scalar y, bool relative=false)
PathBuilder & | QuadraticCurveTo (Point controlPoint, Point point, bool relative=false)
| Insert a quadradic curve from the current position to `point` using the control point `controlPoint`. More...
PathBuilder & | ConicCurveTo (Point controlPoint, Point point, Scalar weight, bool relative=false)
| Insert a conic curve from the current position to `point` using the control point `controlPoint` and the weight `weight`. More...
PathBuilder & | CubicCurveTo (Point controlPoint1, Point controlPoint2, Point point, bool relative=false)
| Insert a cubic curve from the curren position to `point` using the control points `controlPoint1` and `controlPoint2`. More...
PathBuilder & | AddRect (const Rect &rect)
PathBuilder & | AddCircle (const Point &center, Scalar radius)
PathBuilder & | AddArc (const Rect &oval_bounds, Radians start, Radians sweep, bool use_center=false)
PathBuilder & | AddOval (const Rect &rect)
PathBuilder & | AddLine (const Point &p1, const Point &p2)
| Move to point `p1`, then insert a line from `p1` to `p2`. More...
PathBuilder & | AddQuadraticCurve (const Point &p1, const Point &cp, const Point &p2)
| Move to point `p1`, then insert a quadradic curve from `p1` to `p2` with the control point `cp`. More...
PathBuilder & | AddConicCurve (const Point &p1, const Point &cp, const Point &p2, Scalar weight)
| Move to point `p1`, then insert a conic curve from `p1` to `p2` with the control point `cp` and weight `weight`. More...
PathBuilder & | AddCubicCurve (const Point &p1, const Point &cp1, const Point &cp2, const Point &p2)
| Move to point `p1`, then insert a cubic curve from `p1` to `p2` with control points `cp1` and `cp2`. More...
PathBuilder & | Shift (Point offset)
| Transform the existing path segments and contours by the given `offset`. More...
PathBuilder & | SetBounds (Rect bounds)
| Set the bounding box that will be used by `Path.GetBoundingBox` in place of performing the computation. More...
PathBuilder & | AddRoundRect (RoundRect rect)
PathBuilder & | AddRoundSuperellipse (RoundSuperellipse rse)
PathBuilder & | AddPath (const Path &path)

## Static Public Attributes
constexpr static const Scalar | kArcApproximationMagic = 0.551915024494f

## Detailed Description

Definition at line 16 of file path_builder.h.

## Constructor & Destructor Documentation

## ◆ PathBuilder()

impeller::PathBuilder::PathBuilder | ( |  | ) |

Definition at line 15 of file path_builder.cc.

15 {
16 AddContourComponent({});
17 }

## ◆ ~PathBuilder()

impeller::PathBuilder::~PathBuilder | ( |  | ) |
| default

## Member Function Documentation

## ◆ AddArc()

PathBuilder & impeller::PathBuilder::AddArc | ( | const Rect & | oval_bounds,
|  | Radians | start,
|  | Radians | sweep,
|  | bool | use_center = `false`
| ) |  |

Definition at line 397 of file path_builder.cc.

400 {
401 if (sweep.radians < 0) {
402 start.radians += sweep.radians;
403 sweep.radians *= -1;
404 }
405 sweep.radians = std::min(k2Pi, sweep.radians);
406 start.radians = std::fmod(start.radians, k2Pi);
407
408 const Point center = oval_bounds.GetCenter();
409 const Point radius = center - oval_bounds.GetOrigin();
410
411 Vector2 p1_unit(std::cos(start.radians), std::sin(start.radians));
412
413 if (use_center) {
414 MoveTo(center);
415 LineTo(center + p1_unit * radius);
416 } else {
417 MoveTo(center + p1_unit * radius);
418 }
419
420 while (sweep.radians > 0) {
421 Vector2 p2_unit;
422 Scalar quadrant_angle;
423 if (sweep.radians < kPiOver2) {
424 quadrant_angle = sweep.radians;
425 p2_unit = Vector2(std::cos(start.radians + quadrant_angle),
426 std::sin(start.radians + quadrant_angle));
427 } else {
428 quadrant_angle = kPiOver2;
429 p2_unit = Vector2(-p1_unit.y, p1_unit.x);
430 }
431
432 Vector2 arc_cp_lengths =
433 (quadrant_angle / kPiOver2) * kArcApproximationMagic * radius;
434
435 Point p1 = center + p1_unit * radius;
436 Point p2 = center + p2_unit * radius;
437 Point cp1 = p1 + Vector2(-p1_unit.y, p1_unit.x) * arc_cp_lengths;
438 Point cp2 = p2 + Vector2(p2_unit.y, -p2_unit.x) * arc_cp_lengths;
439
440 AddCubicComponent(p1, cp1, cp2, p2);
441 current_ = p2;
442
443 start.radians += quadrant_angle;
444 sweep.radians -= quadrant_angle;
445 p1_unit = p2_unit;
446 }
447
448 if (use_center) {
449 Close();
450 }
451
452 return *this;
453 }
impeller::PathBuilder::LineTo
PathBuilder & LineTo(Point point, bool relative=false)
Insert a line from the current position to point.
Definition: path_builder.cc:66
impeller::PathBuilder::MoveTo
PathBuilder & MoveTo(Point point, bool relative=false)
Definition: path_builder.cc:47
impeller::PathBuilder::Close
PathBuilder & Close()
Definition: path_builder.cc:54
impeller::PathBuilder::kArcApproximationMagic
constexpr static const Scalar kArcApproximationMagic
Definition: path_builder.h:25
impeller::k2Pi
constexpr float k2Pi
Definition: constants.h:29
impeller::Vector2
Point Vector2
Definition: point.h:331
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
impeller::kPiOver2
constexpr float kPiOver2
Definition: constants.h:32

References Close(), impeller::TRect< T >::GetCenter(), impeller::TRect< T >::GetOrigin(), impeller::k2Pi, kArcApproximationMagic, impeller::kPiOver2, LineTo(), MoveTo(), impeller::Radians::radians, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by impeller::DlDispatcherBase::drawArc(), and impeller::testing::TEST().

## ◆ AddCircle()

PathBuilder & impeller::PathBuilder::AddCircle | ( | const Point & | center,
|  | Scalar | radius
| ) |  |

Definition at line 171 of file path_builder.cc.

171 {
172 return AddOval(Rect::MakeXYWH(c.x - r, c.y - r, 2.0f * r, 2.0f * r));
173 }
impeller::PathBuilder::AddOval
PathBuilder & AddOval(const Rect &rect)
Definition: path_builder.cc:455
impeller::TRect< Scalar >::MakeXYWH
constexpr static TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition: rect.h:136

References AddOval(), impeller::TRect< Scalar >::MakeXYWH(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by impeller::testing::TEST().

## ◆ AddConicCurve()

PathBuilder & impeller::PathBuilder::AddConicCurve | ( | const Point & | p1,
|  | const Point & | cp,
|  | const Point & | p2,
|  | Scalar | weight
| ) |  |

Move to point `p1`, then insert a conic curve from `p1` to `p2` with the control point `cp` and weight `weight`.

Definition at line 135 of file path_builder.cc.

138 {
139 MoveTo(p1);
140 AddConicComponent(p1, cp, p2, weight);
141 return *this;
142 }

References MoveTo().

Referenced by impeller::testing::TEST().

## ◆ AddCubicCurve()

PathBuilder & impeller::PathBuilder::AddCubicCurve | ( | const Point & | p1,
|  | const Point & | cp1,
|  | const Point & | cp2,
|  | const Point & | p2
| ) |  |

Move to point `p1`, then insert a cubic curve from `p1` to `p2` with control points `cp1` and `cp2`.

Definition at line 144 of file path_builder.cc.

147 {
148 MoveTo(p1);
149 AddCubicComponent(p1, cp1, cp2, p2);
150 return *this;
151 }

References MoveTo().

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

## ◆ AddLine()

PathBuilder & impeller::PathBuilder::AddLine | ( | const Point & | p1,
|  | const Point & | p2
| ) |  |

Move to point `p1`, then insert a line from `p1` to `p2`.

Definition at line 503 of file path_builder.cc.

503 {
504 MoveTo(p1);
505 AddLinearComponent(p1, p2);
506 return *this;
507 }

References MoveTo().

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

## ◆ AddOval()

PathBuilder & impeller::PathBuilder::AddOval | ( | const Rect & | rect | ) |

Definition at line 455 of file path_builder.cc.

455 {
456 const Point c = container.GetCenter();
457 const Point r = c - container.GetOrigin();
458 const Point m = r * kArcApproximationMagic;
459
460 MoveTo({c.x, c.y - r.y});
461
462 //----------------------------------------------------------------------------
463 // Top right arc.
464 //
465 AddCubicComponent({c.x, c.y - r.y}, // p1
466 {c.x + m.x, c.y - r.y}, // cp1
467 {c.x + r.x, c.y - m.y}, // cp2
468 {c.x + r.x, c.y} // p2
469 );
470
471 //----------------------------------------------------------------------------
472 // Bottom right arc.
473 //
474 AddCubicComponent({c.x + r.x, c.y}, // p1
475 {c.x + r.x, c.y + m.y}, // cp1
476 {c.x + m.x, c.y + r.y}, // cp2
477 {c.x, c.y + r.y} // p2
478 );
479
480 //----------------------------------------------------------------------------
481 // Bottom left arc.
482 //
483 AddCubicComponent({c.x, c.y + r.y}, // p1
484 {c.x - m.x, c.y + r.y}, // cp1
485 {c.x - r.x, c.y + m.y}, // cp2
486 {c.x - r.x, c.y} // p2
487 );
488
489 //----------------------------------------------------------------------------
490 // Top left arc.
491 //
492 AddCubicComponent({c.x - r.x, c.y}, // p1
493 {c.x - r.x, c.y - m.y}, // cp1
494 {c.x - m.x, c.y - r.y}, // cp2
495 {c.x, c.y - r.y} // p2
496 );
497
498 Close();
499
500 return *this;
501 }

References Close(), impeller::TRect< T >::GetCenter(), impeller::TRect< T >::GetOrigin(), kArcApproximationMagic, MoveTo(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by AddCircle(), AddRoundSuperellipse(), impeller::Canvas::DrawOval(), and impeller::testing::TEST().

## ◆ AddPath()

PathBuilder & impeller::PathBuilder::AddPath | ( | const Path & | path | ) |

Definition at line 509 of file path_builder.cc.

509 {
510 auto& points = prototype_.points;
511 auto& components = prototype_.components;
512 size_t source_offset = points.size();
513
514 points.insert(points.end(), path.data_->points.begin(),
515 path.data_->points.end());
516 components.insert(components.end(), path.data_->components.begin(),
517 path.data_->components.end());
518
519 for (auto component : path.data_->components) {
520 if (component == Path::ComponentType::kContour) {
521 current_contour_location_ = source_offset;
522 contour_count_ += 1;
523 }
524 source_offset += Path::VerbToOffset(component);
525 }
526 return *this;
527 }
impeller::Path::ComponentType::kContour
@ kContour
impeller::Path::VerbToOffset
static constexpr size_t VerbToOffset(Path::ComponentType verb)
Definition: path.h:95

References impeller::Path::kContour, and impeller::Path::VerbToOffset().

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

## ◆ AddQuadraticCurve()

PathBuilder & impeller::PathBuilder::AddQuadraticCurve | ( | const Point & | p1,
|  | const Point & | cp,
|  | const Point & | p2
| ) |  |

Move to point `p1`, then insert a quadradic curve from `p1` to `p2` with the control point `cp`.

Definition at line 127 of file path_builder.cc.

129 {
130 MoveTo(p1);
131 AddQuadraticComponent(p1, cp, p2);
132 return *this;
133 }

References MoveTo().

Referenced by impeller::testing::TEST().

## ◆ AddRect()

PathBuilder & impeller::PathBuilder::AddRect | ( | const Rect & | rect | ) |

Definition at line 153 of file path_builder.cc.

153 {
154 auto origin = rect.GetOrigin();
155 auto size = rect.GetSize();
156
157 auto tl = origin;
158 auto bl = origin + Point{0.0, size.height};
159 auto br = origin + size;
160 auto tr = origin + Point{size.width, 0.0};
161
162 MoveTo(tl);
163 LineTo(tr);
164 LineTo(br);
165 LineTo(bl);
166 Close();
167
168 return *this;
169 }

References Close(), impeller::TRect< T >::GetOrigin(), impeller::TRect< T >::GetSize(), LineTo(), and MoveTo().

Referenced by AddRoundRect(), AddRoundSuperellipse(), impeller::Canvas::DrawRect(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ AddRoundRect()

PathBuilder & impeller::PathBuilder::AddRoundRect | ( | RoundRect | rect | ) |

Definition at line 175 of file path_builder.cc.

175 {
176 auto rect = round_rect.GetBounds();
177 auto radii = round_rect.GetRadii();
178 if (radii.AreAllCornersEmpty()) {
179 return AddRect(rect);
180 }
181
182 auto rect_origin = rect.GetOrigin();
183 auto rect_size = rect.GetSize();
184
185 current_ = rect_origin + Point{radii.top_left.width, 0.0};
186
187 MoveTo({rect_origin.x + radii.top_left.width, rect_origin.y});
188
189 //----------------------------------------------------------------------------
190 // Top line.
191 //
192 AddLinearComponentIfNeeded(
193 {rect_origin.x + radii.top_left.width, rect_origin.y},
194 {rect_origin.x + rect_size.width - radii.top_right.width, rect_origin.y});
195
196 //----------------------------------------------------------------------------
197 // Top right arc.
198 //
199 AddRoundedRectTopRight(rect, radii);
200
201 //----------------------------------------------------------------------------
202 // Right line.
203 //
204 AddLinearComponentIfNeeded(
205 {rect_origin.x + rect_size.width, rect_origin.y + radii.top_right.height},
206 {rect_origin.x + rect_size.width,
207 rect_origin.y + rect_size.height - radii.bottom_right.height});
208
209 //----------------------------------------------------------------------------
210 // Bottom right arc.
211 //
212 AddRoundedRectBottomRight(rect, radii);
213
214 //----------------------------------------------------------------------------
215 // Bottom line.
216 //
217 AddLinearComponentIfNeeded(
218 {rect_origin.x + rect_size.width - radii.bottom_right.width,
219 rect_origin.y + rect_size.height},
220 {rect_origin.x + radii.bottom_left.width,
221 rect_origin.y + rect_size.height});
222
223 //----------------------------------------------------------------------------
224 // Bottom left arc.
225 //
226 AddRoundedRectBottomLeft(rect, radii);
227
228 //----------------------------------------------------------------------------
229 // Left line.
230 //
231 AddLinearComponentIfNeeded(
232 {rect_origin.x,
233 rect_origin.y + rect_size.height - radii.bottom_left.height},
234 {rect_origin.x, rect_origin.y + radii.top_left.height});
235
236 //----------------------------------------------------------------------------
237 // Top left arc.
238 //
239 AddRoundedRectTopLeft(rect, radii);
240
241 Close();
242
243 return *this;
244 }
impeller::PathBuilder::AddRect
PathBuilder & AddRect(const Rect &rect)
Definition: path_builder.cc:153

References AddRect(), Close(), impeller::RoundRect::GetBounds(), impeller::RoundRect::GetRadii(), and MoveTo().

Referenced by impeller::DlDispatcherBase::clipRoundRect(), impeller::DlDispatcherBase::drawDiffRoundRect(), impeller::Canvas::DrawRoundRect(), and impeller::testing::TEST().

## ◆ AddRoundSuperellipse()

PathBuilder & impeller::PathBuilder::AddRoundSuperellipse | ( | RoundSuperellipse | rse | ) |

Definition at line 246 of file path_builder.cc.

246 {
247 if (rse.IsRect()) {
248 AddRect(rse.GetBounds());
249 } else if (rse.IsOval()) {
250 AddOval(rse.GetBounds());
251 } else {
252 impeller::RoundSuperellipseParam::MakeBoundsRadii(rse.GetBounds(),
253 rse.GetRadii())
254 .AddToPath(*this);
255 }
256 return *this;
257 }
impeller::RoundSuperellipseParam::MakeBoundsRadii
static RoundSuperellipseParam MakeBoundsRadii(const Rect &bounds, const RoundingRadii &radii)
Definition: round_superellipse_param.cc:463
impeller::RoundSuperellipseParam::AddToPath
void AddToPath(PathBuilder &path) const
Definition: round_superellipse_param.cc:499

References AddOval(), AddRect(), impeller::RoundSuperellipseParam::AddToPath(), impeller::RoundSuperellipse::GetBounds(), impeller::RoundSuperellipse::GetRadii(), impeller::RoundSuperellipse::IsOval(), impeller::RoundSuperellipse::IsRect(), and impeller::RoundSuperellipseParam::MakeBoundsRadii().

Referenced by impeller::Canvas::DrawRoundSuperellipse(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ Close()

PathBuilder & impeller::PathBuilder::Close | ( |  | ) |

Definition at line 54 of file path_builder.cc.

54 {
55 // If the subpath start is the same as the current position, this
56 // is an empty contour and inserting a line segment will just
57 // confuse the tessellator.
58 if (subpath_start_ != current_) {
59 LineTo(subpath_start_);
60 }
61 SetContourClosed(true);
62 AddContourComponent(current_);
63 return *this;
64 }

References LineTo().

Referenced by AddArc(), AddOval(), AddRect(), AddRoundRect(), impeller::RoundSuperellipseParam::AddToPath(), impeller::Close(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ ConicCurveTo()

PathBuilder & impeller::PathBuilder::ConicCurveTo | ( | Point | controlPoint,
|  | Point | point,
|  | Scalar | weight,
|  | bool | relative = `false`
| ) |  |

Insert a conic curve from the current position to `point` using the control point `controlPoint` and the weight `weight`.

If `relative` is true the `point` and `controlPoint` are relative to current location.

Definition at line 99 of file path_builder.cc.

102 {
103 point = relative ? current_ + point : point;
104 controlPoint = relative ? current_ + controlPoint : controlPoint;
105 AddConicComponent(current_, controlPoint, point, weight);
106 current_ = point;
107 return *this;
108 }

Referenced by impeller::testing::TEST().

## ◆ CopyPath()

Path impeller::PathBuilder::CopyPath | ( | FillType | fill = `FillType::kNonZero` | ) |

Definition at line 21 of file path_builder.cc.

21 {
22 prototype_.fill = fill;
23 prototype_.single_contour =
24 current_contour_location_ == 0u ||
25 (contour_count_ == 2 &&
26 prototype_.components.back() == Path::ComponentType::kContour);
27 return Path(prototype_);
28 }

References impeller::Path::kContour.

Referenced by impeller::Tessellate(), and impeller::testing::TEST().

## ◆ CubicCurveTo()

PathBuilder & impeller::PathBuilder::CubicCurveTo | ( | Point | controlPoint1,
|  | Point | controlPoint2,
|  | Point | point,
|  | bool | relative = `false`
| ) |  |

Insert a cubic curve from the curren position to `point` using the control points `controlPoint1` and `controlPoint2`.

If `relative` is true the `point`, `controlPoint1`, and `controlPoint2` are relative to current location.

Definition at line 115 of file path_builder.cc.

118 {
119 controlPoint1 = relative ? current_ + controlPoint1 : controlPoint1;
120 controlPoint2 = relative ? current_ + controlPoint2 : controlPoint2;
121 point = relative ? current_ + point : point;
122 AddCubicComponent(current_, controlPoint1, controlPoint2, point);
123 current_ = point;
124 return *this;
125 }

Referenced by impeller::CubicTo(), and impeller::testing::TEST().

## ◆ HorizontalLineTo()

PathBuilder & impeller::PathBuilder::HorizontalLineTo | ( | Scalar | x,
|  | bool | relative = `false`
| ) |  |

Definition at line 73 of file path_builder.cc.

73 {
74 Point endpoint =
75 relative ? Point{current_.x + x, current_.y} : Point{x, current_.y};
76 AddLinearComponent(current_, endpoint);
77 current_ = endpoint;
78 return *this;
79 }
x
int32_t x
Definition: dl_golden_unittests.cc:458
impeller::TPoint::y
Type y
Definition: point.h:31
impeller::TPoint::x
Type x
Definition: point.h:30

References x, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by impeller::testing::TEST().

## ◆ LineTo()

PathBuilder & impeller::PathBuilder::LineTo | ( | Point | point,
|  | bool | relative = `false`
| ) |  |

Insert a line from the current position to `point`.

If `relative` is true, then `point` is relative to the current location.

Definition at line 66 of file path_builder.cc.

66 {
67 point = relative ? current_ + point : point;
68 AddLinearComponent(current_, point);
69 current_ = point;
70 return *this;
71 }

Referenced by AddArc(), AddRect(), impeller::RoundSuperellipseParam::AddToPath(), Close(), impeller::DlDispatcherBase::drawDashedLine(), impeller::LineTo(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ MoveTo()

PathBuilder & impeller::PathBuilder::MoveTo | ( | Point | point,
|  | bool | relative = `false`
| ) |  |

Definition at line 47 of file path_builder.cc.

47 {
48 current_ = relative ? current_ + point : point;
49 subpath_start_ = current_;
50 AddContourComponent(current_);
51 return *this;
52 }

Referenced by AddArc(), AddConicCurve(), AddCubicCurve(), AddLine(), AddOval(), AddQuadraticCurve(), AddRect(), AddRoundRect(), impeller::RoundSuperellipseParam::AddToPath(), impeller::DlDispatcherBase::drawDashedLine(), impeller::MoveTo(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ QuadraticCurveTo()

PathBuilder & impeller::PathBuilder::QuadraticCurveTo | ( | Point | controlPoint,
|  | Point | point,
|  | bool | relative = `false`
| ) |  |

Insert a quadradic curve from the current position to `point` using the control point `controlPoint`.

If `relative` is true the `point` and `controlPoint` are relative to current location.

Definition at line 89 of file path_builder.cc.

91 {
92 point = relative ? current_ + point : point;
93 controlPoint = relative ? current_ + controlPoint : controlPoint;
94 AddQuadraticComponent(current_, controlPoint, point);
95 current_ = point;
96 return *this;
97 }

Referenced by impeller::testing::TEST().

## ◆ Reserve()

void impeller::PathBuilder::Reserve | ( | size_t | point_size,
|  | size_t | verb_size
| ) |  |

Reserve [point_size] points and [verb_size] verbs in the underlying path buffer.

Definition at line 42 of file path_builder.cc.

42 {
43 prototype_.points.reserve(point_size);
44 prototype_.components.reserve(verb_size);
45 }

## ◆ SetBounds()

PathBuilder & impeller::PathBuilder::SetBounds | ( | Rect | bounds | ) |

Set the bounding box that will be used by `Path.GetBoundingBox` in place of performing the computation.

       When Impeller recieves Skia Path objects, many of these already
       have computed bounds. This method is used to avoid needlessly
       recomputing these bounds.

Definition at line 576 of file path_builder.cc.

576 {
577 prototype_.bounds = bounds;
578 return *this;
579 }

Referenced by impeller::DlDispatcherBase::drawDiffRoundRect(), impeller::Canvas::DrawRoundRect(), impeller::Canvas::DrawRoundSuperellipse(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ SetConvexity()

PathBuilder & impeller::PathBuilder::SetConvexity | ( | Convexity | value | ) |

Definition at line 110 of file path_builder.cc.

110 {
111 prototype_.convexity = value;
112 return *this;
113 }
value
int32_t value
Definition: dl_golden_unittests.cc:459

References value.

Referenced by impeller::Canvas::DrawRoundRect(), impeller::Canvas::DrawRoundSuperellipse(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ Shift()

PathBuilder & impeller::PathBuilder::Shift | ( | Point | offset | ) |

Transform the existing path segments and contours by the given `offset`.

Definition at line 529 of file path_builder.cc.

529 {
530 auto& points = prototype_.points;
531 size_t storage_offset = 0u;
532 for (const auto& component : prototype_.components) {
533 switch (component) {
534 case Path::ComponentType::kLinear: {
535 auto* linear =
536 reinterpret_cast<LinearPathComponent*>(&points[storage_offset]);
537 linear->p1 += offset;
538 linear->p2 += offset;
539 break;
540 }
541 case Path::ComponentType::kQuadratic: {
542 auto* quad =
543 reinterpret_cast<QuadraticPathComponent*>(&points[storage_offset]);
544 quad->p1 += offset;
545 quad->p2 += offset;
546 quad->cp += offset;
547 } break;
548 case Path::ComponentType::kConic: {
549 auto* conic =
550 reinterpret_cast<ConicPathComponent*>(&points[storage_offset]);
551 conic->p1 += offset;
552 conic->p2 += offset;
553 conic->cp += offset;
554 } break;
555 case Path::ComponentType::kCubic: {
556 auto* cubic =
557 reinterpret_cast<CubicPathComponent*>(&points[storage_offset]);
558 cubic->p1 += offset;
559 cubic->p2 += offset;
560 cubic->cp1 += offset;
561 cubic->cp2 += offset;
562 } break;
563 case Path::ComponentType::kContour:
564 auto* contour =
565 reinterpret_cast<ContourComponent*>(&points[storage_offset]);
566 contour->destination += offset;
567 break;
568 }
569 storage_offset += Path::VerbToOffset(component);
570 }
571
572 prototype_.bounds.reset();
573 return *this;
574 }
impeller::Path::ComponentType::kCubic
@ kCubic
impeller::Path::ComponentType::kLinear
@ kLinear
impeller::Path::ComponentType::kConic
@ kConic
impeller::Path::ComponentType::kQuadratic
@ kQuadratic
offset
SeparatedVector2 offset
Definition: stroke_path_geometry.cc:322

References impeller::ContourComponent::destination, impeller::Path::kConic, impeller::Path::kContour, impeller::Path::kCubic, impeller::Path::kLinear, impeller::Path::kQuadratic, offset, impeller::LinearPathComponent::p1, impeller::QuadraticPathComponent::p1, impeller::ConicPathComponent::p1, impeller::CubicPathComponent::p1, and impeller::Path::VerbToOffset().

Referenced by impeller::testing::TEST().

## ◆ TakePath()

Path impeller::PathBuilder::TakePath | ( | FillType | fill = `FillType::kNonZero` | ) |

Definition at line 30 of file path_builder.cc.

30 {
31 prototype_.fill = fill;
32 UpdateBounds();
33 prototype_.single_contour =
34 current_contour_location_ == 0u ||
35 (contour_count_ == 2 &&
36 prototype_.components.back() == Path::ComponentType::kContour);
37 current_contour_location_ = 0u;
38 contour_count_ = 1;
39 return Path(std::move(prototype_));
40 }

References impeller::Path::kContour.

Referenced by impeller::DlDispatcherBase::drawArc(), impeller::DlDispatcherBase::drawDashedLine(), impeller::DlDispatcherBase::drawDiffRoundRect(), impeller::Canvas::DrawRoundRect(), impeller::Canvas::DrawRoundSuperellipse(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ VerticalLineTo()

PathBuilder & impeller::PathBuilder::VerticalLineTo | ( | Scalar | y,
|  | bool | relative = `false`
| ) |  |

Definition at line 81 of file path_builder.cc.

81 {
82 Point endpoint =
83 relative ? Point{current_.x, current_.y + y} : Point{current_.x, y};
84 AddLinearComponent(current_, endpoint);
85 current_ = endpoint;
86 return *this;
87 }

References impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by impeller::testing::TEST().

## Member Data Documentation

## ◆ kArcApproximationMagic

constexpr static const Scalar impeller::PathBuilder::kArcApproximationMagic = 0.551915024494f
| static constexpr

Used for approximating quarter circle arcs with cubic curves. This is the control point distance which results in the smallest possible unit circle integration for a right angle arc. It can be used to approximate arcs less than 90 degrees to great effect by simply reducing it proportionally to the angle. However, accuracy rapidly diminishes if magnified for obtuse angle arcs, and so multiple cubic curves should be used when approximating arcs greater than 90 degrees.

Definition at line 25 of file path_builder.h.

Referenced by AddArc(), AddOval(), and flutter::testing::TEST_P().

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

- impeller/geometry/path_builder.h
- impeller/geometry/path_builder.cc