Fix spherical Sutherland-Hodgman dropping thin grazing slivers#425
Merged
Conversation
`_sh_spherical_intersection` chose the subject-arc crossing with `point_on_spherical_arc`, whose `spherical_orient(p1, p2, cand) == 0` gate rejects the cross-product candidate that round-off pushes just off the great circle. For a grazing crossing both antipodal candidates were rejected and the function fell back to an arc endpoint, collapsing the sliver to zero area — and the empty result then made the containment fallback return the whole clip cell, so `area(A ∩ B)` depended on argument order. The two candidates are antipodal, so just keep the one on the subject arc (same hemisphere as the midpoint). Adds a regression test on the real grid cells. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
95ce4de to
789b077
Compare
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.
area(intersection(A, B))for two convex spherical polygons could depend on argument order. When a subject edge grazes the great-circle extension of a clip edge, two overlapping cells returned the whole clip polygon one way and the correct thin sliver the other — breaking conservative regridding between HEALPix-family grids (some cells got ~2× their area)._sh_spherical_intersectionselected the arc crossing withpoint_on_spherical_arc, whosespherical_orient(p1, p2, cand) == 0gate rejects the cross-product candidate (round-off pushes it just off the great circle). Both antipodal candidates get rejected → fall back to an arc endpoint → sliver collapses to zero → the containment fallback returns the whole clip cell.The two candidates are antipodal, so just keep the one on the subject arc (same hemisphere as the midpoint). Regression test uses the real grid cells that triggered it; the OctaHEALPix↔HEALPix area-agreement error drops from ~1.0 to ~1e-12.
Independent of #414 (which touches the same file); based on
main.🤖 Generated with Claude Code