Skip to content

fix(pstricks): map pointer coordinates through the svg's drawn scale - #41

Merged
pyramation merged 3 commits into
mainfrom
devin/1792625294-scaled-pointer-coords
Oct 22, 2026
Merged

pyramation merged 3 commits into
mainfrom
devin/1792625294-scaled-pointer-coords

Conversation

@pyramation

Copy link
Copy Markdown
Collaborator

Summary

Interactive pictures (\userline, uservariable plots) read the pointer with event.offsetX (mouse) or clientX - target.getBoundingClientRect().left (touch). Both are in screen pixels, while the drawing works in the picture's natural pixel space. When a page draws the svg smaller than its natural size (latex2js.com / mathapedia.com now zoom wide pictures down to fit a phone), the dragged vector no longer follows the finger: it lands at the scaled distance from the origin. The touch path also measured event.target, so a touch on a child path used that path's box.

New psgraph.pointerCoords(svg, clientX, clientY) measures the svg itself and divides out the drawn scale (rect.width / width attr). Used by both the psgraph.pspicture listeners and the React Pspicture mouse/touch handlers:

// before
var coords = [event.offsetX || 0, event.offsetY || 0];
// after
drawLayer(psgraph.pointerCoords(svg.node(), event.clientX, event.clientY), { pointer: true });

Unscaled pictures are unchanged (scale = 1).

Evidence

  • New test in packages/html5/test/pspicture.test.ts draws a 200px picture at 100px and moves the pointer. Fails before the fix (Expected: 100, Received: 0), passes after.
  • pstricks 202/202, html5 74/74 tests pass; react tsc clean.
  • Browser check on latex2js.com /examples/unit-circle with this build overlaid: pointer at 75%/25% of the drawn picture puts the userline end at (0.749, 0.25) of natural size at 1024px (no zoom) and (0.749, 0.248) at 390px (zoom: 0.606). Before the fix the mobile endpoint was off.

Needed for the mobile fixes in latex2js.com / mathapedia.com to keep draggable diagrams accurate. Those sites need a new @latex2js/pstricks + latex2react publish to pick this up.

Link to Devin session: https://app.devin.ai/sessions/7fcd2deb6fb144849a9dd3f8dc116d42
Open in Devin Desktop: https://app.devin.ai/desktop/session/7fcd2deb6fb144849a9dd3f8dc116d42?variant=devin
Requested by: @pyramation

@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@pyramation
pyramation merged commit 5580068 into main Oct 22, 2026
4 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