| 778 | } |
| 779 | |
| 780 | void rebuildSegment( |
| 781 | ClipperLib::Path::size_type start_index, |
| 782 | ClipperLib::Path::size_type end_index, |
| 783 | bool sequence_increasing, |
| 784 | const ClipperLib::Path& polygon, |
| 785 | const PolyMap& polymap, |
| 786 | PathObject* object) |
| 787 | { |
| 788 | auto num_points = polygon.size(); |
| 789 | |
| 790 | object->getCoordinateRef(object->getCoordinateCount() - 1).setCurveStart(true); |
| 791 | |
| 792 | if ((start_index + 1) % num_points == end_index) |
| 793 | { |
| 794 | // This could happen for a straight line or a very flat curve - take coords directly from original |
| 795 | rebuildTwoIndexSegment(start_index, end_index, sequence_increasing, polygon, polymap, object); |
| 796 | return; |
| 797 | } |
| 798 | |
| 799 | // Get polygon point coordinates |
| 800 | const auto& start_point = polygon.at(start_index); |
| 801 | const auto& second_point = polygon.at((start_index + 1) % num_points); |
| 802 | const auto& second_last_point = polygon.at((end_index ? end_index : num_points) - 1); |
| 803 | const auto& end_point = polygon.at(end_index); |
| 804 | |
| 805 | // Try to find the middle coordinates in the same part |
| 806 | bool found = false; |
| 807 | PathCoordInfo second_info{ nullptr, nullptr }; |
| 808 | PathCoordInfo second_last_info{ nullptr, nullptr }; |
| 809 | for (auto second_it = polymap.find(second_point); second_it != polymap.end(); ++second_it) |
| 810 | { |
| 811 | for (auto second_last_it = polymap.find(second_last_point); |
| 812 | second_last_it != polymap.end() && second_last_it.key() == second_last_point; |
| 813 | ++second_last_it) |
| 814 | { |
| 815 | if (second_it->first == second_last_it->first && |
| 816 | second_it->second->index == second_last_it->second->index) |
| 817 | { |
| 818 | // Same part |
| 819 | found = true; |
| 820 | second_info = *second_it; |
| 821 | second_last_info = *second_last_it; |
| 822 | break; |
| 823 | } |
| 824 | } |
| 825 | if (found) |
| 826 | break; |
| 827 | } |
| 828 | |
| 829 | if (!found) |
| 830 | { |
| 831 | // Need unambiguous path part information to find the original object with high probability |
| 832 | qDebug() << "BooleanTool::rebuildSegment: cannot identify original object!"; |
| 833 | rebuildSegmentFromPathOnly(start_point, second_point, second_last_point, end_point, object); |
| 834 | return; |
| 835 | } |
| 836 | |
| 837 | const PathPart* original_path = second_info.first; |
no test coverage detected