1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
//! This module provides basic structures for representing a transit network.
//! It provides `TransitNode` and `TransitEdge` structures, along with ID types for them.
//! The `TransitNode` represents a node in the transit network, while the `TransitEdge` represents a connection between two nodes.
//! The module also provides `Accessability`, an enum for representing the accessibility of nodes in the network.
mod edge;
pub use edge::{EdgeId, PathCoordinates, TransitEdge};
mod accessability;
/// Re-export of the `Accessability` enum from the `accessability` module.
pub use accessability::Accessability;
use serde::{Deserialize, Serialize};
/// Type alias for an identifier.
pub type IdType = u64;
/// Type alias for a node identifier.
pub type NodeId = IdType;
/// Structure representing a node in the transit network.
///
/// Each node has a unique identifier and a location.
/// The location type `T` is generic and can be any type that implements the `Copy` trait.
///
/// # Examples
///
/// ```
/// use geo::coord;
/// use transit_grid::core::TransitNode;
///
/// // GPS coordinates for London, UK: 51.5074 N, 0.1278 W
/// let node = TransitNode {
/// id: 1,
/// location: coord! { x: -0.1278, y: 51.5074 },
/// };
/// assert_eq!(node.id, 1);
/// assert_eq!(node.location, coord! { x: -0.1278, y: 51.5074 });
/// ```
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub struct TransitNode<T> {
/// A unique identifier for the node.
pub id: NodeId,
/// The location of the node, represented by a generic type `T`.
pub location: T,
}
#[cfg(test)]
mod tests {
use super::*;
use geo::coord;
#[test]
fn test_node() {
let node = TransitNode {
id: 1,
location: coord! { x:0.0, y:0.0},
};
assert_eq!(node.id, 1);
assert_eq!(node.location, coord! { x:0.0, y:0.0});
}
}