wiki-graphs.rs

1.6 kB · rust · 52 lines

1use mrlycore::errors::Result;2use mrlyfig::{ink, save, Board};3use mrlymath::two::designs;4use mrlymath::two::graph::core_graph;5use mrlynum::graph::{census, roles, Role};67const LEVEL: usize = 3;8const SIDE: f64 = 8.0;910fn main() -> Result<()> {11    let cell = designs::create(7, 2, LEVEL, 0, 2)?;12    let network = core_graph(&cell)?;13    let tally = census(&network);14    let tags = roles(&network);15    let tips = tags.iter().filter(|r| **r == Role::Tip).count();16    let through = tags.iter().filter(|r| **r == Role::Through).count();17    let junctions = tags.iter().filter(|r| **r == Role::Junction).count();18    assert_eq!(tally.nodes, 27);19    assert_eq!(tally.branches, 26);20    assert_eq!(tally.components, 1);21    assert_eq!((tips, through, junctions), (10, 9, 8));2223    let mut board = Board::square();24    let frame = board.frame(0.08);25    let unit = frame.w / SIDE;26    let at = |index: usize| {27        let node = &network.nodes[index];28        (29            frame.x + node.position[0] * unit,30            frame.y + node.position[1] * unit,31        )32    };33    for branch in &network.branches {34        board.segment(35            at(branch.parent),36            at(branch.child),37            unit * 0.16,38            ink::fade(ink::blue(), 0.6),39        );40    }41    for (index, role) in tags.iter().enumerate() {42        let (x, y) = at(index);43        let (radius, color) = match role {44            Role::Junction => (unit * 0.30, ink::pink()),45            Role::Tip => (unit * 0.26, ink::yellow()),46            _ => (unit * 0.21, ink::blue()),47        };48        board.disc(x, y, radius, color);49    }50    save("wiki-graphs", &board)?;51    Ok(())52}