aboutsummaryrefslogtreecommitdiff
path: root/public/app.js
diff options
context:
space:
mode:
authordax <me@dax.ist>2026-08-04 07:17:37 +0000
committerdax <me@dax.ist>2026-08-04 07:17:37 +0000
commit1b24afa90bbcc9311cf19ea0aad29dc05f102bac (patch)
treeac3de51a721ee099f6c38da6e3c0772a138f76bc /public/app.js
parent08fa2e1bee4e0bae417cfda508212e011eccf631 (diff)
pathways: smarter placement - fine-grained nearest fit + snap to neighbor edges, no more coarse tile-width jumps
Diffstat (limited to 'public/app.js')
-rw-r--r--public/app.js34
1 files changed, 27 insertions, 7 deletions
diff --git a/public/app.js b/public/app.js
index b8aeb68..6411bf7 100644
--- a/public/app.js
+++ b/public/app.js
@@ -78,14 +78,34 @@ function placeRect(w, h, from, dir) {
const base = baseRect(w, h, from, dir)
if (!collides(base)) return base
const horiz = dir === "N" || dir === "S"
- for (let k = 1; k < 60; k++) {
- const off = k * (w + GAP)
- const a = horiz ? { ...base, x: base.x + off } : { ...base, y: base.y + off }
- if (!collides(a)) return a
- const b = horiz ? { ...base, x: base.x - off } : { ...base, y: base.y - off }
- if (!collides(b)) return b
+ const fixed = horiz ? base.y : base.x
+ const slide0 = horiz ? base.x : base.y
+ let best = null
+ for (let k = 1; k < 1000; k++) {
+ for (const off of [k * 2, -k * 2]) {
+ const rect = horiz ? { x: slide0 + off, y: fixed, w, h } : { x: fixed, y: slide0 + off, w, h }
+ if (!collides(rect)) {
+ best = rect
+ break
+ }
+ }
+ if (best) break
+ }
+ if (!best) return base
+ let snap = null
+ for (const t of tiles.values()) {
+ const r = t.rect
+ const lines = horiz
+ ? [r.x - w - GAP, r.x + r.w + GAP, r.x + (r.w - w) / 2]
+ : [r.y - h - GAP, r.y + r.h + GAP, r.y + (r.h - h) / 2]
+ for (const c of lines) {
+ const at = horiz ? best.x : best.y
+ if (Math.abs(c - at) > GAP) continue
+ const rect = horiz ? { x: c, y: fixed, w, h } : { x: fixed, y: c, w, h }
+ if (!collides(rect)) snap = rect
+ }
}
- return base
+ return snap || best
}
function addTile(info, rect) {