MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / computeCameraTarget

Function computeCameraTarget

graph-ui/src/components/GraphScene.tsx:251–298  ·  view source on GitHub ↗
(
  nodes: GraphNode[],
  ids: Set<number>,
)

Source from the content-addressed store, hash-verified

249/* ── Helper: compute camera target from node IDs ────────── */
250
251export function computeCameraTarget(
252 nodes: GraphNode[],
253 ids: Set<number>,
254): CameraTarget | null {
255 if (ids.size === 0) return null;
256
257 let cx = 0,
258 cy = 0,
259 cz = 0,
260 count = 0;
261 for (const node of nodes) {
262 if (ids.has(node.id)) {
263 cx += node.x;
264 cy += node.y;
265 cz += node.z;
266 count++;
267 }
268 }
269 if (count === 0) return null;
270
271 cx /= count;
272 cy /= count;
273 cz /= count;
274
275 /* Distance based on cluster spread — ensure we never zoom too close */
276 let maxDist = 0;
277 for (const node of nodes) {
278 if (ids.has(node.id)) {
279 const d = Math.sqrt(
280 (node.x - cx) ** 2 + (node.y - cy) ** 2 + (node.z - cz) ** 2,
281 );
282 if (d > maxDist) maxDist = d;
283 }
284 }
285
286 /* Minimum distance scales with count: single node = 300, cluster = spread-based */
287 const spreadDist = maxDist * 3;
288 const minDist = count <= 5 ? 300 : 200;
289 const distance = Math.max(minDist, spreadDist);
290 const lookAt = new THREE.Vector3(cx, cy, cz);
291 const position = new THREE.Vector3(
292 cx + distance * 0.2,
293 cy + distance * 0.15,
294 cz + distance,
295 );
296
297 return { position, lookAt };
298}

Callers 1

GraphTabFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected