--- a/src/main.rs Tue Oct 22 09:41:47 2024 -0500 +++ b/src/main.rs Fri Oct 25 13:16:25 2024 -0500 @@ -9,18 +9,22 @@ #![allow(confusable_idents)] use serde::Serialize; +use alg_tools::logger::Logger; +use alg_tools::tabledump::{TableDump, write_csv}; +use alg_tools::error::DynError; +use alg_tools::lingrid::LinSpace; +use alg_tools::loc::Loc; +use alg_tools::types::*; +use alg_tools::mapping::{Sum, Apply}; +use alg_tools::iterate::{AlgIteratorOptions, AlgIteratorFactory, Verbose}; +use image::{ImageFormat, ImageBuffer, Rgb}; + use dist::DistToSquaredDiv2; use fb::{forward_backward, IterInfo}; use manifold::EmbeddedManifoldPoint; -use alg_tools::logger::Logger; -use alg_tools::tabledump::TableDump; -use alg_tools::error::DynError; use cube::*; -use image::{ - ImageFormat, - ImageBuffer, - Rgb -}; +use Face::*; +use zero::ZeroFn; mod manifold; mod fb; @@ -49,11 +53,6 @@ /// A simple test on the cube fn simple_cube_test() -> DynError { - use alg_tools::loc::Loc; - use Face::*; - use zero::ZeroFn; - use alg_tools::mapping::{Sum, Apply}; - use alg_tools::iterate::{AlgIteratorOptions, AlgIteratorFactory, Verbose}; let points = [ //OnCube::new(F1, Loc([0.5, 0.5])), @@ -92,7 +91,8 @@ logger.write_csv(format!("{PREFIX}/log.txt"))?; for face in Face::all() { - write_face(format!("{PREFIX}/{face}"), face, 128, |x| f.apply(x) + g.apply(x))?; + write_face_csv(format!("{PREFIX}/{face}"), face, 64, |x| f.apply(x) + g.apply(x))?; + write_face_img(format!("{PREFIX}/{face}"), face, 128, |x| f.apply(x) + g.apply(x))?; } Ok(()) @@ -100,11 +100,7 @@ /// Writes the values of `f` on `face` of a [`OnCube`] into a PNG file /// with resolution `n × n`. -fn write_face(filename : String, face : Face, n : usize, mut f : impl FnMut(&OnCube) -> f64) -> DynError { - use alg_tools::lingrid::LinSpace; - use alg_tools::loc::Loc; - use alg_tools::types::*; - +fn write_face_img(filename : String, face : Face, n : usize, mut f : impl FnMut(&OnCube) -> f64) -> DynError { let mut img = ImageBuffer::new(n as u32, n as u32); let grid = LinSpace { start : Loc([0.0, 0.0]), @@ -127,3 +123,24 @@ Ok(()) } + +/// Writes the values of `f` on `face` of a [`OnCube`] into a CSV file +/// with resolution `n × n`. +fn write_face_csv(filename : String, face : Face, n : usize, mut f : impl FnMut(&OnCube) -> f64) -> DynError { + + #[derive(Serialize)] + struct CSVFace { u : f64, v : f64, value : f64 } + + let grid = LinSpace { + start : Loc([0.0, 0.0]), + end : Loc([1.0, 1.0]), + count : [n, n] + }; + + let data = grid.into_iter() + .map(|p@Loc([u,v])| CSVFace{ u, v, value : f(&OnCube::new(face, p)) }); + + write_csv(data, format!("{filename}.csv"))?; + + Ok(()) +}