Skip to content

Commit 9652695

Browse files
committed
Restore arc_tolerance value when using Clipper2's InflatePaths
This was missed when upgrading from Clipper to Clipper2.
1 parent db66bd3 commit 9652695

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

core/math/geometry_2d.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
#define STB_RECT_PACK_IMPLEMENTATION
3636
#include "thirdparty/misc/stb_rect_pack.h"
3737

38-
#define PRECISION 5 // Based on CMP_EPSILON.
38+
const int clipper_precision = 5; // Based on CMP_EPSILON.
39+
const double clipper_scale = Math::pow(10.0, clipper_precision);
3940

4041
Vector<Vector<Vector2>> Geometry2D::decompose_polygon_in_convex(const Vector<Point2> &polygon) {
4142
Vector<Vector<Vector2>> decomp;
@@ -224,7 +225,7 @@ Vector<Vector<Point2>> Geometry2D::_polypaths_do_operation(PolyBooleanOperation
224225
path_b[i] = PointD(p_polypath_b[i].x, p_polypath_b[i].y);
225226
}
226227

227-
ClipperD clp(PRECISION); // Scale points up internally to attain the desired precision.
228+
ClipperD clp(clipper_precision); // Scale points up internally to attain the desired precision.
228229
clp.PreserveCollinear(false); // Remove redundant vertices.
229230
if (is_a_open) {
230231
clp.AddOpenSubject({ path_a });
@@ -298,9 +299,10 @@ Vector<Vector<Point2>> Geometry2D::_polypath_offset(const Vector<Point2> &p_poly
298299
}
299300

300301
// Inflate/deflate.
301-
PathsD paths = InflatePaths({ polypath }, p_delta, jt, et, 2.0, PRECISION, 0.0);
302-
// Here the miter_limit = 2.0 and arc_tolerance = 0.0 are Clipper2 defaults,
303-
// and the PRECISION is used to scale points up internally, to attain the desired precision.
302+
PathsD paths = InflatePaths({ polypath }, p_delta, jt, et, 2.0, clipper_precision, 0.25 * clipper_scale);
303+
// Here the points are scaled up internally and
304+
// the arc_tolerance is scaled accordingly
305+
// to attain the desired precision.
304306

305307
Vector<Vector<Point2>> polypaths;
306308
for (PathsD::size_type i = 0; i < paths.size(); ++i) {

0 commit comments

Comments
 (0)