reviewed
This commit is contained in:
parent
62a385e4c9
commit
7959fe85cc
29 changed files with 1679 additions and 498 deletions
67
tests/piece-labels.test.ts
Normal file
67
tests/piece-labels.test.ts
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { defaultProject, fireplace } from '../src/lib/defaults';
|
||||
import { buildGeometry } from '../src/lib/geometry';
|
||||
import { planFlooring } from '../src/lib/flooring';
|
||||
import { floorPieceLabels } from '../src/lib/piece-labels';
|
||||
|
||||
describe('floorplan piece labels', () => {
|
||||
const room = fireplace('room-2', 'Room 2');
|
||||
const settings = {
|
||||
...defaultProject().flooring,
|
||||
pattern: 'random' as const,
|
||||
minOffset: 100,
|
||||
maxOffset: 1000,
|
||||
minLength: 10,
|
||||
minWidth: 0.1,
|
||||
};
|
||||
const plan = planFlooring([room], settings, 10);
|
||||
const geometry = buildGeometry(room, 10);
|
||||
const cuts = plan.pieces.filter((piece) => piece.cut || piece.reused);
|
||||
|
||||
it('labels short positive cuts without covering neighboring labels or changing their geometry', () => {
|
||||
const before = structuredClone(plan.pieces);
|
||||
const labels = floorPieceLabels(plan.pieces, geometry.vertices, 0, 4800 * 0.024);
|
||||
expect(labels.map((label) => label.id)).toEqual(cuts.map((piece) => piece.id));
|
||||
const small = cuts.filter((piece) => piece.length < 180);
|
||||
expect(small.length).toBeGreaterThan(0);
|
||||
for (const piece of small) {
|
||||
expect(piece.length).toBeGreaterThan(0);
|
||||
expect(piece.width).toBeGreaterThan(0);
|
||||
expect(labels.find((label) => label.id === piece.id)!.leader).toBe(true);
|
||||
}
|
||||
for (const [index, label] of labels.entries()) {
|
||||
expect(label.box.minX).toBeGreaterThanOrEqual(0);
|
||||
expect(label.box.maxX).toBeLessThanOrEqual(4800);
|
||||
for (const other of labels.slice(index + 1)) {
|
||||
expect(
|
||||
label.box.minX >= other.box.maxX ||
|
||||
label.box.maxX <= other.box.minX ||
|
||||
label.box.minY >= other.box.maxY ||
|
||||
label.box.maxY <= other.box.minY,
|
||||
).toBe(true);
|
||||
}
|
||||
}
|
||||
expect(plan.pieces).toEqual(before);
|
||||
expect(floorPieceLabels(plan.pieces, geometry.vertices, 0, 4800 * 0.024)).toEqual(labels);
|
||||
});
|
||||
|
||||
it('allows space for complete three-digit codes and completion marks in either direction', () => {
|
||||
const piece = { ...cuts[0], id: 'F999' };
|
||||
for (const direction of [0, 90] as const) {
|
||||
const plain = floorPieceLabels([piece], geometry.vertices, direction, 100)[0];
|
||||
const done = floorPieceLabels(
|
||||
[piece],
|
||||
geometry.vertices,
|
||||
direction,
|
||||
100,
|
||||
[],
|
||||
[`floor:${piece.stockId}`],
|
||||
)[0];
|
||||
expect(done.text).toBe('F999 ✓');
|
||||
expect(done.width).toBeGreaterThan(plain.width);
|
||||
expect(done.angle).toBe(direction);
|
||||
expect(done.box.maxX - done.box.minX).toBeCloseTo(direction === 0 ? done.width : done.height);
|
||||
expect(done.box.maxY - done.box.minY).toBeCloseTo(direction === 0 ? done.height : done.width);
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue