Merge pull request #98017 from rburing/clipper2_arc_tolerance
Some checks are pending
🔗 GHA / 📊 Static checks (push) Waiting to run
🔗 GHA / 🤖 Android (push) Blocked by required conditions
🔗 GHA / 🍏 iOS (push) Blocked by required conditions
🔗 GHA / 🐧 Linux (push) Blocked by required conditions
🔗 GHA / 🍎 macOS (push) Blocked by required conditions
🔗 GHA / 🏁 Windows (push) Blocked by required conditions
🔗 GHA / 🌐 Web (push) Blocked by required conditions
🔗 GHA / 🪲 Godot CPP (push) Blocked by required conditions

Restore `arc_tolerance` value when using Clipper2's `InflatePaths`
This commit is contained in:
Clay John 2024-10-10 15:18:05 +02:00 committed by GitHub
commit 68f053bf82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -35,7 +35,8 @@
#define STB_RECT_PACK_IMPLEMENTATION #define STB_RECT_PACK_IMPLEMENTATION
#include "thirdparty/misc/stb_rect_pack.h" #include "thirdparty/misc/stb_rect_pack.h"
#define PRECISION 5 // Based on CMP_EPSILON. const int clipper_precision = 5; // Based on CMP_EPSILON.
const double clipper_scale = Math::pow(10.0, clipper_precision);
Vector<Vector<Vector2>> Geometry2D::decompose_polygon_in_convex(const Vector<Point2> &polygon) { Vector<Vector<Vector2>> Geometry2D::decompose_polygon_in_convex(const Vector<Point2> &polygon) {
Vector<Vector<Vector2>> decomp; Vector<Vector<Vector2>> decomp;
@ -224,7 +225,7 @@ Vector<Vector<Point2>> Geometry2D::_polypaths_do_operation(PolyBooleanOperation
path_b[i] = PointD(p_polypath_b[i].x, p_polypath_b[i].y); path_b[i] = PointD(p_polypath_b[i].x, p_polypath_b[i].y);
} }
ClipperD clp(PRECISION); // Scale points up internally to attain the desired precision. ClipperD clp(clipper_precision); // Scale points up internally to attain the desired precision.
clp.PreserveCollinear(false); // Remove redundant vertices. clp.PreserveCollinear(false); // Remove redundant vertices.
if (is_a_open) { if (is_a_open) {
clp.AddOpenSubject({ path_a }); clp.AddOpenSubject({ path_a });
@ -298,9 +299,10 @@ Vector<Vector<Point2>> Geometry2D::_polypath_offset(const Vector<Point2> &p_poly
} }
// Inflate/deflate. // Inflate/deflate.
PathsD paths = InflatePaths({ polypath }, p_delta, jt, et, 2.0, PRECISION, 0.0); PathsD paths = InflatePaths({ polypath }, p_delta, jt, et, 2.0, clipper_precision, 0.25 * clipper_scale);
// Here the miter_limit = 2.0 and arc_tolerance = 0.0 are Clipper2 defaults, // Here the points are scaled up internally and
// and the PRECISION is used to scale points up internally, to attain the desired precision. // the arc_tolerance is scaled accordingly
// to attain the desired precision.
Vector<Vector<Point2>> polypaths; Vector<Vector<Point2>> polypaths;
for (PathsD::size_type i = 0; i < paths.size(); ++i) { for (PathsD::size_type i = 0; i < paths.size(); ++i) {