| 609 | } |
| 610 | |
| 611 | void polygonToPathPart(const ClipperLib::Path& polygon, const PolyMap& polymap, PathObject* object) |
| 612 | { |
| 613 | auto num_points = polygon.size(); |
| 614 | if (num_points < 3) |
| 615 | return; |
| 616 | |
| 617 | // Index of first used point in polygon |
| 618 | auto part_start_index = 0u; |
| 619 | auto cur_info = PathCoordInfo{ nullptr, nullptr }; |
| 620 | |
| 621 | // Check if we can find either an unknown intersection point |
| 622 | // or a path coord with parameter 0. |
| 623 | // This gives a starting point to search for curves to rebuild |
| 624 | // (because we cannot start in the middle of a curve) |
| 625 | for (; part_start_index < num_points; ++part_start_index) |
| 626 | { |
| 627 | auto current_point = polygon.at(part_start_index); |
| 628 | if (!polymap.contains(current_point)) |
| 629 | break; |
| 630 | |
| 631 | if (polymap.value(current_point).second->param == 0.0) |
| 632 | { |
| 633 | cur_info = polymap.value(current_point); |
| 634 | break; |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | if (part_start_index == num_points) |
| 639 | { |
| 640 | // Did not find a valid starting point. Return the part as a polygon. |
| 641 | for (auto i = 0u; i < num_points; ++i) |
| 642 | object->addCoordinate(MapCoord::fromNative64(polygon.at(i).X, polygon.at(i).Y), i == 0); |
| 643 | object->parts().back().setClosed(true, true); |
| 644 | return; |
| 645 | } |
| 646 | |
| 647 | // Add the first point to the object |
| 648 | rebuildCoordinate(part_start_index, polygon, polymap, object, true); |
| 649 | |
| 650 | |
| 651 | // Index of first segment point in polygon |
| 652 | auto segment_start_index = part_start_index; |
| 653 | bool have_sequence = false; |
| 654 | bool sequence_increasing = false; |
| 655 | bool stop_before = false; |
| 656 | |
| 657 | // Advance along the boundary and rebuild the curve for every sequence |
| 658 | // of path coord pointers with the same path and index. |
| 659 | auto i = part_start_index; |
| 660 | do |
| 661 | { |
| 662 | ++i; |
| 663 | if (i >= num_points) |
| 664 | i = 0; |
| 665 | |
| 666 | PathCoordInfo new_info{ nullptr, nullptr }; |
| 667 | auto new_point = polygon.at(i); |
| 668 | if (polymap.contains(new_point)) |
no test coverage detected