Skip to content

Fix orientation of the inner circular arc extras - #70

Merged
fontanf merged 1 commit into
mainfrom
fix-circular-arc-extras-inner-orientation
Sep 23, 2026
Merged

fontanf merged 1 commit into
mainfrom
fix-circular-arc-extras-inner-orientation

Conversation

@fontanf

@fontanf fontanf commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Found while investigating fontanf/packingsolver#595.

Problem

When the line-segment approximation of a shape self-intersects, approximate_by_line_segments falls back to a union of the original shape with "extras": the circular segments between each arc and its chords (or tangents).

compute_circular_arc_extras_inner built these circular segments clockwise (negative area), whatever the arc's own orientation. compute_union expects anticlockwise shapes, which is how compute_circular_arc_extras_outer builds them. For an anticlockwise hole arc, the union then filled the hole entirely instead of replacing its arcs by chords. This is a silently wrong result: on a 100 × 60 rectangle with a circular hole of radius 20, the output had no hole and area 6000.

Fix

Build them anticlockwise: the arc traversed anticlockwise, closed by the chord.

Testing

  • New approximate_by_line_segments/4.json case: a 100 × 100 square with a thin half-annulus hole (anticlockwise outer arc of radius 30, clockwise inner arc of radius 25), with segment length 20. At that length, the tangent approximation of the inner arc crosses the chords of the outer arc, so the fallback union is used.
  • The rectangle-with-a-circular-hole case from the first version of this PR was dropped: since Fix degenerate line segment at the end of an on-circle arc approximation #69, that input no longer goes through the fallback, so it passes without this fix.
  • All 484 tests pass.

'compute_circular_arc_extras_inner' built each circular segment between
a chord and its arc clockwise (negative area), whatever the arc's own
orientation, while 'compute_union' expects anticlockwise shapes, as
'compute_circular_arc_extras_outer' builds them. In the fallback union
of 'approximate_by_line_segments', the extras of an anticlockwise hole
arc then made the union fill the hole entirely instead of replacing its
arcs by chords.

Build them anticlockwise: the arc traversed anticlockwise, closed by the
chord.
@fontanf
fontanf force-pushed the fix-circular-arc-extras-inner-orientation branch from d048aec to 3192076 Compare September 23, 2026 13:55
@fontanf
fontanf merged commit 4b68699 into main Sep 23, 2026
3 checks passed
@fontanf
fontanf deleted the fix-circular-arc-extras-inner-orientation branch September 23, 2026 14:15
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