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 } |