fix: keep flipped openings on wall centerline

Issue: #250
User-Visible: yes
This commit is contained in:
Sergey Matyunin
2026-08-23 01:59:26 +03:00
parent 2534916c94
commit 0eb9ffe480
24 changed files with 341 additions and 334 deletions
+19 -20
View File
@@ -5,26 +5,25 @@ import { openingSymbolOffset } from '../test-build/opening-symbol-placement.js';
const positiveFace = { ox: 0, oy: 20, cm: 20, side: 1 };
const negativeFace = { ox: 0, oy: -20, cm: 20, side: -1 };
test('default opening symbols stay centred regardless of the resolved room face', () => {
test('every opening symbol stays exactly on the wall centreline', () => {
const faces = [
positiveFace,
negativeFace,
{ ox: 20, oy: 0, cm: 20, side: 1 },
{ ox: 0, oy: 0, cm: 0, side: -1 },
{ ox: Infinity, oy: NaN, cm: 20, side: 1 },
];
for (const type of ['door', 'window', 'gate', 'passage']) {
assert.deepEqual(openingSymbolOffset(type, false, 0, positiveFace), { ox: 0, oy: 0 });
assert.deepEqual(openingSymbolOffset(type, false, 0, negativeFace), { ox: 0, oy: 0 });
for (const flip of [false, true]) {
for (const angle of [0, 45, 90, -135, NaN]) {
for (const face of faces) {
assert.deepEqual(
openingSymbolOffset(type, flip, angle, face),
{ ox: 0, oy: 0 },
`${type} flip=${flip} angle=${angle} face=${face.ox},${face.oy}`,
);
}
}
}
}
});
test('saved door and window flips use one canonical local edge', () => {
for (const type of ['door', 'window']) {
assert.deepEqual(openingSymbolOffset(type, true, 0, positiveFace), { ox: 0, oy: 20 });
assert.deepEqual(openingSymbolOffset(type, true, 0, negativeFace), { ox: 0, oy: 20 });
const diagonal = openingSymbolOffset(type, true, 90, positiveFace);
assert.ok(Math.abs(diagonal.ox + 20) < 1e-9);
assert.ok(Math.abs(diagonal.oy) < 1e-9);
}
});
test('gate leaves never translate and malformed faces fail centred', () => {
assert.deepEqual(openingSymbolOffset('gate', true, 0, positiveFace), { ox: 0, oy: 0 });
assert.deepEqual(openingSymbolOffset('gate', true, 45, negativeFace), { ox: 0, oy: 0 });
assert.deepEqual(openingSymbolOffset('door', true, NaN, positiveFace), { ox: 0, oy: 0 });
assert.deepEqual(openingSymbolOffset('window', true, 0, { ox: 0, oy: 0 }), { ox: 0, oy: 0 });
});