Files
rayd1o dd41588527
ci / backend (push) Has been cancelled
ci / frontend (push) Has been cancelled
ci / delivery (push) Has been cancelled
release / images (push) Has been cancelled
release: bump version to 0.76.2
2026-10-01 02:29:49 +08:00

36 lines
1.1 KiB
JavaScript

// Shared screen-pick ordering for surface icon layers.
// Smaller screen distance wins; the priority only resolves a true overlap.
export const INTERACTIVE_PICK_PRIORITY = Object.freeze({
earth_interactable: 50,
compute_center: 40,
bgp: 30,
bgp_collector: 20,
vessel: 10,
});
export function pickNearestInteractiveHit(groups = []) {
const candidates = [];
groups.forEach(({ type, hits = [] }) => {
hits.forEach((hit) => {
if (!hit?.object || hit.cluster) return;
candidates.push({
type,
hit,
object: hit.object,
distancePxSq: Number.isFinite(hit.distancePxSq) ? hit.distancePxSq : Infinity,
priority: INTERACTIVE_PICK_PRIORITY[type] || 0,
});
});
});
candidates.sort((left, right) =>
left.distancePxSq - right.distancePxSq || right.priority - left.priority,
);
return candidates[0] || null;
}
export function pickNearestPointCandidate(candidates = []) {
return candidates
.filter(candidate => candidate?.object && Number.isFinite(candidate.distancePxSq))
.sort((left, right) => left.distancePxSq - right.distancePxSq)[0] || null;
}