Files
SnapOtter/tests/unit/web/sign-geometry.test.ts
T
SnapOtterandGitHub 0cdd560ac4 feat: add Sign PDF tool (draw/type/upload signatures, place on a PDF) (#370)
Draw, type, or upload a signature and place resizable/rotatable copies across PDF pages; output flattened server-side with PyMuPDF. Visual electronic signature, not cryptographic. New interactive-sign display mode (pdf.js + Konva) and a custom docs-pool route.
2026-06-29 11:01:25 +08:00

30 lines
924 B
TypeScript

import { describe, expect, it } from "vitest";
import { rotatedBoundingBox, toNormalizedRect } from "@/lib/sign-geometry";
describe("sign-geometry", () => {
it("normalizes a pixel rect against the render size", () => {
expect(toNormalizedRect({ x: 50, y: 100, w: 25, h: 10 }, 100, 200)).toEqual({
x: 0.5,
y: 0.5,
w: 0.25,
h: 0.05,
});
});
it("bounding box of an unrotated rect is unchanged", () => {
expect(rotatedBoundingBox(40, 20, 0)).toEqual({ w: 40, h: 20 });
});
it("bounding box of a 90deg rotation swaps w/h", () => {
const b = rotatedBoundingBox(40, 20, 90);
expect(b.w).toBeCloseTo(20, 5);
expect(b.h).toBeCloseTo(40, 5);
});
it("bounding box grows for a 45deg rotation", () => {
const b = rotatedBoundingBox(40, 20, 45);
expect(b.w).toBeCloseTo((40 + 20) / Math.SQRT2, 5);
expect(b.h).toBeCloseTo((40 + 20) / Math.SQRT2, 5);
});
});