rustsim-transit 0.0.1

Public-transit primitives for rustsim: stops, routes, schedules, boarding/alighting queues, dwell times, headway control
Documentation
//! Transit stops.

use rustsim_geometry::vec3::Vec3;

/// Stable identifier for a [`Stop`].
pub type StopId = u64;

/// A boarding point on a transit network.
#[derive(Debug, Clone)]
pub struct Stop {
    /// Unique identifier.
    pub id: StopId,
    /// Human-readable name.
    pub name: String,
    /// 3-D position (for multi-level stations; use `z = 0` for street level).
    pub pos: Vec3,
    /// Maximum waiting passengers (soft cap used by schedulers).
    pub capacity: u32,
}

impl Stop {
    /// Construct a street-level stop at `(x, y)`.
    pub fn at_ground(id: StopId, name: impl Into<String>, x: f64, y: f64, capacity: u32) -> Self {
        Self {
            id,
            name: name.into(),
            pos: [x, y, 0.0],
            capacity,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn construct_at_ground() {
        let s = Stop::at_ground(1, "Main St & 3rd", 10.0, 20.0, 120);
        assert_eq!(s.id, 1);
        assert_eq!(s.pos, [10.0, 20.0, 0.0]);
        assert_eq!(s.capacity, 120);
    }
}