#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.pos: Vec2Position in metres.
vel: Vec2Velocity in m/s.
radius: f64Body radius in metres (typical pedestrian: 0.2–0.3 m).
desired_speed: f64Desired free-flow walking speed in m/s (Weidmann mean: 1.34 m/s).
destination: Vec2Target destination in metres.
Implementations§
Source§impl Pedestrian
impl Pedestrian
Sourcepub fn new(
pos: Vec2,
vel: Vec2,
radius: f64,
desired_speed: f64,
destination: Vec2,
) -> Self
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.
Sourcepub fn to_destination(&self) -> Vec2
pub fn to_destination(&self) -> Vec2
Vector from pos to destination.
Sourcepub fn desired_direction(&self) -> Vec2
pub fn desired_direction(&self) -> Vec2
Unit vector pointing at the destination, or [0, 0] if already there.
Sourcepub fn distance_to_destination(&self) -> f64
pub fn distance_to_destination(&self) -> f64
Euclidean distance from pos to destination.
Sourcepub fn has_arrived(&self, arrival_radius: f64) -> bool
pub fn has_arrived(&self, arrival_radius: f64) -> bool
Returns true if the pedestrian is inside its arrival radius.
Sourcepub fn effective_desired_speed(&self, arrival_radius: f64) -> f64
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
impl Clone for Pedestrian
Source§fn clone(&self) -> Pedestrian
fn clone(&self) -> Pedestrian
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more