/** * Local collision avoidance: nudge a set of circular agents apart so they stop * overlapping, kept deliberately separate from route planning so a game can * pair it with nav paths, flow fields, direct seek, or vehicle steering. It is a * short symmetric relaxation (Jacobi position correction) over a bounded uniform * hash grid — each agent only tests the 3×3 cells around it, so cost scales with * local density, never O(n²) across the whole world. Corrections are summed per * agent and applied after each pass, so the result is order-independent and * deterministic for a given agent list. Different radii and per-agent weights * (inverse mass; `0` = immovable anchor/obstacle) are honored. */ import type { Vec2 } from "./formation.js"; /** A circular agent that avoidance may push on the XZ plane. */ export interface AvoidanceAgent { /** Current XZ position; reassigned in place by {@link resolveLocalAvoidance}. */ position: Vec2; /** Collision radius (world units). */ radius: number; } /** Tuning for {@link resolveLocalAvoidance}. */ export interface LocalAvoidanceOptions { /** Relaxation passes; more converges denser packs. Default `2`. */ iterations?: number; /** Fraction of each overlap resolved per pass, `0..1`. Lower is softer/less jittery. Default `1`. */ strength?: number; /** Extra gap enforced beyond the two radii (world units). Default `0`. */ padding?: number; /** * Per-agent inverse mass, parallel to the agent list. `0` pins an agent * (obstacle/leader); a heavier agent (smaller value) yields less. Omitted or * negative entries default to `1`. Two pinned agents never push each other. */ weights?: readonly number[]; } /** * Resolve overlaps in `agents` in place and return how many overlapping pairs * remained on the final pass (`0` = fully separated). Uses a bounded uniform * hash grid sized to the largest agent, so only nearby agents are ever compared. * Deterministic: corrections are accumulated then applied per pass, independent * of agent order. Pass `weights` to pin or differentially push agents. * * @capability local-avoidance bounded deterministic local collision avoidance for moving agents * @consumer squad/crowd movement — keep grouped agents from overlapping without a whole-world scan */ export declare function resolveLocalAvoidance(agents: AvoidanceAgent[], options?: LocalAvoidanceOptions): number;