Continuous Projection
A 2D Euclidean projection: each agent in the context has an optional Point2D position. The projection tracks positions in a map keyed by agent reference; positions are set explicitly via placeAt / moveTo from user code.
Spatial queries are accelerated by an internal uniform spatial hash: the plane is partitioned into square cells of cellSize units, and agents are bucketed into the cell their position falls into. within scans only the cells overlapping the query disk rather than every agent; nearest does the same via progressive radius doubling. Insertion / move / remove are O(1) amortized.
The default cellSize is min(xSize, ySize) / 10.0 — ten cells along the smaller dimension. Tune for your model: cell size roughly equal to typical query radius gives near-optimal performance. Smaller cells cost more bookkeeping but tighter query bounding boxes; larger cells cost more agents-per-cell to filter.
Boundaries: positions are not enforced to be inside xRange / yRange — the ranges describe the projection's logical domain but placeAt / moveTo accept any coordinates. When torus is true, distance computes wrapped distance using the ranges as the torus dimensions, and the spatial hash wraps bucket coordinates accordingly.
Parameters
the context whose agents this projection positions
logical x bounds (used for torus wrapping)
logical y bounds (used for torus wrapping)
if true, distances wrap at the bounds
side length of each spatial-hash cell. Defaults to min(xSize, ySize) / 10.0, or 1.0 for degenerate ranges. Must be positive.
display name
Constructors
Types
Mutable global defaults for ContinuousProjection internals.
Properties
Maximum occupancy of any single bucket. Diagnostic for cellSize tuning.
Number of non-empty buckets. Indicates how well-distributed agents are across the spatial hash. Pure diagnostic — useful for tuning cellSize on a model with known typical population.
Functions
Construct a ProjectionSpatialModel over this projection. Each call creates a new spatial model; locations created by one spatial model are not valid in another. Store the result and reuse it across all MovableResource / move / transport calls that need to share coordinates with this projection.
Signed shortest-direction delta from from to to under this projection's geometry. For a non-torus projection this is the trivial component-wise subtraction to - from. For a torus, each component picks whichever wrap (positive or negative) is shorter — so a boid at x = 99 querying a peer at x = 1 in a 100-wide torus gets dx = +2, not -98.
Distance between two agents. Returns Double.NaN if either agent has no assigned position. Uses Euclidean distance, or wrapped Euclidean if torus is true.
Distance between two points under this projection's metric (Euclidean, with torus wrap if enabled).
Called by the AgentModel.Context when agent leaves. Default no-op — projections that track per-agent state (positions, edges) typically override to drop their bookkeeping for the departing agent.
Return the position of agent, or null if the agent has no assigned position (never placed, or has left the context).