mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-23 22:54:08 -06:00
Arachne: Fix an arithmetic overflow that causing extra points outside plate (#7330)
* Arachne: Fix an arithmetic overflow that causing extra points outside the plate (SoftFever/OrcaSlicer#7321) * Better way of avoiding overflow, works in Release mode as well * Fix debug build * Fix build
This commit is contained in:
parent
543e85019a
commit
27ec1980bc
1 changed files with 11 additions and 2 deletions
|
@ -153,10 +153,19 @@ void ExtrusionLine::simplify(const int64_t smallest_line_segment_squared, const
|
|||
// ^ current
|
||||
Point intersection_point;
|
||||
bool has_intersection = Line(previous_previous.p, previous.p).intersection_infinite(Line(current.p, next.p), &intersection_point);
|
||||
const auto dist_greater = [](const Point& p1, const Point& p2, const int64_t threshold) {
|
||||
const auto vec = (p1 - p2).cwiseAbs().cast<uint64_t>();
|
||||
if(vec.x() > threshold || vec.y() > threshold) {
|
||||
// If this condition is true, the distance is definitely greater than the threshold.
|
||||
// We don't need to calculate the squared norm at all, which avoid potential arithmetic overflow.
|
||||
return true;
|
||||
}
|
||||
return vec.squaredNorm() > threshold;
|
||||
};
|
||||
if (!has_intersection
|
||||
|| Line::distance_to_infinite_squared(intersection_point, previous.p, current.p) > double(allowed_error_distance_squared)
|
||||
|| (intersection_point - previous.p).cast<int64_t>().squaredNorm() > smallest_line_segment_squared // The intersection point is way too far from the 'previous'
|
||||
|| (intersection_point - current.p).cast<int64_t>().squaredNorm() > smallest_line_segment_squared) // and 'current' points, so it shouldn't replace 'current'
|
||||
|| dist_greater(intersection_point, previous.p, smallest_line_segment_squared) // The intersection point is way too far from the 'previous'
|
||||
|| dist_greater(intersection_point, current.p, smallest_line_segment_squared)) // and 'current' points, so it shouldn't replace 'current'
|
||||
{
|
||||
// We can't find a better spot for it, but the size of the line is more than 5 micron.
|
||||
// So the only thing we can do here is leave it in...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue