Skip to content

Fix arc track hit test for arcs crossing 0 degrees - #589

Merged
qu1ck merged 1 commit into
openscopeproject:masterfrom
DominikPalo:fix-arc-track-hit-test
Oct 6, 2026
Merged

qu1ck merged 1 commit into
openscopeproject:masterfrom
DominikPalo:fix-arc-track-hit-test

Conversation

@DominikPalo

Copy link
Copy Markdown
Contributor

pointWithinDistanceToArc (web/render.js), used by netHitScan to find the net under a click on arc tracks, normalizes the start and end angles to [0, 2π) and then checks whether the click angle falls inside the arc. Arc tracks are drawn with ctx.arc(center, r, start, end), i.e. going from start with increasing angle to end. When the normalized start is greater than the end, the arc wraps through 0 and covers angle >= start || angle <= end.

The wrap-around branch had the angles swapped:

if (angle1 > angle2)
  return (angle >= angle2 || angle <= angle1);   // true for every angle

Since angle2 < angle1, every angle satisfies one side, so for any arc crossing 0° a click anywhere on its full circle (within the track width) selected the arc's net. Arcs not crossing 0° were unaffected.

The fix swaps the comparison to angle >= angle1 || angle <= angle2.

Testing

I loaded pointWithinDistanceToArc from master and from this branch in Node and evaluated 24 points (every 15°) on each arc's circle against the range covered by ctx.arc(start, end):

Arc (start → end) crosses 0° wrong results on master wrong results with this PR
-10° → 10° yes 23 / 24 0
350° → 20° yes 22 / 24 0
270° → 90° yes 11 / 24 0
-90° → 0° yes 17 / 24 0
30° → 120° no 0 0
90° → 270° no 0 0

The reported case, a click at 180° on a -10°..10° arc, returned true on master and returns false now. Points off the circle are rejected by both versions as before.

🤖 Generated with Claude Code

When an arc's normalized start angle is greater than its end angle the
arc wraps through 0 and covers angles >= start or <= end. The check had
the two angles swapped, which is true for every angle, so clicking
anywhere on the arc's full circle within the track width selected its
net.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@qu1ck
qu1ck merged commit 92f88ef into openscopeproject:master Oct 6, 2026
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.

2 participants