Keep snap helper safe without context (#1828)

This commit is contained in:
red person
2026-06-29 10:54:44 -07:00
committed by GitHub
parent d2a6d73aa5
commit 00dfd2d47a
2 changed files with 26 additions and 2 deletions
+4 -2
View File
@@ -23,8 +23,10 @@
* @returns {{x: number, y: number, guides: Array}}
*/
export function computeSnap(layer, nx, ny, ctx) {
const SNAP_PX = 6 / Math.max(ctx.zoom, 0.0001);
const cw = ctx.canvasW, ch = ctx.canvasH;
if (!layer || !layer.canvas || !ctx) return { x: nx, y: ny, guides: [] };
const zoom = Number.isFinite(Number(ctx.zoom)) ? Number(ctx.zoom) : 1;
const SNAP_PX = 6 / Math.max(zoom, 0.0001);
const cw = Number(ctx.canvasW) || 0, ch = Number(ctx.canvasH) || 0;
const w = layer.canvas.width, h = layer.canvas.height;
const vTargets = [