1extern crate cfg_if;
2extern crate wasm_bindgen;
3
4mod utils;
5mod colormaps;
6mod variable_mesh;
7mod fixed_resolution_buffer;
8
9use cfg_if::cfg_if;
10
11pub use variable_mesh::VariableMesh;
12pub use colormaps::ColormapCollection;
13pub use fixed_resolution_buffer::FixedResolutionBuffer;
14
15cfg_if! {
16 if #[cfg(feature = "wee_alloc")] {
19 extern crate wee_alloc;
20 #[global_allocator]
21 static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
22 }
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn deposit_vm_fixed_res() {
31 let mut px: Vec<f64> = Vec::new();
33 let mut py: Vec<f64> = Vec::new();
34 let mut pdx: Vec<f64> = Vec::new();
35 let mut pdy: Vec<f64> = Vec::new();
36 let mut field: Vec<f64> = Vec::new();
37
38 let _nval = 32;
39 let _npix = 1024;
40
41 let mut sum_x = 0.0;
44 let mut sum_y = 0.0;
45 let mut widths_x: Vec<f64> = Vec::new();
47 let mut widths_y: Vec<f64> = Vec::new();
48 for _i in 0.._nval {
49 let _px = (1.0 - sum_x)/2.0;
52 let _py = (0.9 - sum_y)/2.0;
55 widths_x.push(_px/2.0);
56 widths_y.push(_py/2.0);
57 sum_x += _px;
58 sum_y += _py;
59 }
60
61 widths_x.push((1.0 - sum_x)/2.0);
62 widths_y.push((1.0 - sum_y)/2.0);
63
64 let mut x;
65 let mut y;
66
67 x = 0.0;
68 y = 0.0;
69 for &_pdx in widths_x.iter() {
70 x += _pdx;
71 y = 0.0;
72 for &_pdy in widths_y.iter() {
73 y += _pdy;
74 px.push(x);
75 py.push(y);
76 pdx.push(_pdx);
77 pdy.push(_pdy);
78 field.push(1.0);
79 y += _pdy;
80 }
81 assert_eq!(y, 1.0);
82 x += _pdx;
83 }
84
85 assert_eq!(x, 1.0);
86
87 let _vm = VariableMesh::new(px, py, pdx, pdy, field);
88
89 for pixel in _vm.iter() {
90 assert_eq!(pixel.val, 1.0);
91 }
92
93 let mut _frb_test = FixedResolutionBuffer::new(_npix, _npix, 0.0, 1.0, 0.0, 1.0);
94
95 let mut buffer: Vec<f64> = Vec::new();
96 buffer.resize(_npix * _npix, 0.0);
97
98 let _count = _frb_test.deposit(&_vm, buffer.as_mut_slice());
101
102 for &v in buffer.iter() {
103 assert_eq!(v, 1.0);
104 }
105 }
106}