Skip to content

Commit

Permalink
Updated dependencies to support WebAssembly
Browse files Browse the repository at this point in the history
  • Loading branch information
ReeceHumphreys committed Jan 23, 2024
1 parent 9725ddb commit 879eed6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
8 changes: 6 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::satellite::{SatKind, Satellite};

use ndarray::*;
use ndarray_linalg::*;
use wasm_bindgen::prelude::*;

pub trait FragmentationEvent {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>) -> f32 {
arr.iter().map(|x| x.powi(2)).sum::<f32>().sqrt()
}

0 comments on commit 879eed6

Please sign in to comment.