Fix ZeroDivisionError in hull() for overlapping circles#1989
Open
tairabun wants to merge 1 commit intoCadQuery:masterfrom
Open
Fix ZeroDivisionError in hull() for overlapping circles#1989tairabun wants to merge 1 commit intoCadQuery:masterfrom
tairabun wants to merge 1 commit intoCadQuery:masterfrom
Conversation
When Sketch.hull() is called on faces containing overlapping circles,
boolean face fusion splits the circles into multiple arc segments that
share the same center. The gift-wrapping hull algorithm was not designed
for multiple arcs per circle — it causes a ZeroDivisionError in
arc_arc() (dividing by the zero distance between concentric centers).
The fix deduplicates 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.
Reproducer:
Sketch()
.face(Sketch().circle(35).moved(Location(Vector(-19, 0, 0))))
.face(Sketch().circle(35).moved(Location(Vector(19, 0, 0))))
.hull()
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3e984ef to
d2b5d1c
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1989 +/- ##
==========================================
+ Coverage 96.07% 96.15% +0.07%
==========================================
Files 29 29
Lines 7956 7957 +1
Branches 1190 1191 +1
==========================================
+ Hits 7644 7651 +7
+ Misses 179 175 -4
+ Partials 133 131 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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