Skip to content

Commit 2b3b655

Browse files
committed
Revert "Take average of point-on-line projections instead of intersection of outer lines."
This reverts commit 58eaae887e04cc7f699efb0735b193d4b8f55b8b.
1 parent c56500a commit 2b3b655

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

src/utils/linearAlg2D.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,6 @@ class LinearAlg2D
9292
return true;
9393
}
9494

95-
inline static Point projectPointOnLine(const Point& p, const Point& a, const Point& b)
96-
{
97-
const Point vec = b - a;
98-
return a + ((dot(p - a, vec) * vec) / vSize2(vec));
99-
}
100-
10195
/*!
10296
* Find whether a point projected on a line segment would be projected to
10397
* - properly on the line : zero returned

src/utils/polygon.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,14 @@ void PolygonRef::simplify(const coord_t smallest_line_segment_squared, const coo
390390
{
391391
// Special case; The next line is long. If we were to remove this, it could happen that we get quite noticeable artifacts.
392392
// We should instead move this point to a location where both edges are kept and then remove the previous point that we wanted to keep.
393-
// By taking the average of the projections of the original points on the outer lines, we get a point that mostly preserves the direction (so it makes the corner a bit more pointy).
393+
// By taking the intersection of these two lines, we get a point that preserves the direction (so it makes the corner a bit more pointy).
394394
// We just need to be sure that the intersection point does not introduce an artifact itself.
395-
const Point mid = (previous + current) / 2;
396-
const Point a = LinearAlg2D::projectPointOnLine(mid, previous_previous, previous);
397-
const Point b = LinearAlg2D::projectPointOnLine(mid, current, next);
398-
const Point intersection_point = (a + b) / 2;
399-
if (LinearAlg2D::getDist2FromLine(intersection_point, previous, current) > allowed_error_distance_squared
400-
|| vSize2(intersection_point - previous) > smallest_line_segment_squared // The intersection point is way too far from the 'previous'
401-
|| vSize2(intersection_point - next) > smallest_line_segment_squared) // and 'next' points, so it shouldn't replace 'current'
395+
Point intersection_point;
396+
bool has_intersection = LinearAlg2D::lineLineIntersection(previous_previous, previous, current, next, intersection_point);
397+
if (!has_intersection
398+
|| LinearAlg2D::getDist2FromLine(intersection_point, previous, current) > allowed_error_distance_squared
399+
|| vSize2(intersection_point - previous) > smallest_line_segment_squared // The intersection point is way too far from the 'previous'
400+
|| vSize2(intersection_point - next) > smallest_line_segment_squared) // and 'next' points, so it shouldn't replace 'current'
402401
{
403402
// We can't find a better spot for it, but the size of the line is more than 5 micron.
404403
// So the only thing we can do here is leave it in...

0 commit comments

Comments
 (0)