From fee7ac467384a681d5baeca228a28f0a9337b5be Mon Sep 17 00:00:00 2001 From: Florian Fontan Date: Sat, 31 Oct 2026 01:03:09 +0100 Subject: [PATCH 1/2] Sort with std::stable_sort and exact comparisons std::sort doesn't specify the relative order of elements which compare equal, and each standard library orders them its own way: libstdc++, for example, keeps them in input order for 16 elements or fewer and not beyond. So the same input could give different results with libstdc++, libc++ and MSVC, or even with another libstdc++ version. All the calls to std::sort are replaced by std::stable_sort, which keeps elements which compare equal in input order. Besides, 8 sorts compared the lengths along an element within the tolerance, with strictly_lesser, directly or through Shape::is_strictly_closer_to_path_start. Equivalence within tolerance is not transitive: with a = 0, b = 0.7e-6 and c = 1.4e-6, a and b are equivalent, b and c are equivalent, but a is lesser than c. Such a comparison is not a strict weak ordering, and std::sort's behavior is then undefined; the libstdc++ implementation may even read out of the range. These sorts now compare exactly, with the new Shape::is_exactly_closer_to_path_start or with operator<. The points within tolerance of each other are still adjacent once sorted, and the code which goes through them still compares them within tolerance. --- include/shape/shape.hpp | 13 +++++++++++++ src/boolean_operations.cpp | 8 ++++---- src/convex_hull.cpp | 2 +- src/elements_intersections.cpp | 2 +- src/equalize.cpp | 2 +- src/intersection_tree.cpp | 6 +++--- src/no_fit_polygon.cpp | 6 +++--- src/rasterization.cpp | 6 +++--- src/shape.cpp | 20 +++++++++++++++----- src/shapes_intersections.cpp | 28 ++++++++++++++-------------- src/trapezoidation.cpp | 4 ++-- 11 files changed, 60 insertions(+), 37 deletions(-) diff --git a/include/shape/shape.hpp b/include/shape/shape.hpp index 8a313fb..c453408 100644 --- a/include/shape/shape.hpp +++ b/include/shape/shape.hpp @@ -952,6 +952,19 @@ struct Shape const ShapePoint& point_1, const ShapePoint& point_2) const; + /** + * Same as is_strictly_closer_to_path_start but compare exactly, without + * tolerance. + * + * Unlike is_strictly_closer_to_path_start, it is a strict weak ordering, + * so it can be used to sort points: two points within the tolerance of + * each other are not equivalent for is_strictly_closer_to_path_start, + * but equivalence within tolerance is not transitive. + */ + bool is_exactly_closer_to_path_start( + const ShapePoint& point_1, + const ShapePoint& point_2) const; + /** * Return a point of the boundary strictly between 'point_1' and * 'point_2', going forward from 'point_1' (around the start of the shape diff --git a/src/boolean_operations.cpp b/src/boolean_operations.cpp index f28f8f9..63c4ff2 100644 --- a/src/boolean_operations.cpp +++ b/src/boolean_operations.cpp @@ -654,7 +654,7 @@ ComputeSplittedElementsOutput compute_splitted_elements( } // Sort intersection points of this element. - std::sort( + std::stable_sort( intersections.begin(), intersections.end(), [&element]( @@ -828,7 +828,7 @@ ComputeSplittedElementsOutput compute_splitted_elements( ++it) { ComponentId component_id = *it; auto& splitted_elements = output.components_splitted_elements[component_id]; - std::sort(splitted_elements.begin(), splitted_elements.end()); + std::stable_sort(splitted_elements.begin(), splitted_elements.end()); // Keep a single element for each group of identical elements. The // directions in which each shape goes through it are summed: the // element kept is from a shape for which this sum is not zero, in @@ -907,7 +907,7 @@ BooleanOperationGraph compute_graph( sorted_element_points.push_back({element_pos, true}); sorted_element_points.push_back({element_pos, false}); } - std::sort( + std::stable_sort( sorted_element_points.begin(), sorted_element_points.end(), [&splitted_elements]( @@ -993,7 +993,7 @@ std::vector compute_arcs_next( } l /= 2; // Sort the arcs at this node by angle. - std::sort( + std::stable_sort( node.successors.begin(), node.successors.end(), [&l, &splitted_elements]( diff --git a/src/convex_hull.cpp b/src/convex_hull.cpp index 773cbee..3b23dd8 100644 --- a/src/convex_hull.cpp +++ b/src/convex_hull.cpp @@ -56,7 +56,7 @@ Shape shape::convex_hull( points.push_back(shape_element.start); } - std::sort( + std::stable_sort( points.begin(), points.end(), [&point_least_y]( diff --git a/src/elements_intersections.cpp b/src/elements_intersections.cpp index 74bd991..0b0f6da 100644 --- a/src/elements_intersections.cpp +++ b/src/elements_intersections.cpp @@ -376,7 +376,7 @@ ShapeElementIntersectionsOutput compute_line_line_intersections( // If they are aligned, check if they overlap. std::array sorted_points = {0, 1, 2, 3}; - std::sort( + std::stable_sort( sorted_points.begin(), sorted_points.end(), [&points_values]( diff --git a/src/equalize.cpp b/src/equalize.cpp index 93144a8..2b34152 100644 --- a/src/equalize.cpp +++ b/src/equalize.cpp @@ -16,7 +16,7 @@ std::vector shape::equalize_points( std::vector> sorted_points(points.size()); for (ElementPos pos = 0; pos < (ElementPos)points.size(); ++pos) sorted_points[pos] = {points[pos], pos}; - std::sort( + std::stable_sort( sorted_points.begin(), sorted_points.end(), [](const auto& pair_1, const auto pair_2) diff --git a/src/intersection_tree.cpp b/src/intersection_tree.cpp index 1d39ba3..bb83b81 100644 --- a/src/intersection_tree.cpp +++ b/src/intersection_tree.cpp @@ -650,7 +650,7 @@ std::vector> IntersectionTree::compute_intersectin } // Remove duplicates. - std::sort(potentially_intersecting_shapes.begin(), potentially_intersecting_shapes.end()); + std::stable_sort(potentially_intersecting_shapes.begin(), potentially_intersecting_shapes.end()); potentially_intersecting_shapes.erase( unique(potentially_intersecting_shapes.begin(), potentially_intersecting_shapes.end()), potentially_intersecting_shapes.end()); @@ -722,7 +722,7 @@ std::vector IntersectionTree::compute_intersecting_e } // Remove duplicates. - std::sort(potentially_intersecting_elements.begin(), potentially_intersecting_elements.end()); + std::stable_sort(potentially_intersecting_elements.begin(), potentially_intersecting_elements.end()); potentially_intersecting_elements.erase( unique(potentially_intersecting_elements.begin(), potentially_intersecting_elements.end()), potentially_intersecting_elements.end()); @@ -799,7 +799,7 @@ std::vector> IntersectionTree::compute_equal_p // Remove duplicates. //std::cout << "remove duplicates..." << std::endl; - std::sort(potentially_equal_points.begin(), potentially_equal_points.end()); + std::stable_sort(potentially_equal_points.begin(), potentially_equal_points.end()); potentially_equal_points.erase( unique(potentially_equal_points.begin(), potentially_equal_points.end()), potentially_equal_points.end()); diff --git a/src/no_fit_polygon.cpp b/src/no_fit_polygon.cpp index b1a93a4..afec4c6 100644 --- a/src/no_fit_polygon.cpp +++ b/src/no_fit_polygon.cpp @@ -109,7 +109,7 @@ std::vector split_arc_into_pieces( return {arc}; // Order the directions along the arc, and remove the duplicates. - std::sort( + std::stable_sort( split_directions.begin(), split_directions.end(), [&arc](const Point& direction_1, const Point& direction_2) @@ -995,7 +995,7 @@ void compute_feasible_elements_and_points( for (const Point& point: elements_intersections[element_pos]) if (overlapping_part.contains(point)) points.push_back(point); - std::sort( + std::stable_sort( points.begin(), points.end(), [&overlapping_part]( @@ -1034,7 +1034,7 @@ void compute_feasible_elements_and_points( output.feasible_elements = merge_continuing_line_segments(feasible_elements); // Feasible points. - std::sort( + std::stable_sort( candidate_points.begin(), candidate_points.end(), [](const Point& point_1, const Point& point_2) diff --git a/src/rasterization.cpp b/src/rasterization.cpp index fe1e13c..104de53 100644 --- a/src/rasterization.cpp +++ b/src/rasterization.cpp @@ -108,14 +108,14 @@ void fill_columns_intersections( std::cout << point.element_pos << " " << point.point.to_string() << std::endl; #endif // Sort intersection points by their length on the element. - std::sort( + std::stable_sort( intersection_points.begin(), intersection_points.end(), [&shape]( const ShapePoint& point_1, const ShapePoint& point_2) { - return shape.is_strictly_closer_to_path_start(point_1, point_2); + return shape.is_exactly_closer_to_path_start(point_1, point_2); }); // A vertex on a column line is found as the end of an element and as the // start of the next one; keep it once. @@ -304,7 +304,7 @@ RasterizedGrid shape::rasterization( // Sort intersections by ascending min(y_in, y_out). std::vector sorted_intersections = column_inters; - std::sort( + std::stable_sort( sorted_intersections.begin(), sorted_intersections.end(), []( diff --git a/src/shape.cpp b/src/shape.cpp index 6e6cf2e..7db5ffa 100644 --- a/src/shape.cpp +++ b/src/shape.cpp @@ -1445,7 +1445,7 @@ Point Shape::find_point_strictly_inside() const touches.push_back({x_max, false}); } } - std::sort( + std::stable_sort( touches.begin(), touches.end(), [](const RayCrossing& touch_1, const RayCrossing& touch_2) @@ -1503,6 +1503,16 @@ bool Shape::is_strictly_closer_to_path_start( return strictly_lesser(element.length(point_1.point), element.length(point_2.point)); } +bool Shape::is_exactly_closer_to_path_start( + const ShapePoint& point_1, + const ShapePoint& point_2) const +{ + if (point_1.element_pos != point_2.element_pos) + return point_1.element_pos < point_2.element_pos; + const ShapeElement& element = this->elements[point_1.element_pos]; + return element.length(point_1.point) < element.length(point_2.point); +} + ShapePoint Shape::find_point_between( const ShapePoint& point_1, const ShapePoint& point_2) const @@ -1733,7 +1743,7 @@ Shape Shape::replace(const std::vector& paths) const std::vector sorted_paths(paths.size()); std::iota(sorted_paths.begin(), sorted_paths.end(), 0); - std::sort( + std::stable_sort( sorted_paths.begin(), sorted_paths.end(), [this, &paths]( @@ -1742,7 +1752,7 @@ Shape Shape::replace(const std::vector& paths) const { const PathReplacement& path_1 = paths[path_pos_1]; const PathReplacement& path_2 = paths[path_pos_2]; - return this->is_strictly_closer_to_path_start(path_1.start, path_2.start); + return this->is_exactly_closer_to_path_start(path_1.start, path_2.start); }); Shape shape; @@ -2233,7 +2243,7 @@ bool ShapeWithHoles::check() const for (const Point& point: intersections.proper_intersections) points.push_back(point); } - std::sort( + std::stable_sort( points.begin(), points.end(), [&element](const Point& point_1, const Point& point_2) @@ -2372,7 +2382,7 @@ Point ShapeWithHoles::find_point_strictly_inside() const } } } - std::sort( + std::stable_sort( touches.begin(), touches.end(), [](const RayCrossing& touch_1, const RayCrossing& touch_2) diff --git a/src/shapes_intersections.cpp b/src/shapes_intersections.cpp index 9db321a..e1962a5 100644 --- a/src/shapes_intersections.cpp +++ b/src/shapes_intersections.cpp @@ -231,7 +231,7 @@ bool shape::intersect( intersections.push_back({1, (ElementPos)intersection_points.size()}); intersection_points.push_back(element.end); // Sort intersections. - std::sort( + std::stable_sort( intersections.begin(), intersections.end(), [&element, &overlapping_parts, &intersection_points]( @@ -319,14 +319,14 @@ std::vector shape::compute_intersections( return {*p.first, *p.second}; } // Sort intersections. - std::sort( + std::stable_sort( output.begin(), output.end(), [&element]( const ShapePoint& point_1, const ShapePoint& point_2) { - return strictly_lesser(element.length(point_1.point), element.length(point_2.point)); + return element.length(point_1.point) < element.length(point_2.point); }); return output; } @@ -366,7 +366,7 @@ std::vector shape::compute_strict_intersections( } } // Sort intersections. - std::sort( + std::stable_sort( intersections.begin(), intersections.end(), [&element, &overlapping_parts, &intersection_points]( @@ -383,7 +383,7 @@ std::vector shape::compute_strict_intersections( overlapping_parts[p2.second].first, overlapping_parts[p2.second].second.start}: intersection_points[p2.second]; - return strictly_lesser(element.length(point_1.point), element.length(point_2.point)); + return element.length(point_1.point) < element.length(point_2.point); }); std::vector output; intersections.push_back({1, (ElementPos)intersection_points.size()}); @@ -501,7 +501,7 @@ bool shape::intersect( intersection_points.push_back({(ElementPos)shape_1.elements.size() - 1, shape_1.elements.back().end}); } // Sort intersections. - std::sort( + std::stable_sort( intersections.begin(), intersections.end(), [&shape_1, &overlapping_parts, &intersection_points]( @@ -518,7 +518,7 @@ bool shape::intersect( overlapping_parts[p2.second].first, overlapping_parts[p2.second].second.start}: intersection_points[p2.second]; - return shape_1.is_strictly_closer_to_path_start(point_1, point_2); + return shape_1.is_exactly_closer_to_path_start(point_1, point_2); }); ShapePoint current_point = {0, shape_1.elements.front().start}; for (ElementPos pos = 0; pos < (ElementPos)intersections.size(); ++pos) { @@ -627,7 +627,7 @@ std::vector shape::compute_intersections( return {*p.first, *p.second}; } // Sort intersections. - std::sort( + std::stable_sort( output.begin(), output.end(), [&path]( @@ -636,7 +636,7 @@ std::vector shape::compute_intersections( { ShapePoint point_1 = {p1.path_element_pos, p1.point}; ShapePoint point_2 = {p2.path_element_pos, p2.point}; - return path.is_strictly_closer_to_path_start(point_1, point_2); + return path.is_exactly_closer_to_path_start(point_1, point_2); }); return output; } @@ -686,7 +686,7 @@ std::vector shape::compute_strict_intersections( intersections.push_back({1, (ElementPos)intersection_points.size()}); intersection_points.push_back({(ElementPos)path.elements.size() - 1, -1, path.elements.back().end}); // Sort intersections. - std::sort( + std::stable_sort( intersections.begin(), intersections.end(), [&path, &overlapping_parts, &intersection_points]( @@ -707,7 +707,7 @@ std::vector shape::compute_strict_intersections( ShapePoint{ intersection_points[p2.second].path_element_pos, intersection_points[p2.second].point}; - return path.is_strictly_closer_to_path_start(point_1, point_2); + return path.is_exactly_closer_to_path_start(point_1, point_2); }); std::vector output; PathShapeIntersectionPoint current_point = {0, -1, path.elements.front().start}; @@ -870,7 +870,7 @@ bool shape::intersect( intersections.push_back({1, (ElementPos)intersection_points.size()}); intersection_points.push_back(element.end); // Sort intersections. - std::sort( + std::stable_sort( intersections.begin(), intersections.end(), [&element, &overlapping_parts, &intersection_points]( @@ -990,7 +990,7 @@ bool shape::intersect( intersection_points.push_back({(ElementPos)shape.elements.size() - 1, shape.elements.back().end}); } // Sort intersections. - std::sort( + std::stable_sort( intersections.begin(), intersections.end(), [&shape, &overlapping_parts, &intersection_points]( @@ -1007,7 +1007,7 @@ bool shape::intersect( overlapping_parts[p2.second].first, overlapping_parts[p2.second].second.start}: intersection_points[p2.second]; - return shape.is_strictly_closer_to_path_start(point_1, point_2); + return shape.is_exactly_closer_to_path_start(point_1, point_2); }); ShapePoint current_point = {0, shape.elements.front().start}; for (ElementPos pos = 0; pos < (ElementPos)intersections.size(); ++pos) { diff --git a/src/trapezoidation.cpp b/src/trapezoidation.cpp index 83c5615..3d10413 100644 --- a/src/trapezoidation.cpp +++ b/src/trapezoidation.cpp @@ -150,7 +150,7 @@ std::pair find_trapezoid_containing_vertex( std::vector> candidates = strict; if (candidates.size() < 2) candidates.insert(candidates.end(), on_side.begin(), on_side.end()); - std::sort(candidates.begin(), candidates.end()); + std::stable_sort(candidates.begin(), candidates.end()); std::pair res = {-1, -1}; if (candidates.size() >= 1) res.first = std::get<2>(candidates[0]); @@ -380,7 +380,7 @@ std::vector shape::trapezoidation( return std::make_pair(rank, (rank == 2)? -width: width); }; // Sort. - std::sort( + std::stable_sort( sorted_vertices.begin(), sorted_vertices.end(), [&shape, &vertex_rank]( From 96a8386e434d0e3c932f2c98bc8cbdfdf543c62c Mon Sep 17 00:00:00 2001 From: Florian Fontan Date: Sat, 31 Oct 2026 01:35:43 +0100 Subject: [PATCH 2/2] Keep std::sort rather than std::stable_sort std::stable_sort may be slower than std::sort. Only the sorts which compared within tolerance are changed, to compare exactly. --- src/boolean_operations.cpp | 8 ++++---- src/convex_hull.cpp | 2 +- src/elements_intersections.cpp | 2 +- src/equalize.cpp | 2 +- src/intersection_tree.cpp | 6 +++--- src/no_fit_polygon.cpp | 6 +++--- src/rasterization.cpp | 4 ++-- src/shape.cpp | 8 ++++---- src/shapes_intersections.cpp | 16 ++++++++-------- src/trapezoidation.cpp | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/boolean_operations.cpp b/src/boolean_operations.cpp index 63c4ff2..f28f8f9 100644 --- a/src/boolean_operations.cpp +++ b/src/boolean_operations.cpp @@ -654,7 +654,7 @@ ComputeSplittedElementsOutput compute_splitted_elements( } // Sort intersection points of this element. - std::stable_sort( + std::sort( intersections.begin(), intersections.end(), [&element]( @@ -828,7 +828,7 @@ ComputeSplittedElementsOutput compute_splitted_elements( ++it) { ComponentId component_id = *it; auto& splitted_elements = output.components_splitted_elements[component_id]; - std::stable_sort(splitted_elements.begin(), splitted_elements.end()); + std::sort(splitted_elements.begin(), splitted_elements.end()); // Keep a single element for each group of identical elements. The // directions in which each shape goes through it are summed: the // element kept is from a shape for which this sum is not zero, in @@ -907,7 +907,7 @@ BooleanOperationGraph compute_graph( sorted_element_points.push_back({element_pos, true}); sorted_element_points.push_back({element_pos, false}); } - std::stable_sort( + std::sort( sorted_element_points.begin(), sorted_element_points.end(), [&splitted_elements]( @@ -993,7 +993,7 @@ std::vector compute_arcs_next( } l /= 2; // Sort the arcs at this node by angle. - std::stable_sort( + std::sort( node.successors.begin(), node.successors.end(), [&l, &splitted_elements]( diff --git a/src/convex_hull.cpp b/src/convex_hull.cpp index 3b23dd8..773cbee 100644 --- a/src/convex_hull.cpp +++ b/src/convex_hull.cpp @@ -56,7 +56,7 @@ Shape shape::convex_hull( points.push_back(shape_element.start); } - std::stable_sort( + std::sort( points.begin(), points.end(), [&point_least_y]( diff --git a/src/elements_intersections.cpp b/src/elements_intersections.cpp index 0b0f6da..74bd991 100644 --- a/src/elements_intersections.cpp +++ b/src/elements_intersections.cpp @@ -376,7 +376,7 @@ ShapeElementIntersectionsOutput compute_line_line_intersections( // If they are aligned, check if they overlap. std::array sorted_points = {0, 1, 2, 3}; - std::stable_sort( + std::sort( sorted_points.begin(), sorted_points.end(), [&points_values]( diff --git a/src/equalize.cpp b/src/equalize.cpp index 2b34152..93144a8 100644 --- a/src/equalize.cpp +++ b/src/equalize.cpp @@ -16,7 +16,7 @@ std::vector shape::equalize_points( std::vector> sorted_points(points.size()); for (ElementPos pos = 0; pos < (ElementPos)points.size(); ++pos) sorted_points[pos] = {points[pos], pos}; - std::stable_sort( + std::sort( sorted_points.begin(), sorted_points.end(), [](const auto& pair_1, const auto pair_2) diff --git a/src/intersection_tree.cpp b/src/intersection_tree.cpp index bb83b81..1d39ba3 100644 --- a/src/intersection_tree.cpp +++ b/src/intersection_tree.cpp @@ -650,7 +650,7 @@ std::vector> IntersectionTree::compute_intersectin } // Remove duplicates. - std::stable_sort(potentially_intersecting_shapes.begin(), potentially_intersecting_shapes.end()); + std::sort(potentially_intersecting_shapes.begin(), potentially_intersecting_shapes.end()); potentially_intersecting_shapes.erase( unique(potentially_intersecting_shapes.begin(), potentially_intersecting_shapes.end()), potentially_intersecting_shapes.end()); @@ -722,7 +722,7 @@ std::vector IntersectionTree::compute_intersecting_e } // Remove duplicates. - std::stable_sort(potentially_intersecting_elements.begin(), potentially_intersecting_elements.end()); + std::sort(potentially_intersecting_elements.begin(), potentially_intersecting_elements.end()); potentially_intersecting_elements.erase( unique(potentially_intersecting_elements.begin(), potentially_intersecting_elements.end()), potentially_intersecting_elements.end()); @@ -799,7 +799,7 @@ std::vector> IntersectionTree::compute_equal_p // Remove duplicates. //std::cout << "remove duplicates..." << std::endl; - std::stable_sort(potentially_equal_points.begin(), potentially_equal_points.end()); + std::sort(potentially_equal_points.begin(), potentially_equal_points.end()); potentially_equal_points.erase( unique(potentially_equal_points.begin(), potentially_equal_points.end()), potentially_equal_points.end()); diff --git a/src/no_fit_polygon.cpp b/src/no_fit_polygon.cpp index afec4c6..b1a93a4 100644 --- a/src/no_fit_polygon.cpp +++ b/src/no_fit_polygon.cpp @@ -109,7 +109,7 @@ std::vector split_arc_into_pieces( return {arc}; // Order the directions along the arc, and remove the duplicates. - std::stable_sort( + std::sort( split_directions.begin(), split_directions.end(), [&arc](const Point& direction_1, const Point& direction_2) @@ -995,7 +995,7 @@ void compute_feasible_elements_and_points( for (const Point& point: elements_intersections[element_pos]) if (overlapping_part.contains(point)) points.push_back(point); - std::stable_sort( + std::sort( points.begin(), points.end(), [&overlapping_part]( @@ -1034,7 +1034,7 @@ void compute_feasible_elements_and_points( output.feasible_elements = merge_continuing_line_segments(feasible_elements); // Feasible points. - std::stable_sort( + std::sort( candidate_points.begin(), candidate_points.end(), [](const Point& point_1, const Point& point_2) diff --git a/src/rasterization.cpp b/src/rasterization.cpp index 104de53..87b9272 100644 --- a/src/rasterization.cpp +++ b/src/rasterization.cpp @@ -108,7 +108,7 @@ void fill_columns_intersections( std::cout << point.element_pos << " " << point.point.to_string() << std::endl; #endif // Sort intersection points by their length on the element. - std::stable_sort( + std::sort( intersection_points.begin(), intersection_points.end(), [&shape]( @@ -304,7 +304,7 @@ RasterizedGrid shape::rasterization( // Sort intersections by ascending min(y_in, y_out). std::vector sorted_intersections = column_inters; - std::stable_sort( + std::sort( sorted_intersections.begin(), sorted_intersections.end(), []( diff --git a/src/shape.cpp b/src/shape.cpp index 7db5ffa..85745b2 100644 --- a/src/shape.cpp +++ b/src/shape.cpp @@ -1445,7 +1445,7 @@ Point Shape::find_point_strictly_inside() const touches.push_back({x_max, false}); } } - std::stable_sort( + std::sort( touches.begin(), touches.end(), [](const RayCrossing& touch_1, const RayCrossing& touch_2) @@ -1743,7 +1743,7 @@ Shape Shape::replace(const std::vector& paths) const std::vector sorted_paths(paths.size()); std::iota(sorted_paths.begin(), sorted_paths.end(), 0); - std::stable_sort( + std::sort( sorted_paths.begin(), sorted_paths.end(), [this, &paths]( @@ -2243,7 +2243,7 @@ bool ShapeWithHoles::check() const for (const Point& point: intersections.proper_intersections) points.push_back(point); } - std::stable_sort( + std::sort( points.begin(), points.end(), [&element](const Point& point_1, const Point& point_2) @@ -2382,7 +2382,7 @@ Point ShapeWithHoles::find_point_strictly_inside() const } } } - std::stable_sort( + std::sort( touches.begin(), touches.end(), [](const RayCrossing& touch_1, const RayCrossing& touch_2) diff --git a/src/shapes_intersections.cpp b/src/shapes_intersections.cpp index e1962a5..e9d7375 100644 --- a/src/shapes_intersections.cpp +++ b/src/shapes_intersections.cpp @@ -231,7 +231,7 @@ bool shape::intersect( intersections.push_back({1, (ElementPos)intersection_points.size()}); intersection_points.push_back(element.end); // Sort intersections. - std::stable_sort( + std::sort( intersections.begin(), intersections.end(), [&element, &overlapping_parts, &intersection_points]( @@ -319,7 +319,7 @@ std::vector shape::compute_intersections( return {*p.first, *p.second}; } // Sort intersections. - std::stable_sort( + std::sort( output.begin(), output.end(), [&element]( @@ -366,7 +366,7 @@ std::vector shape::compute_strict_intersections( } } // Sort intersections. - std::stable_sort( + std::sort( intersections.begin(), intersections.end(), [&element, &overlapping_parts, &intersection_points]( @@ -501,7 +501,7 @@ bool shape::intersect( intersection_points.push_back({(ElementPos)shape_1.elements.size() - 1, shape_1.elements.back().end}); } // Sort intersections. - std::stable_sort( + std::sort( intersections.begin(), intersections.end(), [&shape_1, &overlapping_parts, &intersection_points]( @@ -627,7 +627,7 @@ std::vector shape::compute_intersections( return {*p.first, *p.second}; } // Sort intersections. - std::stable_sort( + std::sort( output.begin(), output.end(), [&path]( @@ -686,7 +686,7 @@ std::vector shape::compute_strict_intersections( intersections.push_back({1, (ElementPos)intersection_points.size()}); intersection_points.push_back({(ElementPos)path.elements.size() - 1, -1, path.elements.back().end}); // Sort intersections. - std::stable_sort( + std::sort( intersections.begin(), intersections.end(), [&path, &overlapping_parts, &intersection_points]( @@ -870,7 +870,7 @@ bool shape::intersect( intersections.push_back({1, (ElementPos)intersection_points.size()}); intersection_points.push_back(element.end); // Sort intersections. - std::stable_sort( + std::sort( intersections.begin(), intersections.end(), [&element, &overlapping_parts, &intersection_points]( @@ -990,7 +990,7 @@ bool shape::intersect( intersection_points.push_back({(ElementPos)shape.elements.size() - 1, shape.elements.back().end}); } // Sort intersections. - std::stable_sort( + std::sort( intersections.begin(), intersections.end(), [&shape, &overlapping_parts, &intersection_points]( diff --git a/src/trapezoidation.cpp b/src/trapezoidation.cpp index 3d10413..83c5615 100644 --- a/src/trapezoidation.cpp +++ b/src/trapezoidation.cpp @@ -150,7 +150,7 @@ std::pair find_trapezoid_containing_vertex( std::vector> candidates = strict; if (candidates.size() < 2) candidates.insert(candidates.end(), on_side.begin(), on_side.end()); - std::stable_sort(candidates.begin(), candidates.end()); + std::sort(candidates.begin(), candidates.end()); std::pair res = {-1, -1}; if (candidates.size() >= 1) res.first = std::get<2>(candidates[0]); @@ -380,7 +380,7 @@ std::vector shape::trapezoidation( return std::make_pair(rank, (rank == 2)? -width: width); }; // Sort. - std::stable_sort( + std::sort( sorted_vertices.begin(), sorted_vertices.end(), [&shape, &vertex_rank](