Files
photoreport/apps/api/test/face-frame.test.ts
spark ff8488fd93
ci / rust (push) Successful in 16m17s
ci / typescript (push) Failing after 16m55s
Kiosk with photobooth on a tablet, Windows print agent, face boxes that follow the crop
Impressão → Quiosque: a secret link for a tablet (photographer's photos, front camera photobooth, name and copies; paid prints at the counter). Print agent: Windows spooler through PowerShell. Loupe: face boxes in the edited preview's frame.

Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
2026-10-13 11:29:23 +01:00

40 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { insideRotated } from "../src/composition/geometry.js";
import { boxInCrop, cropOfSettings } from "../src/faces/frame.js";
describe("face boxes on edited previews", () => {
it("leaves an uncropped photo alone", () => {
const box = { x0: 0.2, y0: 0.2, x1: 0.3, y1: 0.35 };
expect(boxInCrop(box, cropOfSettings({ crop: { geometry: { rect: { x0: 0, y0: 0, x1: 1, y1: 1 }, angle: 0 } } }), 6000, 4000)).toEqual(box);
expect(cropOfSettings(null)).toBeNull();
});
it("moves and scales the box into the crop, and drops faces left outside", () => {
const crop = cropOfSettings({ crop: { geometry: { rect: { x0: 0.25, y0: 0.2, x1: 0.75, y1: 0.7 } } } })!;
const inside = boxInCrop({ x0: 0.5, y0: 0.4, x1: 0.55, y1: 0.5 }, crop, 6000, 4000)!;
expect(inside.x0).toBeCloseTo(0.5);
expect(inside.y0).toBeCloseTo(0.4);
expect(inside.x1).toBeCloseTo(0.6);
expect(inside.y1).toBeCloseTo(0.6);
expect(boxInCrop({ x0: 0.05, y0: 0.1, x1: 0.1, y1: 0.15 }, crop, 6000, 4000)).toBeNull();
// Cut by the crop's edge: clipped.
expect(boxInCrop({ x0: 0.2, y0: 0.3, x1: 0.3, y1: 0.4 }, crop, 6000, 4000)!.x0).toBe(0);
});
it("follows the straighten angle the same way the crop is checked against the photo", () => {
const crop = { rect: { x0: 0.1, y0: 0.1, x1: 0.9, y1: 0.9 }, angle: 5 };
// A tiny box at a point of the original lands where insideRotated (straightened -> original) would send it back.
const p = boxInCrop({ x0: 0.7, y0: 0.3, x1: 0.7, y1: 0.3 }, { rect: { x0: 0, y0: 0, x1: 1, y1: 1 }, angle: 5 }, 6000, 4000)!;
expect(insideRotated({ x0: p.x0, y0: p.y0, x1: p.x0, y1: p.y0 }, 5, 6000, 4000)).toBe(true);
const back = (() => {
const a = (-5 * Math.PI) / 180;
const px = p.x0 * 6000 - 3000;
const py = p.y0 * 4000 - 2000;
return [(px * Math.cos(a) - py * Math.sin(a) + 3000) / 6000, (px * Math.sin(a) + py * Math.cos(a) + 2000) / 4000];
})();
expect(back[0]).toBeCloseTo(0.7, 6);
expect(back[1]).toBeCloseTo(0.3, 6);
expect(boxInCrop({ x0: 0.45, y0: 0.45, x1: 0.55, y1: 0.55 }, crop, 6000, 4000)).not.toBeNull();
});
});