mod.rs
2.4 kB · rust · 88 lines
1//! The moire fields.2//!3//! One design sampled at many scales and stacked makes an interference pattern; the layers, their4//! combination, the volume they cut and the PNG they render live here.56use serde::{Deserialize, Serialize};78/// The square grid of f32 samples.9pub mod field;10/// The recipe and sampling of one moire layer.11pub mod layer;12/// The exact correlations of flat carpet layers, and the prime detector they make.13pub mod pairs;14/// The named recipes: the parity heatmap, its weave, its hive and the carpet stack.15pub mod presets;16/// The quantized PNG rendering of a field.17pub mod render;18/// The lattice coordinates and code-membership tests behind the layers.19pub mod sample;20/// The stacking of layers into one combined field.21pub mod stack;22/// The cube designs stacked into a volume, and the planes that cut it.23pub mod volume;2425/// The sampling lattice of a moire field.26#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]27pub enum Lattice {28 /// The square lattice.29 Square,30 /// The hexagonal lattice.31 Hex,32}3334/// The way stacked layers merge.35#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]36pub enum Combine {37 /// The layer-count sum.38 Sum,39 /// The intersection.40 And,41 /// The parity.42 Xor,43}4445/// The identity of a design: its code, base and dimension.46#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]47pub struct Spec {48 /// The design code.49 pub code: u128,50 /// The residue base.51 pub base: usize,52 /// The design dimension.53 pub dimension: usize,54}5556impl Spec {57 /// Builds a spec from a code, base and dimension.58 pub fn new(code: u128, base: usize, dimension: usize) -> Spec {59 Spec {60 code,61 base,62 dimension,63 }64 }65}6667pub use field::Field;68pub use layer::{layer, Layer};69pub use presets::{all, named, Preset};70pub use render::render;71pub use stack::{merge, stack, stack_codes};72pub use volume::{frame, volume, Frame, Volume};7374#[cfg(test)]75mod tests {76 use super::{Combine, Field, Lattice, Spec};77 use crate::math::moire::pairs::witness;78 use crate::math::round_trip;7980 #[test]81 fn serde_round_trips() {82 round_trip(Spec::new(7, 2, 2));83 round_trip(Lattice::Hex);84 round_trip(Combine::Xor);85 round_trip(Field::new(2));86 round_trip(witness(9).unwrap());87 }88}