pub struct Grid2D { /* private fields */ }Expand description
Multi-occupancy 2D grid space.
Each cell can hold an arbitrary number of agents. Backed by a flat
Vec<Vec<AgentId>> of size width x height.
§Boundary modes
periodic = true- toroidal wrapping (positions are taken modulo grid size).periodic = false- bounded (out-of-bounds positions return an error).
Implementations§
Source§impl Grid2D
impl Grid2D
Sourcepub fn dimensions(&self) -> (usize, usize)
pub fn dimensions(&self) -> (usize, usize)
Grid dimensions as (width, height).
Sourcepub fn is_in_bounds(&self, pos: GridPos2) -> bool
pub fn is_in_bounds(&self, pos: GridPos2) -> bool
Check whether a position is within the grid bounds.
Sourcepub fn ids_in_position(&self, pos: GridPos2) -> Option<&[AgentId]>
pub fn ids_in_position(&self, pos: GridPos2) -> Option<&[AgentId]>
Return the agent IDs at a given position, or None if out of bounds.
Trait Implementations§
Source§impl<A> SpaceInteraction<A> for Grid2Dwhere
A: PositionedAgent<Position = GridPos2>,
impl<A> SpaceInteraction<A> for Grid2Dwhere
A: PositionedAgent<Position = GridPos2>,
Source§fn random_position<R: RngCore>(&self, rng: &mut R) -> A::Position
fn random_position<R: RngCore>(&self, rng: &mut R) -> A::Position
Generate a random valid position within this space.
Source§fn add_agent(&mut self, agent: &A) -> Result<(), Self::Error>
fn add_agent(&mut self, agent: &A) -> Result<(), Self::Error>
Register an agent with the space at its current position.
impl Space for Grid2D
Auto Trait Implementations§
impl Freeze for Grid2D
impl RefUnwindSafe for Grid2D
impl Send for Grid2D
impl Sync for Grid2D
impl Unpin for Grid2D
impl UnsafeUnpin for Grid2D
impl UnwindSafe for Grid2D
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more