Skip to main content

ContinuousSpace3D

Struct ContinuousSpace3D 

Source
pub struct ContinuousSpace3D { /* private fields */ }
Expand description

3D continuous space with uniform-grid spatial hashing for fast neighbor queries.

The space spans [0, extent_x) x [0, extent_y) x [0, extent_z). An internal grid of cells (side length = spacing) accelerates nearby_ids_euclidean to O(k) where k is the number of agents in the neighborhood, rather than O(n).

Implementations§

Source§

impl ContinuousSpace3D

Source

pub fn new( extent_x: f64, extent_y: f64, extent_z: f64, periodic: bool, spacing: f64, ) -> Result<Self, ContinuousSpace3DConfigError>

Create a new 3D continuous space.

§Arguments
  • extent_x, extent_y, extent_z - space dimensions.
  • periodic - whether boundaries wrap.
  • spacing - cell side length for the spatial hash grid.
Source

pub fn extent(&self) -> (f64, f64, f64)

Space dimensions as (extent_x, extent_y, extent_z).

Source

pub fn periodic(&self) -> bool

Whether the space wraps around (toroidal boundaries).

Source

pub fn spacing(&self) -> f64

Cell side length for the spatial hash grid.

Source

pub fn agent_position(&self, id: AgentId) -> Option<&ContinuousPos3D>

Look up the current position of an agent.

Source

pub fn move_agent_pos( &mut self, id: AgentId, new_pos: ContinuousPos3D, ) -> Result<ContinuousPos3D, ContinuousSpace3DError>

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.

Source

pub fn nearby_ids_euclidean( &self, pos: &ContinuousPos3D, 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 ContinuousSpace3D

Source§

fn clone(&self) -> ContinuousSpace3D

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContinuousSpace3D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A> SpaceInteraction<A> for ContinuousSpace3D
where A: PositionedAgent<Position = ContinuousPos3D>,

Source§

type Error = ContinuousSpace3DError

Error type for space operations.
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. Read more
Source§

impl Space for ContinuousSpace3D

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Message for T
where T: Clone + Send + Sync + 'static,