1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
extern crate cfg_if;
extern crate wasm_bindgen;

mod utils;
mod colormaps;
mod variable_mesh;
mod fixed_resolution_buffer;

use cfg_if::cfg_if;

pub use variable_mesh::VariableMesh;
pub use colormaps::ColormapCollection;
pub use fixed_resolution_buffer::FixedResolutionBuffer;

cfg_if! {
    // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
    // allocator.
    if #[cfg(feature = "wee_alloc")] {
        extern crate wee_alloc;
        #[global_allocator]
        static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn deposit_vm_fixed_res() {
        // This should eventually be parameterized.
        let mut px: Vec<f64> = Vec::new();
        let mut py: Vec<f64> = Vec::new();
        let mut pdx: Vec<f64> = Vec::new();
        let mut pdy: Vec<f64> = Vec::new();
        let mut field: Vec<f64> = Vec::new();

        let _nval = 32;
        let _npix = 1024;

        // We will now create a generic mesh

        let mut sum_x = 0.0;
        let mut sum_y = 0.0;
        // Compute our widths, which we'll use to generate the 
        let mut widths_x: Vec<f64> = Vec::new();
        let mut widths_y: Vec<f64> = Vec::new();
        for _i in 0.._nval {
            // Just some generic values which we'll clean up at the end.
            // We do the second divide by two so that we have half-widths
            let _px = (1.0 - sum_x)/2.0;
            // Also note that we're going to do something funky here,
            // just to make sure we're not always the same for x and y.
            let _py = (0.9 - sum_y)/2.0;
            widths_x.push(_px/2.0);
            widths_y.push(_py/2.0);
            sum_x += _px;
            sum_y += _py;
        }

        widths_x.push((1.0 - sum_x)/2.0);
        widths_y.push((1.0 - sum_y)/2.0);

        let mut x;
        let mut y;

        x = 0.0;
        y = 0.0;
        for &_pdx in widths_x.iter() {
            x += _pdx;
            y = 0.0;
            for &_pdy in widths_y.iter() {
                y += _pdy;
                px.push(x);
                py.push(y);
                pdx.push(_pdx);
                pdy.push(_pdy);
                field.push(1.0);
                y += _pdy;
            }
            assert_eq!(y, 1.0);
            x += _pdx;
        }

        assert_eq!(x, 1.0);

        let _vm = VariableMesh::new(px, py, pdx, pdy, field);

        for pixel in _vm.iter() {
            assert_eq!(pixel.val, 1.0);
        }

        let mut _frb_test = FixedResolutionBuffer::new(_npix, _npix, 0.0, 1.0, 0.0, 1.0);

        let mut buffer: Vec<f64> = Vec::new();
        buffer.resize(_npix * _npix, 0.0);

        // This does not always work, because of how we compute rows and columns,
        // so we don't assert.  We will eventually do so, though.
        let _count = _frb_test.deposit(&_vm, buffer.as_mut_slice());

        for &v in buffer.iter() {
            assert_eq!(v, 1.0);
        }
    }
}