@@ -42,10 +42,16 @@ Path& Path::AddCubicComponent(Point p1, Point cp1, Point cp2, Point p2) {
42
42
return *this ;
43
43
}
44
44
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 {
49
55
size_t currentIndex = 0 ;
50
56
for (const auto & component : components_) {
51
57
switch (component.type ) {
@@ -64,6 +70,11 @@ void Path::EnumerateComponents(
64
70
cubic_applier (currentIndex, cubics_[component.index ]);
65
71
}
66
72
break ;
73
+ case ComponentType::kMove :
74
+ if (move_applier) {
75
+ move_applier (currentIndex, moves_[component.index ]);
76
+ }
77
+ break ;
67
78
}
68
79
currentIndex++;
69
80
}
@@ -112,6 +123,20 @@ bool Path::GetCubicComponentAtIndex(size_t index,
112
123
return true ;
113
124
}
114
125
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
+
115
140
bool Path::UpdateLinearComponentAtIndex (size_t index,
116
141
const LinearPathComponent& linear) {
117
142
if (index >= components_.size ()) {
@@ -155,12 +180,27 @@ bool Path::UpdateCubicComponentAtIndex(size_t index,
155
180
return true ;
156
181
}
157
182
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 (
159
198
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 ());
164
204
};
165
205
for (const auto & component : components_) {
166
206
switch (component.type ) {
@@ -173,9 +213,12 @@ std::vector<Point> Path::CreatePolyline(
173
213
case ComponentType::kCubic :
174
214
collect_points (cubics_[component.index ].CreatePolyline (approximation));
175
215
break ;
216
+ case ComponentType::kMove :
217
+ polyline.breaks .insert (polyline.points .size ());
218
+ break ;
176
219
}
177
220
}
178
- return points ;
221
+ return polyline ;
179
222
}
180
223
181
224
std::optional<Rect> Path::GetBoundingBox () const {
0 commit comments