@@ -42,10 +42,16 @@ Path& Path::AddCubicComponent(Point p1, Point cp1, Point cp2, Point p2) {
4242 return *this ;
4343}
4444
45- void Path::EnumerateComponents (
46- Applier<LinearPathComponent> linear_applier,
47- Applier<QuadraticPathComponent> quad_applier,
48- Applier<CubicPathComponent> cubic_applier) const {
45+ Path& Path::AddMoveComponent (Point destination) {
46+ moves_.emplace_back (destination);
47+ components_.emplace_back (ComponentType::kMove , moves_.size () - 1 );
48+ return *this ;
49+ }
50+
51+ void Path::EnumerateComponents (Applier<LinearPathComponent> linear_applier,
52+ Applier<QuadraticPathComponent> quad_applier,
53+ Applier<CubicPathComponent> cubic_applier,
54+ Applier<MovePathComponent> move_applier) const {
4955 size_t currentIndex = 0 ;
5056 for (const auto & component : components_) {
5157 switch (component.type ) {
@@ -64,6 +70,11 @@ void Path::EnumerateComponents(
6470 cubic_applier (currentIndex, cubics_[component.index ]);
6571 }
6672 break ;
73+ case ComponentType::kMove :
74+ if (move_applier) {
75+ move_applier (currentIndex, moves_[component.index ]);
76+ }
77+ break ;
6778 }
6879 currentIndex++;
6980 }
@@ -112,6 +123,20 @@ bool Path::GetCubicComponentAtIndex(size_t index,
112123 return true ;
113124}
114125
126+ bool Path::GetMoveComponentAtIndex (size_t index,
127+ MovePathComponent& move) const {
128+ if (index >= components_.size ()) {
129+ return false ;
130+ }
131+
132+ if (components_[index].type != ComponentType::kMove ) {
133+ return false ;
134+ }
135+
136+ move = moves_[components_[index].index ];
137+ return true ;
138+ }
139+
115140bool Path::UpdateLinearComponentAtIndex (size_t index,
116141 const LinearPathComponent& linear) {
117142 if (index >= components_.size ()) {
@@ -155,12 +180,27 @@ bool Path::UpdateCubicComponentAtIndex(size_t index,
155180 return true ;
156181}
157182
158- std::vector<Point> Path::CreatePolyline (
183+ bool Path::UpdateMoveComponentAtIndex (size_t index,
184+ const MovePathComponent& move) {
185+ if (index >= components_.size ()) {
186+ return false ;
187+ }
188+
189+ if (components_[index].type != ComponentType::kMove ) {
190+ return false ;
191+ }
192+
193+ moves_[components_[index].index ] = move;
194+ return true ;
195+ }
196+
197+ Path::Polyline Path::CreatePolyline (
159198 const SmoothingApproximation& approximation) const {
160- std::vector<Point> points;
161- auto collect_points = [&points](const std::vector<Point>& collection) {
162- points.reserve (points.size () + collection.size ());
163- points.insert (points.end (), collection.begin (), collection.end ());
199+ Polyline polyline;
200+ auto collect_points = [&polyline](const std::vector<Point>& collection) {
201+ polyline.points .reserve (polyline.points .size () + collection.size ());
202+ polyline.points .insert (polyline.points .end (), collection.begin (),
203+ collection.end ());
164204 };
165205 for (const auto & component : components_) {
166206 switch (component.type ) {
@@ -173,9 +213,12 @@ std::vector<Point> Path::CreatePolyline(
173213 case ComponentType::kCubic :
174214 collect_points (cubics_[component.index ].CreatePolyline (approximation));
175215 break ;
216+ case ComponentType::kMove :
217+ polyline.breaks .insert (polyline.points .size ());
218+ break ;
176219 }
177220 }
178- return points ;
221+ return polyline ;
179222}
180223
181224std::optional<Rect> Path::GetBoundingBox () const {
0 commit comments