mod.rs

1.3 kB · rust · 40 lines

1//! The spatial network.2//!3//! A grid lifts into nodes and branches, as a core, an edge or a tunnel network, and the census4//! reads its roles, tips, junctions and components back.56/// The role tags, lengths, tip, junction and component counts of a network.7pub mod census;8/// The core, edge and tunnel networks lifted from a grid.9pub mod extract;10/// The force-directed layout that lets a lattice relax.11pub mod layout;12/// The node, branch and network types.13pub mod models;1415pub use census::{census, largest_component, roles, Census, Role};16pub use extract::{core_graph, edge_graph, tunnel_graph};17pub use layout::Layout;18pub use models::{Branch, Network, Node};1920#[cfg(test)]21mod tests {22    use super::{census, Network, Role};23    use crate::math::round_trip;2425    #[test]26    fn serde_round_trips() {27        let mut net = Network::new(2);28        for corner in [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]] {29            net.add_node(corner.to_vec()).unwrap();30        }31        for (a, b) in [(0, 1), (1, 2), (2, 3), (3, 0)] {32            net.add_branch(a, b, 1.0).unwrap();33        }34        round_trip(net.nodes[0].clone());35        round_trip(net.branches[0].clone());36        round_trip(Role::Junction);37        round_trip(census(&net).unwrap());38        round_trip(net);39    }40}