Skip to main content

SpaceInteraction

Trait SpaceInteraction 

Source
pub trait SpaceInteraction<A: PositionedAgent>: Space {
    type Error: Debug + Display;

    // Required methods
    fn random_position<R: RngCore>(&self, rng: &mut R) -> A::Position;
    fn add_agent(&mut self, agent: &A) -> Result<(), Self::Error>;
    fn remove_agent(&mut self, agent: &A) -> Result<(), Self::Error>;
    fn nearby_ids(&self, position: &A::Position, radius: usize) -> Vec<AgentId> ;
}
Expand description

Trait that spaces implement to support agent lifecycle and neighbor queries.

Each space type defines its own Error type and provides methods to add/remove agents, generate random positions, and find nearby agent IDs.

Required Associated Types§

Source

type Error: Debug + Display

Error type for space operations.

Required Methods§

Source

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>

Register an agent with the space at its current position.

Source

fn remove_agent(&mut self, agent: &A) -> Result<(), Self::Error>

Deregister an agent from the space.

Source

fn nearby_ids(&self, position: &A::Position, radius: usize) -> Vec<AgentId>

Return all agent IDs within radius of position.

The meaning of radius depends on the space: grid cells (Chebyshev), Euclidean distance (continuous), or graph hops (graph).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§