feat(network-visualiser): add utility functions for trail positioning and view bounds, and define visualiser constants

This commit is contained in:
Ivan
2026-04-14 19:35:13 -05:00
parent 97fd6049ea
commit 6147415da9
3 changed files with 34 additions and 0 deletions
@@ -0,0 +1,16 @@
export function getPositionAlongTrail(trail, distBehind) {
if (!trail || trail.length === 0) return { x: 0, y: 0 };
if (trail.length === 1) return { ...trail[0] };
let d = 0;
for (let i = trail.length - 1; i > 0; i--) {
const p = trail[i];
const q = trail[i - 1];
const seg = Math.hypot(p.x - q.x, p.y - q.y);
if (d + seg >= distBehind) {
const t = seg > 0 ? (distBehind - d) / seg : 0;
return { x: p.x + (q.x - p.x) * t, y: p.y + (q.y - p.y) * t };
}
d += seg;
}
return { ...trail[0] };
}
@@ -0,0 +1,17 @@
export function getViewCanvasBounds(network) {
const container = document.getElementById("network");
if (!container || !network) return null;
const scale = network.getScale();
const vp = network.getViewPosition();
const w = container.clientWidth;
const h = container.clientHeight;
const halfW = w / (2 * scale);
const halfH = h / (2 * scale);
return {
left: vp.x - halfW,
right: vp.x + halfW,
top: vp.y - halfH,
bottom: vp.y + halfH,
scale,
};
}
@@ -0,0 +1 @@
export const PONG_NODE_IDS = ["__pong_ball", "__pong_pad_l", "__pong_pad_r", "__pong_hud"];