Skip to content

Implement ray-casting based physical to logical layout conversion#16

Draft
Copilot wants to merge 7 commits intofeat/new-layout-convertfrom
copilot/create-layout-conversion-algorithm
Draft

Implement ray-casting based physical to logical layout conversion#16
Copilot wants to merge 7 commits intofeat/new-layout-convertfrom
copilot/create-layout-conversion-algorithm

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Converts physical key layouts (x, y, rotation coordinates) to logical grid positions (row, col integers) using ray-casting and clustering.

Algorithm

  • Ray-casting: Each key casts rays in cardinal directions to find potential neighbors
  • Clustering: Union-Find groups keys into row/column clusters based on neighbor relationships
  • Standard grid fast-path: Layouts with integer positions use direct position mapping
  • Gap detection: Large physical gaps (>1.5U) create empty rows/columns in output

Changes

  • src/lib/physicalToLogical.ts: New algorithm implementation
  • src/components/layouthelper.ts: Updated to use new physicalToLogical function
  • Reuses keyCenter from geometry.ts for center calculation

Example

import { physicalToLogical } from './lib/physicalToLogical';

// Physical layout with staggered keys
const keys = [
  { x: 0, y: 0, w: 1, h: 1 },
  { x: 1, y: 0.25, w: 1, h: 1 },  // staggered
  { x: 2, y: 0, w: 1, h: 1 },
];

physicalToLogical(keys);
// keys now have row/col assigned: [0,0], [0,1], [0,2]

Known Limitations

  • Complex column staggers (like Ferris thumb clusters) may not cluster correctly when Y offsets vary significantly across columns
  • Non-uniform key widths in non-grid layouts may over-segment columns

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

The new algorithm uses ray-casting and clustering to convert physical key positions to logical row/column assignments.

Key features:
- Ray-casting to find neighbor candidates in local coordinate space
- Bidirectional neighbor relationship validation
- Detection of conflicting relationships (keys seeing each other in the same direction)
- Union-Find based clustering for column and row groups
- Support for standard grids (integer positions) with position-based grouping
- Support for rotated/staggered layouts with neighbor-based clustering
- Gap detection to add empty columns/rows for large physical gaps
- Proper handling of non-uniform key sizes (2U, 3U keys)

Co-authored-by: Genteure <11240579+Genteure@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 30, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
shield-wizard 99e295a Commit Preview URL

Branch Preview URL
Jan 30 2026, 04:33 PM

- Fix nullish coalescing for rotation origin (rx/ry) to handle 0 values
- Remove unused second parameter from physicalToLogical call sites
- Extract magic numbers as named constants with documentation
- Improve code clarity with descriptive constant names

Co-authored-by: Genteure <11240579+Genteure@users.noreply.github.com>
Copilot AI changed the title [WIP] Add new algorithm for physical to logical layout conversion New ray-casting algorithm for physical to logical layout conversion Jan 30, 2026
Copilot AI requested a review from Genteure January 30, 2026 12:45
Copilot AI and others added 2 commits January 30, 2026 16:27
Co-authored-by: Genteure <11240579+Genteure@users.noreply.github.com>
Co-authored-by: Genteure <11240579+Genteure@users.noreply.github.com>
Copilot AI changed the title New ray-casting algorithm for physical to logical layout conversion Implement ray-casting based physical to logical layout conversion Jan 30, 2026
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.

2 participants