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