Fix plan scaling: extent tracks actual content/table instead of a fixed 100x100 floor

This commit is contained in:
2026-08-03 16:04:15 +10:00
parent d34b850f1b
commit 7a7d27b9b4
+3 -1
View File
@@ -57,7 +57,7 @@ document.getElementById('controls').innerHTML = `
// ---------- geometry ---------- // ---------- geometry ----------
function extent() { function extent() {
let minX = 0, minZ = 0, maxX = 100, maxZ = 100; let minX = Infinity, minZ = Infinity, maxX = -Infinity, maxZ = -Infinity;
const eat = (x, z, pad = 10) => { const eat = (x, z, pad = 10) => {
minX = Math.min(minX, x - pad); maxX = Math.max(maxX, x + pad); minX = Math.min(minX, x - pad); maxX = Math.max(maxX, x + pad);
minZ = Math.min(minZ, z - pad); maxZ = Math.max(maxZ, z + pad); minZ = Math.min(minZ, z - pad); maxZ = Math.max(maxZ, z + pad);
@@ -68,6 +68,8 @@ function extent() {
for (const b of scene.buildings || []) eat(b.position[0], b.position[2], Math.max(b.size[0], b.size[2]) / 2 + 5); for (const b of scene.buildings || []) eat(b.position[0], b.position[2], Math.max(b.size[0], b.size[2]) / 2 + 5);
for (const s of scene.spawns || []) eat(s.position[0], s.position[2]); for (const s of scene.spawns || []) eat(s.position[0], s.position[2]);
for (const p of scene.paths || []) for (const q of p.points || []) eat(q[0], q[2]); for (const p of scene.paths || []) for (const q of p.points || []) eat(q[0], q[2]);
// nothing to draw → fall back to a small default page area
if (!isFinite(minX)) { minX = 0; minZ = 0; maxX = 100; maxZ = 100; }
return { minX, minZ, maxX, maxZ, w: maxX - minX, h: maxZ - minZ }; return { minX, minZ, maxX, maxZ, w: maxX - minX, h: maxZ - minZ };
} }