Skip to content

Fix/jumping ellipse#3

Merged
u8array merged 4 commits into
mainfrom
fix/jumping-ellipse
May 4, 2026
Merged

Fix/jumping ellipse#3
u8array merged 4 commits into
mainfrom
fix/jumping-ellipse

Conversation

@u8array
Copy link
Copy Markdown
Owner

@u8array u8array commented May 3, 2026

No description provided.

u8array added 2 commits May 3, 2026 23:47
Two related bugs in onTransformEnd surfaced via issue #2:

1. Konva's Ellipse uses its center as the origin while every other shape
   uses top-left, so writing node.x() straight into obj.x stored the
   center. On the next render, the ellipse's center was placed at
   (storedCenter + radius), producing a visible jump by (rx, ry).

2. snap() was applied to the position even on resize. With snap enabled,
   off-grid shapes (including QR codes and other barcodes) were pulled
   onto the grid as a side-effect of resizing, even though the user only
   intended to change the size.

Adds two pure helpers (transformNodeTopLeft, transformPositionMoved) and
their unit tests so the geometry stays testable.

Closes #2.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces logic to correctly calculate the top-left coordinates of transformed Konva nodes, specifically handling center-anchored shapes like ellipses. It also adds a guard to prevent off-grid shapes from snapping to the grid unless their position is significantly changed during a resize. Feedback suggests improving maintainability by using a registry for center-anchored types and correcting JSDoc terminology regarding visual dimensions.

Comment thread src/components/Canvas/hooks/useKonvaTransformer.ts Outdated
Comment thread src/components/Canvas/transformerGeometry.ts Outdated
u8array added 2 commits May 4, 2026 00:01
Remove the hardcoded obj.type === "ellipse" check from useKonvaTransformer
and replace it with an ObjectTypeDefinition.nodeOrigin flag. New
center-anchored shape types now declare 'center' once in the registry
instead of editing the transformer hook.

Other small clean-ups:
- POSITION_MOVE_TOLERANCE_DOTS replaces the magic number 1
- transformPositionMoved -> positionDidMove (idiomatic predicate name)
Gemini PR review correctly flagged that 'nodeSize * s' is the visual
diameter (full width/height), not the radius. The implementation is
unchanged; only the comment is corrected. Also clarifies that the
function returns stage pixels, not dots.
@u8array
Copy link
Copy Markdown
Owner Author

u8array commented May 3, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces logic to correctly handle coordinate transformations for Konva nodes with different origins, specifically addressing center-anchored shapes like Ellipses. It also implements a guard to prevent off-grid objects from snapping to the grid when resized from an anchor that doesn't move the origin. Feedback was provided regarding the tolerance level for detecting position changes, suggesting a smaller value to preserve precision for manual adjustments.

Comment thread src/components/Canvas/transformerGeometry.ts
@u8array u8array linked an issue May 4, 2026 that may be closed by this pull request
@u8array u8array merged commit e924e1c into main May 4, 2026
2 checks passed
@u8array u8array deleted the fix/jumping-ellipse branch May 4, 2026 21:13
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.

Jumping Elipse when klicking

1 participant