src/main.rs

changeset 11
933242e0f3b8
parent 9
0fa3ac0c248b
child 12
3b05a8b45b95
equal deleted inserted replaced
10:cd6f6e7defd2 11:933242e0f3b8
6 #![allow(confusable_idents)] 6 #![allow(confusable_idents)]
7 7
8 use dist::DistToSquaredDiv2; 8 use dist::DistToSquaredDiv2;
9 use fb::forward_backward; 9 use fb::forward_backward;
10 use manifold::EmbeddedManifoldPoint; 10 use manifold::EmbeddedManifoldPoint;
11 use cube::*;
12 use image::{
13 ImageFormat,
14 ImageBuffer,
15 Rgb
16 };
11 17
12 mod manifold; 18 mod manifold;
13 mod fb; 19 mod fb;
14 mod cube; 20 mod cube;
15 mod dist; 21 mod dist;
18 fn main() { 24 fn main() {
19 simple_test() 25 simple_test()
20 } 26 }
21 27
22 fn simple_test() { 28 fn simple_test() {
23 use cube::*;
24 use alg_tools::loc::Loc; 29 use alg_tools::loc::Loc;
25 use Face::*; 30 use Face::*;
26 use zero::ZeroFn; 31 use zero::ZeroFn;
27 use alg_tools::mapping::Sum; 32 use alg_tools::mapping::{Sum, Apply};
28 use alg_tools::iterate::{AlgIteratorOptions, Verbose}; 33 use alg_tools::iterate::{AlgIteratorOptions, Verbose};
29 34
30 let points = [ 35 let points = [
31 //OnCube::new(F1, Loc([0.5, 0.5])), 36 //OnCube::new(F1, Loc([0.5, 0.5])),
32 //OnCube::new(F2, Loc([0.5, 0.5])), 37 //OnCube::new(F2, Loc([0.5, 0.5])),
48 .. Default::default() 53 .. Default::default()
49 }; 54 };
50 55
51 let x̂ = forward_backward(&f, &g, x, τ, iter); 56 let x̂ = forward_backward(&f, &g, x, τ, iter);
52 println!("result = {}\n{:?}", x̂.embedded_coords(), &x̂); 57 println!("result = {}\n{:?}", x̂.embedded_coords(), &x̂);
58
59 for face in Face::all() {
60 write_face(format!("{face}"), face, 128, |x| f.apply(x) + g.apply(x))
61 }
53 } 62 }
63
64 fn write_face(filename : String, face : Face, n : usize, mut f : impl FnMut(&OnCube) -> f64) {
65 use alg_tools::lingrid::LinSpace;
66 use alg_tools::loc::Loc;
67 use alg_tools::types::*;
68
69 let mut img = ImageBuffer::new(n as u32, n as u32);
70 let grid = LinSpace {
71 start : Loc([0.0, 0.0]),
72 end : Loc([1.0, 1.0]),
73 count : [n, n]
74 };
75 let rawdata : Vec<_> = grid.into_iter()
76 .map(|x| f(&OnCube::new(face, x)))
77 .collect();
78 let a = rawdata.iter().copied().reduce(f64::max).unwrap();
79 img.pixels_mut()
80 .zip(rawdata)
81 .for_each(|(p, v)| {
82 let t = v/a;
83 let rgb = [1.0-t, 1.0-t, 1.0];
84 *p = Rgb(rgb.map(|v| (v*(u8::RANGE_MAX as f64)) as u8))
85 });
86
87 img.save_with_format(format!("{filename}.png"), ImageFormat::Png)
88 .expect("Image save error");
89 }

mercurial