Callers must provide the scale factor for how this path will be transformed.
It is suitable to use the max basis length of the matrix used to transform the path. If the provided scale is 0, curves will revert to straight lines.
267 {
268 Polyline
polyline(std::move(point_buffer), std::move(reclaim));
269
270 auto& path_components = data_->components;
271 auto& path_points = data_->points;
272
273 auto get_path_component = [&path_components, &path_points](
275 if (component_i >= path_components.size()) {
276 return std::monostate{};
277 }
278 const auto& component = path_components[component_i];
279 switch (component.type) {
281 return reinterpret_cast<const LinearPathComponent*>(
282 &path_points[component.index]);
284 return reinterpret_cast<const QuadraticPathComponent*>(
285 &path_points[component.index]);
287 return reinterpret_cast<const CubicPathComponent*>(
288 &path_points[component.index]);
290 return std::monostate{};
291 }
292 };
293
294 auto compute_contour_start_direction =
295 [&get_path_component](size_t current_path_component_index) {
296 size_t next_component_index = current_path_component_index + 1;
297 while (!std::holds_alternative<std::monostate>(
298 get_path_component(next_component_index))) {
299 auto next_component = get_path_component(next_component_index);
300 auto maybe_vector =
301 std::visit(PathComponentStartDirectionVisitor(), next_component);
302 if (maybe_vector.has_value()) {
303 return maybe_vector.value();
304 } else {
305 next_component_index++;
306 }
307 }
309 };
310
311 std::vector<PolylineContour::Component> poly_components;
312 std::optional<size_t> previous_path_component_index;
313 auto end_contour = [&
polyline, &previous_path_component_index,
314 &get_path_component, &poly_components]() {
315
316
318 return;
319 }
320
321 if (!previous_path_component_index.has_value()) {
322 return;
323 }
324
327 contour.components = poly_components;
328 poly_components.clear();
329
330 size_t previous_index = previous_path_component_index.value();
331 while (!std::holds_alternative<std::monostate>(
332 get_path_component(previous_index))) {
333 auto previous_component = get_path_component(previous_index);
334 auto maybe_vector =
335 std::visit(PathComponentEndDirectionVisitor(), previous_component);
336 if (maybe_vector.has_value()) {
337 contour.end_direction = maybe_vector.value();
338 break;
339 } else {
340 if (previous_index == 0) {
341 break;
342 }
343 previous_index--;
344 }
345 }
346 };
347
348 for (size_t component_i = 0; component_i < path_components.size();
349 component_i++) {
350 const auto& path_component = path_components[component_i];
351 switch (path_component.type) {
353 poly_components.push_back({
354 .component_start_index =
polyline.points->size() - 1,
355 .is_curve = false,
356 });
357 reinterpret_cast<const LinearPathComponent*>(
358 &path_points[path_component.index])
359 ->AppendPolylinePoints(*
polyline.points);
360 previous_path_component_index = component_i;
361 break;
363 poly_components.push_back({
364 .component_start_index =
polyline.points->size() - 1,
365 .is_curve = true,
366 });
367 reinterpret_cast<const QuadraticPathComponent*>(
368 &path_points[path_component.index])
370 previous_path_component_index = component_i;
371 break;
373 poly_components.push_back({
374 .component_start_index =
polyline.points->size() - 1,
375 .is_curve = true,
376 });
377 reinterpret_cast<const CubicPathComponent*>(
378 &path_points[path_component.index])
380 previous_path_component_index = component_i;
381 break;
383 if (component_i == path_components.size() - 1) {
384
385
386 continue;
387 }
388 end_contour();
389
390 Vector2 start_direction = compute_contour_start_direction(component_i);
391 const auto&
contour = data_->contours[path_component.index];
393 .is_closed =
contour.is_closed,
394 .start_direction = start_direction,
395 .components = poly_components});
396
398 break;
399 }
400 }
401 end_contour();
403}
std::variant< std::monostate, const LinearPathComponent *, const QuadraticPathComponent *, const CubicPathComponent * > PathComponentVariant
const Path::Polyline & polyline