Skip to content

Fix QR code Y-offset drift and 1-dot resize drift#4

Merged
u8array merged 1 commit into
mainfrom
fix/object-resize-jump
May 4, 2026
Merged

Fix QR code Y-offset drift and 1-dot resize drift#4
u8array merged 1 commit into
mainfrom
fix/object-resize-jump

Conversation

@u8array
Copy link
Copy Markdown
Owner

@u8array u8array commented May 4, 2026

Summary

Two resize bugs not covered by #3:

  1. QR code FO Y-offset driftBarcodeObject adds a hardcoded +10 dot Y-offset to QR codes (Zebra firmware artifact). handleDragEnd already inverts this, but onTransformEnd did not, so every resize accumulated a +10 dot drift in the stored model y.
  2. 1-dot resize drift on selected objects — selection stroke leaked into the Konva Transformer's bounding-box math; under scale-aware stroke handling this produced sub-pixel shifts in node.x()/y() that surfaced as 1-dot ZPL coordinate jumps after pxToDots rounding.

Changes

  • New pure helper modelPositionFromRenderedTopLeft in transformPosition.ts that inverts per-type render offsets (currently QR FO +10 dot Y). Mirrors the inversion BarcodeObject.handleDragEnd already does, so drag and resize stay consistent.
  • useKonvaTransformer.onTransformEnd calls the helper after transformNodeTopLeft (Fix/jumping ellipse #3) and before positionDidMove-gated snap.
  • ignoreStroke on the Transformer so the bbox is the geometric shape, not the stroke-padded visual.
  • 6 unit tests for the helper covering FO/FT QR variants and pass-through types.

Test plan

  • pnpm lint
  • pnpm test (424 passed)
  • npx tsc --noEmit
  • Manual: drag QR / Ellipse bottom-right repeatedly larger / smaller; coordinates stay stable

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 improves coordinate handling during canvas transformations by introducing modelPositionFromRenderedTopLeft to correctly invert render-time offsets for specific object types like QR codes and ellipses. It also adds ignoreStroke to the transformer to prevent coordinate drift caused by stroke padding. I have provided feedback suggesting the use of Konva-specific methods for better type safety when accessing ellipse radii and the use of Math.abs() to ensure the coordinate calculation remains robust if objects are flipped.

Comment thread src/components/Canvas/hooks/useKonvaTransformer.ts Outdated
Comment thread src/components/Canvas/hooks/useKonvaTransformer.ts Outdated
Exclude selection stroke from the bbox to prevent sub-dot drift. Adjust
Konva transformer logic to correctly calculate the rendered top-left for
ellipses, which are center-anchored. Introduce a new utility function
`modelPositionFromRenderedTopLeft` to handle per-object rendering
offsets, specifically addressing the +10 dot Y-offset for QR codes when
`positionType` is not 'FT'. This ensures accurate model position updates
after transformations.
@u8array u8array force-pushed the fix/object-resize-jump branch from d2847f8 to 49e3706 Compare May 4, 2026 21:06
@u8array
Copy link
Copy Markdown
Owner Author

u8array commented May 4, 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 addresses coordinate drift and positioning inaccuracies during object transformation on the canvas. Key changes include adding the ignoreStroke property to the Konva transformer to exclude selection strokes from bounding box calculations and introducing a modelPositionFromRenderedTopLeft utility to correctly invert render-time offsets (such as the QR code Y-offset) when updating model positions. Comprehensive tests for the new utility were also added. I have no feedback to provide as there were no review comments to evaluate.

@u8array u8array changed the title Fix ellipse scaling and QR code Y offset Fix QR code Y-offset drift and 1-dot resize drift May 4, 2026
@u8array u8array merged commit a7111f9 into main May 4, 2026
2 checks passed
@u8array u8array deleted the fix/object-resize-jump branch May 4, 2026 21:12
u8array added a commit that referenced this pull request May 22, 2026
Two style fixes folded together:
- em-dashes in new comments and UI strings replaced with colon/semicolon
  per repo writing-style convention; the Variable dropdown options now
  read `{name}: "{default}"`.
- row-error cleanup uses rest-spread destructure instead of a manual
  rebuild loop (Gemini PR-review suggestion #4). `void _drop`
  satisfies the unused-var lint.
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