Skip to content

Fix spherical Sutherland-Hodgman dropping thin grazing slivers#425

Merged
asinghvi17 merged 1 commit into
mainfrom
as/fix-sh-grazing-sliver
Jun 30, 2026
Merged

Fix spherical Sutherland-Hodgman dropping thin grazing slivers#425
asinghvi17 merged 1 commit into
mainfrom
as/fix-sh-grazing-sliver

Conversation

@asinghvi17

@asinghvi17 asinghvi17 commented Jun 30, 2026

Copy link
Copy Markdown
Member

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_intersection selected the arc crossing with point_on_spherical_arc, whose spherical_orient(p1, p2, cand) == 0 gate 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

`_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>
@asinghvi17 asinghvi17 force-pushed the as/fix-sh-grazing-sliver branch from 95ce4de to 789b077 Compare June 30, 2026 16:38
@asinghvi17 asinghvi17 marked this pull request as ready for review June 30, 2026 18:35
@asinghvi17 asinghvi17 merged commit dbc5d37 into main Jun 30, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant