pub struct SpatialMessages2D<M> { /* private fields */ }Expand description
2D spatial message list with spatial-hashing neighbor lookup.
Messages carry an (x, y) position. During finalization, messages are
sorted into a uniform grid of bins (side length = radius). During
the read phase, agents query nearby messages by position and only
iterate bins within the search radius.
This mirrors FlameGPU2’s MessageSpatial2D and its Partition Boundary
Matrix (PBM) – a sorted index of messages by spatial bin.
Performance: O(k) per agent where k = messages in neighboring bins.
Implementations§
Source§impl<M: Clone> SpatialMessages2D<M>
impl<M: Clone> SpatialMessages2D<M>
Sourcepub fn new(radius: f32) -> Result<Self, MessageConfigError>
pub fn new(radius: f32) -> Result<Self, MessageConfigError>
Create a new 2D spatial message list.
radius is both the search radius and the bin side length.
Sourcepub fn output(&mut self, message: M, x: f32, y: f32)
pub fn output(&mut self, message: M, x: f32, y: f32)
Output a message at a 2D position (phase 1).
Sourcepub fn try_output(
&mut self,
message: M,
x: f32,
y: f32,
) -> Result<(), MessagePhaseError>
pub fn try_output( &mut self, message: M, x: f32, y: f32, ) -> Result<(), MessagePhaseError>
Try to output a message at a 2D position, returning a typed phase error on misuse.
Sourcepub fn finalize(&mut self)
pub fn finalize(&mut self)
Build the spatial index (phase boundary).
This constructs a PBM-like structure: messages are logically sorted by bin, and a map records the (start, count) of each bin.
Sourcepub fn read_nearby(&self, x: f32, y: f32, radius: f32) -> SpatialIter2D<'_, M> ⓘ
pub fn read_nearby(&self, x: f32, y: f32, radius: f32) -> SpatialIter2D<'_, M> ⓘ
Iterate messages within radius of (x, y) (phase 2).
Returns an iterator yielding (message_ref, distance_squared).
The caller should filter by distance_squared <= radius * radius
for exact circular queries (the method returns a superset from
the bin neighborhood).
§Panics
Panics if called before finalize. Use
try_read_nearby to handle phase errors explicitly.
Sourcepub fn try_read_nearby(
&self,
x: f32,
y: f32,
radius: f32,
) -> Result<SpatialIter2D<'_, M>, MessagePhaseError>
pub fn try_read_nearby( &self, x: f32, y: f32, radius: f32, ) -> Result<SpatialIter2D<'_, M>, MessagePhaseError>
Try to iterate messages within radius of (x, y) (phase 2).
Sourcepub fn is_finalized(&self) -> bool
pub fn is_finalized(&self) -> bool
Whether the message buffer has been finalized for reading.
Trait Implementations§
Source§impl<M: Clone> Clone for SpatialMessages2D<M>
impl<M: Clone> Clone for SpatialMessages2D<M>
Source§fn clone(&self) -> SpatialMessages2D<M>
fn clone(&self) -> SpatialMessages2D<M>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more