mirror of
https://git.quad4.io/RNS-Things/MeshChatX.git
synced 2026-06-09 12:31:51 +00:00
feat(network-visualiser): add utility functions for trail positioning and view bounds, and define visualiser constants
This commit is contained in:
@@ -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"];
|
||||
Reference in New Issue
Block a user