feat: Rounding coordinates

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs
2026-06-22 14:39:39 +02:00
parent 28a9b1711d
commit 435b4a1684
15 changed files with 537 additions and 522 deletions
+12 -2
View File
@@ -1,4 +1,4 @@
import { average } from "@excalidraw/math";
import { average, round } from "@excalidraw/math";
import type { GlobalCoord } from "@excalidraw/math";
@@ -429,11 +429,21 @@ export const viewportCoordsToSceneCoords = (
scrollX: number;
scrollY: number;
},
decimals: number = 2,
) => {
const x = (clientX - offsetLeft) / zoom.value - scrollX;
const y = (clientY - offsetTop) / zoom.value - scrollY;
return { x, y } as GlobalCoord;
if (decimals === 0) {
return toBrandedType<GlobalCoord>({ x, y });
}
const precision = Math.pow(10, decimals);
return toBrandedType<GlobalCoord>({
x: round(x, precision),
y: round(y, precision),
});
};
export const sceneCoordsToViewportCoords = (