36 lines
1.1 KiB
JavaScript
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;
|
|
}
|