The AI-native screen recorder. Record your screen and talk; the people you share it with and your AI agents both get it.
Rust agent-readableai-agentsarecclaude-codecodexcursorlocal-firstmacosprivacyrustscreen-recorderscreen-recordingtauritranscriptiontypescriptwindows
import { describe, expect, it } from "vitest";
import {
clampPoint,
displayContaining,
isUsableSelection,
moveRect,
rectFromPoints,
resizeRect,
roundRect,
} from "../src/lib/areaSelectGeometry";
const bounds = { width: 100, height: 80 };
const box = { x: 20, y: 15, width: 40, height: 30 };
describe("area selection", () => {
it("clamps a reverse drag to the display and keeps its size positive", () => {
const anchor = { x: 70, y: 10 };
const end = clampPoint({ x: -5, y: 90 }, bounds);
const expected = { x: 0, y: 10, width: 70, height: 70 };
expect(rectFromPoints(anchor, end)).toEqual(expected);
expect(rectFromPoints(end, anchor)).toEqual(expected);
});
it("keeps the far edges inside the display when confirming a fractional selection", () => {
const drag = rectFromPoints({ x: 10.5, y: 15.5 }, { x: 100, y: 80 });
expect(roundRect(drag)).toEqual({ x: 11, y: 16, width: 89, height: 64 });
});
it("requires at least eight pixels on both axes", () => {
expect(isUsableSelection({ ...box, width: 8, height: 8 })).toBe(true);
expect(isUsableSelection({ ...box, width: 7.9 })).toBe(false);
expect(isUsableSelection({ ...box, height: 7.9 })).toBe(false);
});
it("moves the whole box until an edge reaches the display", () => {
expect(moveRect(box, { x: 4, y: -6 }, bounds)).toEqual({ ...box, x: 24, y: 9 });
expect(moveRect(box, { x: 100, y: -100 }, bounds)).toEqual({ ...box, x: 60, y: 0 });
expect(moveRect(box, { x: -100, y: 100 }, bounds)).toEqual({ ...box, x: 0, y: 50 });
});
it.each([
["n", { x: 50, y: 100 }, { x: 20, y: 37, width: 40, height: 8 }],
["w", { x: 100, y: 50 }, { x: 52, y: 15, width: 8, height: 30 }],
["e", { x: 100, y: 50 }, { x: 20, y: 15, width: 80, height: 30 }],
["s", { x: 50, y: 100 }, { x: 20, y: 15, width: 40, height: 65 }],
["nw", { x: -100, y: -100 }, { x: 0, y: 0, width: 60, height: 45 }],
["ne", { x: 9, y: -3 }, { x: 20, y: 12, width: 49, height: 33 }],
["sw", { x: 100, y: -100 }, { x: 52, y: 15, width: 8, height: 8 }],
["se", { x: -100, y: -100 }, { x: 20, y: 15, width: 8, height: 8 }],
] as const)("resizes the %s grip while keeping the opposite edges fixed", (handle, delta, expected) => {
expect(resizeRect(box, handle, delta, bounds)).toEqual(expected);
});
it("locates the cursor on offset displays using half-open bounds", () => {
const left = { id: 2, x: -1280, y: -120, width: 1280, height: 900 };
const main = { id: 1, x: 0, y: 0, width: 1440, height: 900 };
const displays = [left, main];
expect(displayContaining(displays, { x: -0.5, y: 0 })).toEqual(left);
expect(displayContaining(displays, { x: 0, y: 0 })).toEqual(main);
expect(displayContaining(displays, { x: 0, y: -10 })).toBeNull();
expect(displayContaining(displays, { x: 0, y: 900 })).toBeNull();
expect(displayContaining(displays, null)).toBeNull();
});
});