52 lines
2.3 KiB
TypeScript
52 lines
2.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { fireplace } from '../src/lib/defaults';
|
|
import { buildGeometry } from '../src/lib/geometry';
|
|
import { dimensionLabels, wallDimensionBox } from '../src/lib/dimension-labels';
|
|
import fixture from './fixtures/angled-room.json';
|
|
import type { Room } from '../src/lib/types';
|
|
describe('wall dimensions', () => {
|
|
it('keeps fireplace recess measurements apart without changing measured lengths', () => {
|
|
const geometry = buildGeometry(fireplace('room-1', 'Fireplace'), 10);
|
|
const labels = dimensionLabels(geometry.edges, 4800, 1);
|
|
expect(labels).toHaveLength(8);
|
|
expect(labels[3].text).toBe('W4 · 450');
|
|
for (let i = 0; i < labels.length; i++)
|
|
for (let j = i + 1; j < labels.length; j++) {
|
|
const a = labels[i].box,
|
|
b = labels[j].box;
|
|
expect(a.minX >= b.maxX || a.maxX <= b.minX || a.minY >= b.maxY || a.maxY <= b.minY).toBe(
|
|
true,
|
|
);
|
|
}
|
|
expect(dimensionLabels(geometry.edges, 4800, 1)).toEqual(labels);
|
|
});
|
|
});
|
|
|
|
// Regression for the supplied 12-wall plan: W12's outward line crossed the old viewport.
|
|
it('includes the complete diagonal W12 dimension, not only its midpoint label', () => {
|
|
const room = fixture.project.rooms[0] as Room;
|
|
const geometry = buildGeometry(room, fixture.project.tolerance);
|
|
const xs = geometry.vertices.map((p) => p.x),
|
|
ys = geometry.vertices.map((p) => p.y);
|
|
const span = Math.max(Math.max(...xs) - Math.min(...xs), Math.max(...ys) - Math.min(...ys));
|
|
const labels = dimensionLabels(geometry.edges, span, 1);
|
|
const edge = geometry.edges[11],
|
|
label = labels[11];
|
|
const box = wallDimensionBox(edge, label, span);
|
|
expect(label.text).toBe('W12 · 6,097');
|
|
const end = {
|
|
x: edge.end.x + label.normal.x * label.offset,
|
|
y: edge.end.y + label.normal.y * label.offset,
|
|
};
|
|
expect(end.x).toBeLessThan(Math.min(...xs));
|
|
expect(box.minX).toBeLessThan(end.x);
|
|
expect(box.maxX).toBeGreaterThan(label.box.maxX - 1e-6);
|
|
for (const point of [edge.start, edge.end]) {
|
|
const x = point.x + label.normal.x * label.offset,
|
|
y = point.y + label.normal.y * label.offset;
|
|
expect(x).toBeGreaterThanOrEqual(box.minX);
|
|
expect(x).toBeLessThanOrEqual(box.maxX);
|
|
expect(y).toBeGreaterThanOrEqual(box.minY);
|
|
expect(y).toBeLessThanOrEqual(box.maxY);
|
|
}
|
|
});
|