Skip to main content

rustsim_transit/
stop.rs

1//! Transit stops.
2
3use rustsim_geometry::vec3::Vec3;
4
5/// Stable identifier for a [`Stop`].
6pub type StopId = u64;
7
8/// A boarding point on a transit network.
9#[derive(Debug, Clone)]
10pub struct Stop {
11    /// Unique identifier.
12    pub id: StopId,
13    /// Human-readable name.
14    pub name: String,
15    /// 3-D position (for multi-level stations; use `z = 0` for street level).
16    pub pos: Vec3,
17    /// Maximum waiting passengers (soft cap used by schedulers).
18    pub capacity: u32,
19}
20
21impl Stop {
22    /// Construct a street-level stop at `(x, y)`.
23    pub fn at_ground(id: StopId, name: impl Into<String>, x: f64, y: f64, capacity: u32) -> Self {
24        Self {
25            id,
26            name: name.into(),
27            pos: [x, y, 0.0],
28            capacity,
29        }
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[test]
38    fn construct_at_ground() {
39        let s = Stop::at_ground(1, "Main St & 3rd", 10.0, 20.0, 120);
40        assert_eq!(s.id, 1);
41        assert_eq!(s.pos, [10.0, 20.0, 0.0]);
42        assert_eq!(s.capacity, 120);
43    }
44}