diff --git a/Cargo.toml b/Cargo.toml index 6af2de1..4c65bb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,18 +12,23 @@ Kessler is a library for simulating fragmentation events in low Earth orbit. """ [dependencies] -blas-src = { version = "0.8", features = ["openblas"] } -js-sys = "0.3.67" -ndarray = { version = "=0.15.6", features = ["blas", "rayon", "serde"] } -ndarray-linalg = "0.14" +ndarray = { version = "0.15.6", features = ["rayon", "serde"] } ndarray-rand = "0.13.0" -openblas-src = { version = "0.10", features = ["cblas", "system"] } rand = "0.8.5" rand_distr = "0.4.3" serde = { version = "1.0", features = ["derive"] } serde-wasm-bindgen = "0.4" wasm-bindgen = { version = "0.2.90", features = ["serde"]} +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +blas-src = { version = "0.8", features = ["openblas"] } +ndarray-linalg = "0.14" +openblas-src = { version = "0.10", features = ["cblas", "system"] } + +[target.'cfg(target_arch = "wasm32")'.dependencies] +js-sys = "0.3.67" +getrandom = { version = "0.2", features = ["js"] } + [lib] crate-type = ["cdylib", "rlib"] diff --git a/src/event.rs b/src/event.rs index f87bca3..4f521bb 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,7 +1,6 @@ use crate::satellite::{SatKind, Satellite}; use ndarray::*; -use ndarray_linalg::*; use wasm_bindgen::prelude::*; pub trait FragmentationEvent { @@ -96,7 +95,7 @@ impl FragmentationEvent for CollisionEvent { // Determine impact velocity let v1 = satellite_1.get_velocity(); let v2 = satellite_2.get_velocity(); - let v_impact = (Array1::from_vec(v1) - Array1::from_vec(v2)).norm(); + let v_impact = norm(Array1::from_vec(v1) - Array1::from_vec(v2)); // Target is the larger satellite let m_targ = satellite_1.mass; @@ -198,3 +197,8 @@ impl FragmentationEvent for ExplosionEvent { [0.2, 1.85] } } + +// Calculate the l-2 norm of an array +fn norm(arr: Array1) -> f32 { + arr.iter().map(|x| x.powi(2)).sum::().sqrt() +}