pub struct Grid2DSingle { /* private fields */ }Expand description
Single-occupancy 2D grid space.
Each cell holds at most one agent. Attempting to add an agent to an
occupied cell returns GridError::Occupied.
Backed by a flat Vec<Option<AgentId>> of size width x height.
Implementations§
Source§impl Grid2DSingle
impl Grid2DSingle
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 id_in_position(&self, pos: GridPos2) -> Option<AgentId>
pub fn id_in_position(&self, pos: GridPos2) -> Option<AgentId>
Return the agent ID at a given position, or None if empty or out of bounds.
Trait Implementations§
Source§impl Clone for Grid2DSingle
impl Clone for Grid2DSingle
Source§fn clone(&self) -> Grid2DSingle
fn clone(&self) -> Grid2DSingle
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Grid2DSingle
impl Debug for Grid2DSingle
Source§impl<A> SpaceInteraction<A> for Grid2DSinglewhere
A: PositionedAgent<Position = GridPos2>,
impl<A> SpaceInteraction<A> for Grid2DSinglewhere
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 Grid2DSingle
Auto Trait Implementations§
impl Freeze for Grid2DSingle
impl RefUnwindSafe for Grid2DSingle
impl Send for Grid2DSingle
impl Sync for Grid2DSingle
impl Unpin for Grid2DSingle
impl UnsafeUnpin for Grid2DSingle
impl UnwindSafe for Grid2DSingle
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