Skip to content

fix: honor an explicit zero rotation origin for keys#175

Open
numachang wants to merge 1 commit into
zmkfirmware:mainfrom
numachang:upstream-fix/rotated-key-origin
Open

fix: honor an explicit zero rotation origin for keys#175
numachang wants to merge 1 commit into
zmkfirmware:mainfrom
numachang:upstream-fix/rotated-key-origin

Conversation

@numachang

Copy link
Copy Markdown

Problem

Fixes #97.

Keys with a rotation (r != 0) whose rotation origin rx/ry is explicitly 0 are pivoted around each key's own corner instead of the layout origin (0,0). On boards that rotate clusters about the origin this scrambles the layout, as reported in #97.

The cause is in scalePosition:

let transformX = ((rx || x) - x) * oneU;
let transformY = ((ry || y) - y) * oneU;

rx || x treats a legitimate 0 as falsy and falls back to the key's own x, so transformX becomes 0 (pivot at the key's own corner) instead of -x * oneU (pivot at the layout origin).

Fix

Use ?? so an explicit 0 is preserved:

let transformX = ((rx ?? x) - x) * oneU;
let transformY = ((ry ?? y) - y) * oneU;

When rx/ry are non-zero or omitted the behavior is unchanged; only the explicit-zero case is corrected.

Verification

Verified locally in Storybook with a layout containing a thumb cluster rotated about a shared origin plus a key rotated about (0,0): rotated clusters stay connected and the zero-origin key is positioned correctly. tsc and eslint are clean.

🤖 Generated with Claude Code

Keys with a rotation (r != 0) whose origin rx/ry is explicitly 0 were
pivoted around each key's own corner instead of the layout origin (0,0),
scrambling rotated clusters on boards that rotate about the origin.

`(rx || x)` collapsed a legitimate 0 back to the key's own x; switching to
`(rx ?? x)` keeps an explicit 0 as 0.

Fixes zmkfirmware#97

Co-Authored-By: Claude <noreply@anthropic.com>
@netlify

netlify Bot commented May 30, 2026

Copy link
Copy Markdown

Deploy Preview for zmk-studio ready!

Name Link
🔨 Latest commit 3b9f081
🔍 Latest deploy log https://app.netlify.com/projects/zmk-studio/deploys/6a1af21022439a0008344c6a
😎 Deploy Preview https://deploy-preview-175.preview.zmk.studio
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

Incorrect key positioning for rotated keys

1 participant