Fix/jumping ellipse#3
Conversation
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.
There was a problem hiding this comment.
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.
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.
|
/gemini review |
There was a problem hiding this comment.
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.
No description provided.