pub struct ContinuousSpace2D { /* private fields */ }Expand description
2D continuous space with spatial hashing.
Agents are tracked by position and indexed into a uniform grid for fast
neighbor queries. The grid cell size (spacing) determines the tradeoff
between query accuracy and move_agent_pos overhead.
§Boundary modes
periodic = true- toroidal wrapping.periodic = false- bounded; out-of-bounds positions returnContinuousSpaceError::OutOfBounds.
Implementations§
Source§impl ContinuousSpace2D
impl ContinuousSpace2D
Sourcepub fn new(
extent_x: f64,
extent_y: f64,
periodic: bool,
spacing: f64,
) -> Result<Self, ContinuousSpaceConfigError>
pub fn new( extent_x: f64, extent_y: f64, periodic: bool, spacing: f64, ) -> Result<Self, ContinuousSpaceConfigError>
Create a new 2D continuous space.
§Arguments
extent_x,extent_y- space dimensions.periodic- whether boundaries wrap.spacing- cell side length for the spatial hash grid.
Sourcepub fn agent_position(&self, id: AgentId) -> Option<&ContinuousPos>
pub fn agent_position(&self, id: AgentId) -> Option<&ContinuousPos>
Look up the current position of an agent.
Sourcepub fn move_agent_pos(
&mut self,
id: AgentId,
new_pos: ContinuousPos,
) -> Result<ContinuousPos, ContinuousSpaceError>
pub fn move_agent_pos( &mut self, id: AgentId, new_pos: ContinuousPos, ) -> Result<ContinuousPos, ContinuousSpaceError>
Move an agent to a new position, updating the spatial hash.
Returns the (possibly normalized) final position, or an error if the position is out of bounds in a non-periodic space.
Sourcepub fn nearby_ids_euclidean(
&self,
pos: &ContinuousPos,
radius: f64,
) -> Vec<AgentId> ⓘ
pub fn nearby_ids_euclidean( &self, pos: &ContinuousPos, radius: f64, ) -> Vec<AgentId> ⓘ
Find all agent IDs within Euclidean distance radius of pos.
Respects periodic boundaries when enabled.
Trait Implementations§
Source§impl Clone for ContinuousSpace2D
impl Clone for ContinuousSpace2D
Source§fn clone(&self) -> ContinuousSpace2D
fn clone(&self) -> ContinuousSpace2D
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 ContinuousSpace2D
impl Debug for ContinuousSpace2D
Source§impl<A> SpaceInteraction<A> for ContinuousSpace2Dwhere
A: PositionedAgent<Position = ContinuousPos>,
impl<A> SpaceInteraction<A> for ContinuousSpace2Dwhere
A: PositionedAgent<Position = ContinuousPos>,
Source§type Error = ContinuousSpaceError
type Error = ContinuousSpaceError
Error type for space operations.
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 ContinuousSpace2D
Auto Trait Implementations§
impl Freeze for ContinuousSpace2D
impl RefUnwindSafe for ContinuousSpace2D
impl Send for ContinuousSpace2D
impl Sync for ContinuousSpace2D
impl Unpin for ContinuousSpace2D
impl UnsafeUnpin for ContinuousSpace2D
impl UnwindSafe for ContinuousSpace2D
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