Fix ZeroDivisionError in hull() for overlapping circles #1989
+36
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Sketch.hull()raisesZeroDivisionErrorwhen called on faces containing overlapping circles.Reproducer:
Traceback:
Root cause
When two circles overlap, boolean face fusion in
Sketch.face()splits them into multiple arc segments. Arcs originating from the same circle share the same center point. When the gift-wrapping hull algorithm callsarc_arc()on two such concentric arcs, it computesl = distance_between_centers = 0and then divides byl.The hull algorithm was designed for one entity per circle. Multiple arcs per circle (from boolean fusion) violates this assumption.
Fix
Deduplicate arcs by center in
convert_and_validate(), keeping one full-circle arc per unique center (with the largest radius). This ensures the hull algorithm sees exactly one entity per original circle, matching its design assumptions.The fix is entirely in
convert_and_validate()— no changes to the hull algorithm itself.Test plan
test_hull_overlapping_circles— hull via.push().circle().reset().hull()test_hull_overlapping_circles_equal_radii_via_face— hull via.face()composition.cutBlind()for 3D operations