mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-14 04:27:36 +00:00
Unify colinear simplify tolerance in Arachne (#15314)
Introduced a shared `colinear_vertex_tolerance()` helper in `ExtrusionLine.hpp` and updated both simplify paths (`ExtrusionLine.cpp` and `WallToolPaths.cpp`) to use it instead of duplicated hardcoded `0.005` scaled thresholds. This keeps the near-colinear early-out tied to `SCALED_EPSILON` (rounding-noise scale) and avoids unintended curve decimation from larger tolerances, while documenting the geometric impact in code.
This commit is contained in:
@@ -154,8 +154,8 @@ void simplify(Polygon &thiss, const int64_t smallest_line_segment_squared, const
|
|||||||
//h^2 = L^2 / b^2 [factor the divisor]
|
//h^2 = L^2 / b^2 [factor the divisor]
|
||||||
const int64_t height_2 = double(area_removed_so_far) * double(area_removed_so_far) / double(base_length_2);
|
const int64_t height_2 = double(area_removed_so_far) * double(area_removed_so_far) / double(base_length_2);
|
||||||
// Orca: The value of `height_2` is squared, so we need to compare it with the squared value
|
// Orca: The value of `height_2` is squared, so we need to compare it with the squared value
|
||||||
if ((height_2 <= Slic3r::sqr(scaled<coord_t>(0.005)) //Almost exactly colinear (barring rounding errors).
|
if ((height_2 <= Slic3r::sqr(colinear_vertex_tolerance()) //Almost exactly colinear (barring rounding errors).
|
||||||
&& Line::distance_to_infinite(current, previous, next) <= scaled<double>(0.005))) // make sure that height_2 is not small because of cancellation of positive and negative areas
|
&& Line::distance_to_infinite(current, previous, next) <= double(colinear_vertex_tolerance()))) // make sure that height_2 is not small because of cancellation of positive and negative areas
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (length2 < smallest_line_segment_squared
|
if (length2 < smallest_line_segment_squared
|
||||||
|
|||||||
@@ -133,8 +133,8 @@ void ExtrusionLine::simplify(const int64_t smallest_line_segment_squared, const
|
|||||||
const auto height_2 = int64_t(double(area_removed_so_far) * double(area_removed_so_far) / double(base_length_2));
|
const auto height_2 = int64_t(double(area_removed_so_far) * double(area_removed_so_far) / double(base_length_2));
|
||||||
const int64_t extrusion_area_error = calculateExtrusionAreaDeviationError(previous, current, next);
|
const int64_t extrusion_area_error = calculateExtrusionAreaDeviationError(previous, current, next);
|
||||||
// Orca: The value of `height_2` is squared, so we need to compare it with the squared value
|
// Orca: The value of `height_2` is squared, so we need to compare it with the squared value
|
||||||
if ((height_2 <= Slic3r::sqr(scaled<coord_t>(0.005)) // Almost exactly colinear (barring rounding errors).
|
if ((height_2 <= Slic3r::sqr(colinear_vertex_tolerance()) // Almost exactly colinear (barring rounding errors).
|
||||||
&& Line::distance_to_infinite(current.p, previous.p, next.p) <= scaled<double>(0.005)) // Make sure that height_2 is not small because of cancellation of positive and negative areas
|
&& Line::distance_to_infinite(current.p, previous.p, next.p) <= double(colinear_vertex_tolerance())) // Make sure that height_2 is not small because of cancellation of positive and negative areas
|
||||||
// We shouldn't remove middle junctions of colinear segments if the area changed for the C-P segment is exceeding the maximum allowed
|
// We shouldn't remove middle junctions of colinear segments if the area changed for the C-P segment is exceeding the maximum allowed
|
||||||
&& extrusion_area_error <= maximum_extrusion_area_deviation)
|
&& extrusion_area_error <= maximum_extrusion_area_deviation)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,6 +32,14 @@ class Flow;
|
|||||||
namespace Slic3r::Arachne
|
namespace Slic3r::Arachne
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// ORCA: Tolerance of the "almost exactly colinear" early-out shared by the two simplify() passes
|
||||||
|
// (this file and WallToolPaths.cpp). That test drops a vertex regardless of the user's Maximum wall
|
||||||
|
// resolution/deviation, so it has to stay at the scale of coordinate rounding noise. A larger value
|
||||||
|
// silently decimates finely tessellated curves: on a circle, one vertex may be removed whenever the
|
||||||
|
// sagitta of the resulting chord falls below the tolerance, which halves the point count and turns
|
||||||
|
// smooth arcs into corners the firmware has to decelerate through.
|
||||||
|
inline coord_t colinear_vertex_tolerance() { return coord_t(SCALED_EPSILON); }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Represents a polyline (not just a line) that is to be extruded with variable
|
* Represents a polyline (not just a line) that is to be extruded with variable
|
||||||
* line width.
|
* line width.
|
||||||
|
|||||||
Reference in New Issue
Block a user