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/rasterization.cpp b/src/rasterization.cpp index fe1e13c..87b9272 100644 --- a/src/rasterization.cpp +++ b/src/rasterization.cpp @@ -115,7 +115,7 @@ void fill_columns_intersections( 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. diff --git a/src/shape.cpp b/src/shape.cpp index 6e6cf2e..85745b2 100644 --- a/src/shape.cpp +++ b/src/shape.cpp @@ -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 @@ -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; diff --git a/src/shapes_intersections.cpp b/src/shapes_intersections.cpp index 9db321a..e9d7375 100644 --- a/src/shapes_intersections.cpp +++ b/src/shapes_intersections.cpp @@ -326,7 +326,7 @@ std::vector shape::compute_intersections( 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; } @@ -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()}); @@ -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) { @@ -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; } @@ -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}; @@ -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) {