Skip to main content

Pedestrian

Struct Pedestrian 

Source
#[non_exhaustive]
pub struct Pedestrian { pub pos: Vec2, pub vel: Vec2, pub radius: f64, pub desired_speed: f64, pub destination: Vec2, }
Expand description

A single pedestrian agent as seen by every model in this crate.

This is intentionally a small, copy-friendly struct so model step functions can be called on &mut [Pedestrian] without any indirection.

§Construction

Outside this crate, construct via Pedestrian::new, not struct literal syntax: the type is #[non_exhaustive] so that adding a field in a future minor version is a non-breaking change for downstream callers. Field-access (ped.pos, ped.vel = …) remains stable and is intentionally left pub so the SoA-friendly hot path stays indirection-free.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§pos: Vec2

Position in metres.

§vel: Vec2

Velocity in m/s.

§radius: f64

Body radius in metres (typical pedestrian: 0.2–0.3 m).

§desired_speed: f64

Desired free-flow walking speed in m/s (Weidmann mean: 1.34 m/s).

§destination: Vec2

Target destination in metres.

Implementations§

Source§

impl Pedestrian

Source

pub fn new( pos: Vec2, vel: Vec2, radius: f64, desired_speed: f64, destination: Vec2, ) -> Self

Constructs a Pedestrian from its five core fields.

This is the stable construction path for downstream callers: because Pedestrian is #[non_exhaustive], adding a field in a future minor version will not break callers that go through Pedestrian::new. Each new field will get a paired with_* setter (e.g. a hypothetical with_target_floor) so the extension stays additive.

Source

pub fn to_destination(&self) -> Vec2

Vector from pos to destination.

Source

pub fn desired_direction(&self) -> Vec2

Unit vector pointing at the destination, or [0, 0] if already there.

Source

pub fn speed(&self) -> f64

Current speed |vel|.

Source

pub fn distance_to_destination(&self) -> f64

Euclidean distance from pos to destination.

Source

pub fn has_arrived(&self, arrival_radius: f64) -> bool

Returns true if the pedestrian is inside its arrival radius.

Source

pub fn effective_desired_speed(&self, arrival_radius: f64) -> f64

Speed the pedestrian should aim for given how close it is to its destination. Produces a smooth linear taper from the full desired_speed at d ≥ arrival_radius down to 0 at d = 0, so agents do not overshoot their goal and then oscillate back toward it.

arrival_radius ≤ 0 disables the taper (returns desired_speed unchanged).

Trait Implementations§

Source§

impl Clone for Pedestrian

Source§

fn clone(&self) -> Pedestrian

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 Pedestrian

Source§

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

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

impl PartialEq for Pedestrian

Source§

fn eq(&self, other: &Pedestrian) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Pedestrian

Source§

impl StructuralPartialEq for Pedestrian

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,