demo-zeta.rs

1.6 kB · rust · 44 lines

1use mrlycore::errors::Result;2use mrlyfig::{ink, save, Board};3use mrlynum::zeta::Line;45const REACH: f64 = 50.0;6const STEPS: usize = 8000;78fn main() -> Result<()> {9    let line = Line::new();10    let zeros = line.zeros(10);11    assert_eq!(line.count(REACH), 10);12    assert!((zeros[0] - 14.134725).abs() < 1e-5);13    assert!(*zeros.last().unwrap() < REACH);14    let path: Vec<(f64, f64)> = (0..=STEPS)15        .map(|step| {16            let value = line.point(REACH * step as f64 / STEPS as f64).0;17            (value.re, value.im)18        })19        .collect();20    assert_eq!(path.len(), STEPS + 1);2122    let mut board = Board::square();23    let frame = board.frame(0.08);24    let box_of = |pick: fn(&(f64, f64)) -> f64, fold: fn(f64, f64) -> f64| {25        path.iter().map(pick).fold(0.0, fold)26    };27    let (left, right) = (box_of(|p| p.0, f64::min), box_of(|p| p.0, f64::max));28    let (under, over) = (box_of(|p| p.1, f64::min), box_of(|p| p.1, f64::max));29    let unit = frame.w.min(frame.h) / (right - left).max(over - under);30    let (mid_x, mid_y) = frame.center();31    let cx = mid_x - 0.5 * (left + right) * unit;32    let cy = mid_y + 0.5 * (under + over) * unit;33    board.segment((frame.x, cy), (frame.x + frame.w, cy), 2.0, ink::line());34    board.segment((cx, frame.y), (cx, frame.y + frame.h), 2.0, ink::line());35    board.ring(cx, cy, unit, 2.0, ink::line());36    let plane: Vec<(f64, f64)> = path37        .iter()38        .map(|(re, im)| (cx + re * unit, cy - im * unit))39        .collect();40    board.polyline(&plane, 2.5, ink::blue());41    board.ring(cx, cy, unit * 0.07, 7.0, ink::yellow());42    save("demo-zeta", &board)?;43    Ok(())44}