caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

45 lines
1.4 KiB
TypeScript

/** Snap guides: align a moving box's edges/centre to the page and to other layers. */
export interface Box {
x: number;
y: number;
width: number;
height: number;
}
export interface SnapResult {
x: number;
y: number;
/** Guide positions in page units (vertical lines at x, horizontal lines at y). */
guidesX: number[];
guidesY: number[];
}
function best(points: number[], targets: number[], threshold: number): { delta: number; at: number } | null {
let found: { delta: number; at: number } | null = null;
for (const p of points) {
for (const t of targets) {
const d = t - p;
if (Math.abs(d) <= threshold && (!found || Math.abs(d) < Math.abs(found.delta))) found = { delta: d, at: t };
}
}
return found;
}
export function snapBox(box: Box, others: Box[], page: { width: number; height: number }, threshold: number): SnapResult {
const xs = [0, page.width / 2, page.width];
const ys = [0, page.height / 2, page.height];
for (const o of others) {
xs.push(o.x, o.x + o.width / 2, o.x + o.width);
ys.push(o.y, o.y + o.height / 2, o.y + o.height);
}
const sx = best([box.x, box.x + box.width / 2, box.x + box.width], xs, threshold);
const sy = best([box.y, box.y + box.height / 2, box.y + box.height], ys, threshold);
return {
x: box.x + (sx?.delta ?? 0),
y: box.y + (sy?.delta ?? 0),
guidesX: sx ? [sx.at] : [],
guidesY: sy ? [sy.at] : [],
};
}