Skip to content

fix: use cached matrix in viewportToFramedGraph when no override is given - #1543

Open
shaked-shlomo wants to merge 1 commit into
jacomyal:mainfrom
shaked-shlomo:fix/viewport-to-framed-matrix-cache
Open

fix: use cached matrix in viewportToFramedGraph when no override is given#1543
shaked-shlomo wants to merge 1 commit into
jacomyal:mainfrom
shaked-shlomo:fix/viewport-to-framed-matrix-cache

Conversation

@shaked-shlomo

Copy link
Copy Markdown

Bug

viewportToFramedGraph computes recomputeMatrix with a single negation on the last term:

// viewportToFramedGraph (line ~2251)
const recomputeMatrix = !!override.cameraState || !!override.viewportDimensions || !override.graphDimensions;

while its sibling framedGraphToViewport uses a double negation:

// framedGraphToViewport (line ~2223)
const recomputeMatrix = !!override.cameraState || !!override.viewportDimensions || !!override.graphDimensions;

recomputeMatrix is meant to be true only when the caller passes an override that affects the matrix. Because of the stray single !, viewportToFramedGraph instead recomputes whenever graphDimensions is not provided — i.e. on the normal no-override calls made by the mouse (mouse.ts drag/pan, wheel zoom) and touch handlers.

Impact

On those paths the method bypasses the cached this.invMatrix and rebuilds the inverse from the live this.camera.getState(), whereas framedGraphToViewport correctly uses this.matrix snapshotted at the last render(). During a camera animation the live state runs ahead of the rendered matrix, so the two conversions operate on different camera states within the same frame — causing the round-trip to desync (jumpy pan/zoom anchoring).

Fix

Change !override.graphDimensions!!override.graphDimensions, matching framedGraphToViewport. This is the same one-character fix already present on the v4 branch (commit 940ad72a); this backports it to main.

…de given

recomputeMatrix used a single negation on the last term
(!override.graphDimensions) instead of the double negation used by the
sibling framedGraphToViewport (!!override.graphDimensions). The intent is
to recompute only when an override that affects the matrix is supplied;
the stray single ! instead forced a recompute whenever graphDimensions
was NOT provided -- i.e. on the normal no-override calls used by mouse
pan/zoom and touch handlers.

As a result viewportToFramedGraph built its inverse from the live camera
state while framedGraphToViewport used the matrix snapshotted at the last
render(), desyncing the two halves of the round-trip during camera
animations. Matches the fix already on the v4 branch (940ad72).
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