|
35 | 35 | #define STB_RECT_PACK_IMPLEMENTATION |
36 | 36 | #include "thirdparty/misc/stb_rect_pack.h" |
37 | 37 |
|
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); |
39 | 40 |
|
40 | 41 | Vector<Vector<Vector2>> Geometry2D::decompose_polygon_in_convex(const Vector<Point2> &polygon) { |
41 | 42 | Vector<Vector<Vector2>> decomp; |
@@ -224,7 +225,7 @@ Vector<Vector<Point2>> Geometry2D::_polypaths_do_operation(PolyBooleanOperation |
224 | 225 | path_b[i] = PointD(p_polypath_b[i].x, p_polypath_b[i].y); |
225 | 226 | } |
226 | 227 |
|
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. |
228 | 229 | clp.PreserveCollinear(false); // Remove redundant vertices. |
229 | 230 | if (is_a_open) { |
230 | 231 | clp.AddOpenSubject({ path_a }); |
@@ -298,9 +299,10 @@ Vector<Vector<Point2>> Geometry2D::_polypath_offset(const Vector<Point2> &p_poly |
298 | 299 | } |
299 | 300 |
|
300 | 301 | // 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. |
304 | 306 |
|
305 | 307 | Vector<Vector<Point2>> polypaths; |
306 | 308 | for (PathsD::size_type i = 0; i < paths.size(); ++i) { |
|
0 commit comments