Das Marquee (Aufziehen eines Auswahl-Rechtecks) las bisher nur wallId/ drawingId aus den Polygon-Primitiven aus — Decken/Räume/Treppen trugen zwar längst ceilingId/roomId/stairId in denselben Primitiven, wurden aber nie ausgewertet und beim Aufziehen sogar aktiv abgewählt (war im Code bereits als bekannte Lücke kommentiert).
69 lines
2.8 KiB
TypeScript
69 lines
2.8 KiB
TypeScript
/**
|
|
* `marqueeHitCeilings`/`marqueeHitRooms`/`marqueeHitStairs` — Nutzer-Report:
|
|
* "Auswahlrahmen kann nicht alle Elemente anwählen, z.B. Decken, Räume und
|
|
* Treppen nicht". Vorher las das Auswahl-Rechteck nur `wallId`/`drawingId`
|
|
* aus den Polygon-Primitiven; die anderen ID-Felder (die dieselben
|
|
* Primitive längst tragen) wurden ignoriert.
|
|
*/
|
|
|
|
import { describe, it, expect } from "vitest";
|
|
import { marqueeHit, marqueeHitCeilings, marqueeHitRooms, marqueeHitStairs } from "./geometry";
|
|
import type { Primitive } from "../generatePlan";
|
|
|
|
const NO_HATCH = { pattern: "none" as const, color: "#000" };
|
|
|
|
function poly(id: Partial<Record<"wallId" | "ceilingId" | "roomId" | "stairId", string>>, pts: { x: number; y: number }[]): Primitive {
|
|
return {
|
|
kind: "polygon",
|
|
pts,
|
|
fill: "none",
|
|
stroke: "#000",
|
|
strokeWidthMm: 0.18,
|
|
hatch: NO_HATCH,
|
|
...id,
|
|
} as Primitive;
|
|
}
|
|
|
|
const square = (x0: number, y0: number, x1: number, y1: number) => [
|
|
{ x: x0, y: y0 }, { x: x1, y: y0 }, { x: x1, y: y1 }, { x: x0, y: y1 },
|
|
];
|
|
|
|
describe("Marquee — Decken/Räume/Treppen", () => {
|
|
it("marqueeHitCeilings findet eine vollständig eingeschlossene Decke (window)", () => {
|
|
const prims = [poly({ ceilingId: "c1" }, square(1, 1, 3, 3))];
|
|
const rect = { minX: 0, minY: 0, maxX: 5, maxY: 5 };
|
|
expect(marqueeHitCeilings(prims, rect, false)).toEqual(["c1"]);
|
|
});
|
|
|
|
it("marqueeHitRooms ignoriert einen Raum, der nur teilweise im Fenster liegt (window, kein crossing)", () => {
|
|
const prims = [poly({ roomId: "r1" }, square(1, 1, 10, 10))];
|
|
const rect = { minX: 0, minY: 0, maxX: 5, maxY: 5 };
|
|
expect(marqueeHitRooms(prims, rect, false)).toEqual([]);
|
|
// Dieselbe Geometrie im Crossing-Modus (rechts→links) trifft trotzdem.
|
|
expect(marqueeHitRooms(prims, rect, true)).toEqual(["r1"]);
|
|
});
|
|
|
|
it("marqueeHitStairs findet eine Treppe über mehrere Tritt-Polygone (alle müssen im Fenster liegen)", () => {
|
|
const prims = [
|
|
poly({ stairId: "s1" }, square(1, 1, 2, 2)),
|
|
poly({ stairId: "s1" }, square(2, 1, 3, 2)),
|
|
];
|
|
const rect = { minX: 0, minY: 0, maxX: 5, maxY: 5 };
|
|
expect(marqueeHitStairs(prims, rect, false)).toEqual(["s1"]);
|
|
});
|
|
|
|
it("Wände (marqueeHit) und Decken/Räume/Treppen sind unabhängig voneinander auswertbar", () => {
|
|
const prims = [
|
|
poly({ wallId: "w1" }, square(0, 0, 1, 1)),
|
|
poly({ ceilingId: "c1" }, square(1, 1, 2, 2)),
|
|
poly({ roomId: "r1" }, square(2, 2, 3, 3)),
|
|
poly({ stairId: "s1" }, square(3, 3, 4, 4)),
|
|
];
|
|
const rect = { minX: 0, minY: 0, maxX: 5, maxY: 5 };
|
|
expect(marqueeHit(prims, rect, false)).toEqual(["w1"]);
|
|
expect(marqueeHitCeilings(prims, rect, false)).toEqual(["c1"]);
|
|
expect(marqueeHitRooms(prims, rect, false)).toEqual(["r1"]);
|
|
expect(marqueeHitStairs(prims, rect, false)).toEqual(["s1"]);
|
|
});
|
|
});
|