..
This commit is contained in:
parent
9689bfcc18
commit
62a385e4c9
33 changed files with 2649 additions and 809 deletions
|
|
@ -1,7 +1,9 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { fireplace } from '../src/lib/defaults';
|
||||
import { buildGeometry } from '../src/lib/geometry';
|
||||
import { dimensionLabels } from '../src/lib/dimension-labels';
|
||||
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);
|
||||
|
|
@ -19,3 +21,32 @@ describe('wall dimensions', () => {
|
|||
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);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue