mod.rs

4.1 kB · rust · 107 lines

1/// The seeded artwork run from tile recipe to rendered files.2pub mod artwork;3/// The payload a cell's filled sites carry, framed in a sheet.4pub mod carry;5/// The fill, void, perimeter, corner, edge and Euler counts of a flat cell.6pub mod census;7/// The builders of coded, corner, noise and carpet cells.8pub mod designs;9/// The merges, magic folds, masked mosaics and the cube lift of flat cells.10pub mod geometry;11/// The text and PNG renderings of a flat cell.12pub mod renderer;13/// The JSON form of a flat cell.14pub mod serializer;15/// The random tiles and the flat cells they build.16pub mod tile;1718pub use crate::math::dim::graph::{core_graph, edge_graph, tunnel_graph};19pub use crate::math::dim::models::Cell2d;20pub use crate::math::dim::paint;21pub use carry::{capacity, embed, extract, read, sheet};22pub use census::{census, euler, fills, Census};23pub use designs::{24    carpet, create, dust, from_corners, hline, htree, level_set, levels_code, named, net, ones,25    point, star, vline, void, vtree, zeros,26};27pub use geometry::{magic, merge, mosaic, special, to_3d};28pub use renderer::{png, text};29pub use serializer::{from_json, to_json};30pub use tile::{build, create as create_tile, random_tile};3132#[cfg(test)]33mod tests {34    use super::*;35    use crate::core::colors::{BLACK, WHITE};36    use crate::num::graph::census;37    #[test]38    fn default_paint_is_black_on_white() {39        let c = paint(designs::carpet(3, 1).unwrap(), None, None);40        let colors = c.cell.colors.as_ref().unwrap();41        assert_eq!(colors[0], [BLACK.r, BLACK.g, BLACK.b, 255]);42        assert_eq!(colors[4], [WHITE.r, WHITE.g, WHITE.b, 255]);43        let blacks = colors44            .iter()45            .filter(|c| **c == [BLACK.r, BLACK.g, BLACK.b, 255])46            .count();47        assert_eq!(blacks as u64, designs::carpet(3, 1).unwrap().types().sum());48    }49    #[test]50    fn carpet_graphs() {51        let cell = designs::carpet(3, 1).unwrap();52        let core = core_graph(&cell).unwrap();53        assert_eq!(core.nodes.len(), 8);54        assert_eq!(core.branches.len(), 8);55        assert_eq!(census(&core).components, 1);56        assert_eq!(tunnel_graph(&cell).unwrap().nodes.len(), 1);57        assert!(edge_graph(&cell).unwrap().nodes.len() > 8);58    }59}6061#[cfg(test)]62mod spectra {63    use super::*;64    use crate::num::graph::census;65    use crate::num::spectrum::{clusters, laplacian_spectrum, multiplicity};6667    #[test]68    fn the_sierpinski_normalised_spectrum_holds_its_degeneracy_table() {69        let root = 30f64.sqrt() / 6.0;70        let rows = [71            (1usize, 3usize, 3usize, 0usize, 0.0000, 1usize, 0usize),72            (2, 9, 7, 1, 0.3333, 3, 1),73            (3, 27, 17, 3, 0.4815, 9, 2),74            (4, 81, 43, 9, 0.5802, 27, 4),75            (5, 243, 111, 25, 0.6461, 81, 10),76            (6, 729, 289, 67, 0.6955, 243, 28),77        ];78        for (level, nodes, distinct, classes, fraction, one, pair) in rows {79            let cell = designs::create(7, 2, level, 0, 2).unwrap();80            let graph = core_graph(&cell).unwrap();81            assert_eq!(graph.nodes.len(), nodes, "l={level}");82            assert_eq!(census(&graph).components, 1, "l={level}");83            let spectrum = laplacian_spectrum(&graph, true).unwrap();84            let groups = clusters(&spectrum, 1e-9);85            let repeated: usize = groups.iter().filter(|g| g.1 > 1).map(|g| g.1).sum();86            assert_eq!(groups.len(), distinct, "l={level}");87            assert_eq!(88                groups.iter().filter(|g| g.1 > 1).count(),89                classes,90                "l={level}"91            );92            let got = (repeated as f64 / nodes as f64 * 10000.0).round() / 10000.0;93            assert!((got - fraction).abs() < 1e-9, "l={level} {got}");94            assert_eq!(multiplicity(&spectrum, 1.0, 1e-12), one, "l={level}");95            assert_eq!(96                multiplicity(&spectrum, 1.0 - root, 1e-12),97                pair,98                "l={level}"99            );100            assert_eq!(101                multiplicity(&spectrum, 1.0 + root, 1e-12),102                pair,103                "l={level}"104            );105        }106    }107}