Corners of a rectangle, L or U room
64-bitThe corner list of a room from its width, depth and notch.
U notch start a = (W − notch w) ÷ 2
Sums and differences of the room sizes with one halving; nothing is rounded here. The notch is clamped to at least 1 and to 1 or 2 less than the side, in job units.
export function roomPts(room) {
const W = room.w, D = room.d;
const box = [[0, 0], [W, 0], [W, D], [0, D]];
if (room.shape === 'free' && Array.isArray(room.pts)) return room.pts.map((p) => [p[0], p[1]]);
const n = room.notch;
if (room.shape === 'L' && n) {
const nw = clamp(n.w, 1, W - 1), nd = clamp(n.d, 1, D - 1);
switch (n.at) {
case 'NW': return [[0, 0], [W, 0], [W, D], [nw, D], [nw, D - nd], [0, D - nd]];
case 'SE': return [[0, 0], [W - nw, 0], [W - nw, nd], [W, nd], [W, D], [0, D]];
case 'SW': return [[nw, 0], [W, 0], [W, D], [0, D], [0, nd], [nw, nd]];
default: return [[0, 0], [W, 0], [W, D - nd], [W - nw, D - nd], [W - nw, D], [0, D]]; // NE
}
}
if (room.shape === 'U' && n) {
const horiz = n.at === 'N' || n.at === 'S';
const nw = clamp(n.w, 1, (horiz ? W : D) - 2), nd = clamp(n.d, 1, (horiz ? D : W) - 1);
if (n.at === 'S') { const a = (W - nw) / 2; return [[0, 0], [a, 0], [a, nd], [a + nw, nd], [a + nw, 0], [W, 0], [W, D], [0, D]]; }
if (n.at === 'E') { const a = (D - nw) / 2; return [[0, 0], [W, 0], [W, a], [W - nd, a], [W - nd, a + nw], [W, a + nw], [W, D], [0, D]]; }
if (n.at === 'W') { const a = (D - nw) / 2; return [[0, 0], [W, 0], [W, D], [0, D], [0, a + nw], [nd, a + nw], [nd, a], [0, a]]; }
const a = (W - nw) / 2; // N
return [[0, 0], [W, 0], [W, D], [a + nw, D], [a + nw, D - nd], [a, D - nd], [a, D], [0, D]];
}
return box;
}