Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/shape/shape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rasterization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion src/shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1742,7 +1752,7 @@ Shape Shape::replace(const std::vector<PathReplacement>& 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;
Expand Down
12 changes: 6 additions & 6 deletions src/shapes_intersections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ std::vector<ShapePoint> 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;
}
Expand Down Expand Up @@ -383,7 +383,7 @@ std::vector<ShapePoint> 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<ShapePoint> output;
intersections.push_back({1, (ElementPos)intersection_points.size()});
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -636,7 +636,7 @@ std::vector<PathShapeIntersectionPoint> 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;
}
Expand Down Expand Up @@ -707,7 +707,7 @@ std::vector<PathShapeIntersectionPoint> 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<PathShapeIntersectionPoint> output;
PathShapeIntersectionPoint current_point = {0, -1, path.elements.front().start};
Expand Down Expand Up @@ -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) {
Expand Down
Loading