feat(cameras): crossing line editor in Setup (A→B / B→A / A↔B)
Our own line-crossing rule for cameras that have none: draw a segment over the camera's live picture, sides A and B, and pick which crossing counts. Stored as camera config.crossing (CrossingLine in @parking/shared, points normalised to the frame, side A on the screen-left of p1→p2), validated on save; null clears it. Nothing consumes it yet (passage confirmation). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RZgP5oMncSaVmKRKk1UvN4
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { crossingSide, parseCrossingLine, type CrossingLine } from "./index.js";
|
||||
|
||||
// A horizontal line drawn left→right across the middle of the frame.
|
||||
const line: CrossingLine = { p1: { x: 0.1, y: 0.5 }, p2: { x: 0.9, y: 0.5 }, direction: "a-to-b" };
|
||||
|
||||
describe("crossingSide", () => {
|
||||
it("puts the screen-left of p1→p2 on side A (above a left→right line)", () => {
|
||||
expect(crossingSide(line, { x: 0.5, y: 0.2 })).toBe("a");
|
||||
expect(crossingSide(line, { x: 0.5, y: 0.8 })).toBe("b");
|
||||
});
|
||||
it("swapping the points swaps the sides", () => {
|
||||
const swapped = { ...line, p1: line.p2, p2: line.p1 };
|
||||
expect(crossingSide(swapped, { x: 0.5, y: 0.2 })).toBe("b");
|
||||
});
|
||||
it("is null exactly on the line", () => {
|
||||
expect(crossingSide(line, { x: 0.3, y: 0.5 })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseCrossingLine", () => {
|
||||
it("accepts a valid line", () => {
|
||||
expect(parseCrossingLine(line)).toEqual(line);
|
||||
});
|
||||
it("rejects out-of-frame points, unknown directions and a click-length line", () => {
|
||||
expect(parseCrossingLine({ ...line, p1: { x: -0.1, y: 0.5 } })).toBeNull();
|
||||
expect(parseCrossingLine({ ...line, direction: "up" })).toBeNull();
|
||||
expect(parseCrossingLine({ ...line, p2: { x: 0.11, y: 0.5 } })).toBeNull();
|
||||
expect(parseCrossingLine(null)).toBeNull();
|
||||
expect(parseCrossingLine({ p1: { x: "0.1", y: 0.5 }, p2: line.p2, direction: "both" })).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user