Boxes of the things that move
64-bitThe plan box of each wall, drawn floor, column and placed item.
wall corners = end ± n × t ÷ 2
A wall's box is its two ends moved half its thickness to each side; a curved wall is taken from its two ends, not from its arc. A column's corners are turned by its angle with one cosine and sine each; a placed item's box is its insertion point.
/** The walls' outline (centre line ± half the thickness at each end), floors' points, columns' corners, items' insertion point. */
export function movables(w, storey = null) {
const out = [];
for (const x of readWalls(w, storey)) {
const L = Math.hypot(x.b[0] - x.a[0], x.b[1] - x.a[1]) || 1, n = [-(x.b[1] - x.a[1]) / L * x.t / 2, (x.b[0] - x.a[0]) / L * x.t / 2];
out.push({ kind: 'wall', guid: x.guid, storey: x.storey, box: boxOfPts([[x.a[0] + n[0], x.a[1] + n[1]], [x.a[0] - n[0], x.a[1] - n[1]], [x.b[0] + n[0], x.b[1] + n[1]], [x.b[0] - n[0], x.b[1] - n[1]]]) });
}
for (const f of readDrawnFloors(w, storey)) out.push({ kind: 'floor', guid: f.guid, storey: f.storey, box: boxOfPts(f.points) });
for (const c of readColumns(w, storey)) {
const a = (c.angle || 0) * Math.PI / 180, hw = c.width / 2, hd = (c.shape === 'round' ? c.width : c.depth) / 2;
const pts = c.shape === 'round' ? [[c.at[0] - hw, c.at[1] - hw], [c.at[0] + hw, c.at[1] + hw]]
: [[-hw, -hd], [hw, -hd], [hw, hd], [-hw, hd]].map(([x, y]) => [c.at[0] + x * Math.cos(a) - y * Math.sin(a), c.at[1] + x * Math.sin(a) + y * Math.cos(a)]);
out.push({ kind: 'column', guid: c.guid, storey: c.storey, box: boxOfPts(pts) });
}
for (const it of placedItems(w, storey)) out.push({ kind: 'item', guid: it.guid, storey: it.storey, box: { minX: it.x, minY: it.y, maxX: it.x, maxY: it.y } });
return out;
}