This commit is contained in:
Andras Schmelczer 2026-09-11 22:14:24 +01:00
commit 0c0f08b350
45 changed files with 1565 additions and 1579 deletions

View file

@ -9,6 +9,7 @@ import {
import baseline from '../benchmarks/baseline.json';
import { planFlooringOptions } from '../src/lib/flooring';
import { planSkirting } from '../src/lib/skirting';
import { defaultProject, rectangle } from '../src/lib/defaults';
import { buildGeometry, insetPolygon, signedArea } from '../src/lib/geometry';
import type { FlooringPlan, Project } from '../src/lib/types';
@ -29,7 +30,7 @@ function validateFlooring(plan: FlooringPlan, project: Project) {
stock.pieceIds.forEach((id, index) => {
const piece = byId.get(id)!;
expect(piece.stockId).toBe(stock.id);
expect(piece.blankLength!).toBeLessThanOrEqual(remaining + 0.01);
expect(piece.blankLength).toBeLessThanOrEqual(remaining + 0.01);
expect(!piece.factoryLeft || left).toBe(true);
expect(!piece.factoryRight || right).toBe(true);
expect(piece.reused).toBe(index > 0);
@ -38,7 +39,7 @@ function validateFlooring(plan: FlooringPlan, project: Project) {
crosscuts += Number(cut);
expect(piece.cut).toBe(cut || piece.shaped || !!piece.ripEdge);
if (cut) {
remaining = Math.round(Math.max(0, remaining - piece.blankLength! - s.kerf) * 1000) / 1000;
remaining = Math.round(Math.max(0, remaining - piece.blankLength - s.kerf) * 1000) / 1000;
if (piece.factoryRight) right = false;
else left = false;
} else {
@ -136,9 +137,21 @@ describe('measured optimiser quality', () => {
totals.pattern += flooringMetrics(options.random, c.project.flooring).patternPenalty;
totals.skirtingCuts += skirt.cuts;
}
expect(totals.cuts).toBeLessThanOrEqual(1840); // Original: 2177.
expect(totals.randomCuts).toBeLessThanOrEqual(2130);
expect(totals.pattern).toBeLessThanOrEqual(129); // Original: 265.
expect(totals.cuts).toBeLessThanOrEqual(1741); // Original: 2177.
expect(totals.randomCuts).toBeLessThanOrEqual(1994);
expect(totals.pattern).toBeLessThanOrEqual(113); // Original: 265.
expect(totals.skirtingCuts).toBeLessThanOrEqual(1436); // Original: 1447.
});
it('packs reserved offcuts before applying the 2000-board cap on a 500-row floor', () => {
const project = defaultProject();
project.flooring.pattern = 'brick';
project.rooms = [rectangle('limit', 'Limit', 4520, 95020)];
const plan = planFlooringOptions(project.rooms, project.flooring, 1).cuts;
expect(plan.issues.filter((issue) => issue.severity === 'error')).toEqual([]);
expect(plan.rows).toHaveLength(500);
expect(plan.boardCount).toBe(2000);
expect(plan.cuts).toBe(750);
expect(plan.coveredArea).toBe(4500 * 95000);
});
});