use ndarray

This commit is contained in:
Magnus Ulimoen 2019-07-21 13:32:20 +02:00
parent e16f136a59
commit 4304c3e59d
2 changed files with 7 additions and 3 deletions

View File

@ -14,6 +14,7 @@ default = ["console_error_panic_hook", "wee_alloc"]
wasm-bindgen = "*"
console_error_panic_hook = { version = "*", optional = true }
wee_alloc = { version = "*", optional = true }
ndarray = "0.12.1"
[profile.release]
opt-level = "s"

View File

@ -1,3 +1,4 @@
use ndarray::Array2;
use wasm_bindgen::prelude::*;
#[cfg(feature = "wee_alloc")]
@ -13,7 +14,7 @@ pub fn set_panic_hook() {
pub struct Universe {
width: u32,
height: u32,
field: Vec<f32>,
field: Array2<f32>,
}
const WAVESPEED: f32 = 1.0;
@ -28,10 +29,12 @@ impl Universe {
pub fn new(width: u32, height: u32) -> Self {
set_panic_hook();
let field = Array2::zeros((height as usize, width as usize));
Universe {
width,
height,
field: vec![0.0; width as usize * height as usize],
field,
}
}
@ -40,7 +43,7 @@ impl Universe {
for i in 0..self.width {
let x = i as f32 / self.width as f32;
let y = j as f32 / self.height as f32;
self.field[(self.width * j + i) as usize] = func(x, y, t);
self.field[(j as usize, i as usize)] = func(x, y, t);
}
}
}