wiki-gaussian-integers.rs

1.2 kB · rust · 34 lines

1use mrlycore::errors::Result;2use mrlyfig::{ink, plot, save, Board};3use mrlynum::gauss::{Class, Ring, Window};45const REACH: u64 = 20;67fn main() -> Result<()> {8    let mut board = Board::square();9    let frame = board.frame(0.09);10    let window = Window::new(Ring::Gaussian, REACH);11    let census = window.census();12    assert_eq!(census.points, 1681);13    assert_eq!(census.ramified, 4);14    assert_eq!(census.split + census.inert + census.ramified, census.primes);15    let step = frame.w / (2 * REACH) as f64;16    let (cx, cy) = frame.center();17    let place = |a: i64, b: i64| (cx + a as f64 * step, cy - b as f64 * step);18    let mut broken = Vec::new();19    let mut whole = Vec::new();20    for (a, b) in window.points() {21        match window.class(a, b) {22            Class::Split | Class::Ramified => broken.push(place(a, b)),23            Class::Inert => whole.push(place(a, b)),24            _ => {}25        }26    }27    assert_eq!(broken.len(), census.split + census.ramified);28    assert_eq!(whole.len(), census.inert);29    let dot = step * 0.34;30    plot::dots(&mut board, &broken, dot, ink::blue());31    plot::dots(&mut board, &whole, dot, ink::orange());32    save("wiki-gaussian-integers", &board)?;33    Ok(())34}