Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x | /**
* Coordinate conversion utilities (world <-> screen) for 1D and 2D.
*
* The 1D functions match the existing numberToScreenX / screenXToNumber
* from numberLineTicks.ts. The 2D wrappers extend them for the coordinate plane.
*/
// ── 1D conversions ──────────────────────────────────────────────────
/** Convert a world value to a screen coordinate along one axis */
export function worldToScreen(
value: number,
center: number,
pixelsPerUnit: number,
extent: number
): number {
return (value - center) * pixelsPerUnit + extent / 2
}
/** Convert a screen coordinate to a world value along one axis */
export function screenToWorld(
screenPos: number,
center: number,
pixelsPerUnit: number,
extent: number
): number {
return (screenPos - extent / 2) / pixelsPerUnit + center
}
// ── 2D conversions ──────────────────────────────────────────────────
export interface Point2D {
x: number
y: number
}
/**
* Convert a world (x,y) to screen coordinates.
* Note: Y is inverted so positive Y goes up on screen.
*/
export function worldToScreen2D(
worldX: number,
worldY: number,
centerX: number,
centerY: number,
ppuX: number,
ppuY: number,
canvasWidth: number,
canvasHeight: number
): Point2D {
return {
x: (worldX - centerX) * ppuX + canvasWidth / 2,
y: canvasHeight / 2 - (worldY - centerY) * ppuY,
}
}
/**
* Convert screen (x,y) to world coordinates.
* Note: Y is inverted so positive screen Y maps to negative world Y offset.
*/
export function screenToWorld2D(
screenX: number,
screenY: number,
centerX: number,
centerY: number,
ppuX: number,
ppuY: number,
canvasWidth: number,
canvasHeight: number
): Point2D {
return {
x: (screenX - canvasWidth / 2) / ppuX + centerX,
y: (canvasHeight / 2 - screenY) / ppuY + centerY,
}
}
|