From 4e8f49320170f29bb91a572eba3341ec6db2a4d1 Mon Sep 17 00:00:00 2001 From: Ben Plate Date: Tue, 14 Jun 2022 15:30:40 -0700 Subject: [PATCH 1/5] increment version number --- Cargo.toml | 2 +- website-src/package-lock.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cccfc5a..40d6281 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "solar-sim" -version = "0.2.1" +version = "0.2.2" authors = ["Ben Plate "] edition = "2018" description = "Physics simulator written in Rust WASM for use in Solar Sim website" diff --git a/website-src/package-lock.json b/website-src/package-lock.json index e6c8a78..ad29472 100644 --- a/website-src/package-lock.json +++ b/website-src/package-lock.json @@ -1,12 +1,12 @@ { "name": "solar-sim-app", - "version": "0.2.1", + "version": "0.2.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "solar-sim-app", - "version": "0.2.1", + "version": "0.2.2", "license": "MIT", "dependencies": { "solar-sim": "file:../pkg" From 47123850ec6e1ea2566d3fd967a772279281ff59 Mon Sep 17 00:00:00 2001 From: Ben Plate Date: Tue, 14 Jun 2022 15:32:15 -0700 Subject: [PATCH 2/5] optimize distance calculations --- rust-src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/rust-src/lib.rs b/rust-src/lib.rs index be6137f..b3350c9 100644 --- a/rust-src/lib.rs +++ b/rust-src/lib.rs @@ -51,10 +51,7 @@ impl Body<'_> { let angle = dy.atan2(dx); - let distance = (dx.powf(2.0) + dy.powf(2.0)).sqrt(); - - let acceleration = BIG_G * uni[i].mass / distance.powi(2); - let delta_v = acceleration * TIME_STEP; + let delta_v = BIG_G * uni[i].mass / (dx.powf(2.0) + dy.powf(2.0)) * TIME_STEP; // (G(m1)(m2)/d^2) / m1 * t = G(m2)/d^2 * t = at = delta_v out.x += delta_v * -angle.cos(); out.y += delta_v * -angle.sin(); @@ -65,7 +62,7 @@ impl Body<'_> { } fn next_position(&self) -> Vector2D { - return Vector2D { x: self.position.x + self.velocity.x * TIME_STEP, y: self.position.y + self.velocity.y * TIME_STEP }; + return Vector2D { x: self.position.x + self.velocity.x * TIME_STEP, y: self.position.y + self.velocity.y * TIME_STEP }; // x_new = x_old + vt } } From 3aabc89435ce29e3a7ae3caecffd32f54fbcf837 Mon Sep 17 00:00:00 2001 From: Ben Plate Date: Tue, 14 Jun 2022 15:35:27 -0700 Subject: [PATCH 3/5] remove radius from simulation (for now) --- rust-src/lib.rs | 4 +--- website-src/index.js | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/rust-src/lib.rs b/rust-src/lib.rs index b3350c9..cdc3043 100644 --- a/rust-src/lib.rs +++ b/rust-src/lib.rs @@ -28,7 +28,6 @@ pub struct Vector2D { } pub struct Body<'a> { - radius: f64, mass: f64, position: Vector2D, velocity: Vector2D, @@ -98,9 +97,8 @@ pub fn step_time() { } #[wasm_bindgen] -pub fn add_body(radius: f64, mass: f64, position_x: f64, position_y: f64, velocity_x: f64, velocity_y: f64) { +pub fn add_body(mass: f64, position_x: f64, position_y: f64, velocity_x: f64, velocity_y: f64) { let new_body = Body { - radius: radius, mass: mass, position: Vector2D { x: position_x, diff --git a/website-src/index.js b/website-src/index.js index c2b570f..5baa592 100644 --- a/website-src/index.js +++ b/website-src/index.js @@ -75,7 +75,7 @@ let trails = [ for(let i = 0; i < bodies.length; i++) { let body = bodies[i]; - SolarSim.add_body(body.name, body.mass, body.position[0], body.position[1], body.initialVelocity[0], body.initialVelocity[1]); + SolarSim.add_body(body.mass, body.position[0], body.position[1], body.initialVelocity[0], body.initialVelocity[1]); } const canvas = document.getElementById("scene"); @@ -170,6 +170,6 @@ spawnButton.addEventListener("click", (elem, e) => { }); trails.push([]); - SolarSim.add_body(radius, mass, positionX, positionY, velocityX, velocityY); + SolarSim.add_body(mass, positionX, positionY, velocityX, velocityY); step(false); }) \ No newline at end of file From 1aab09b39017c0b8f8eed7ff2deb2226dc5bf390 Mon Sep 17 00:00:00 2001 From: Ben Plate Date: Tue, 14 Jun 2022 15:35:37 -0700 Subject: [PATCH 4/5] formatting stuff --- Cargo.toml | 2 +- rust-src/lib.rs | 2 +- website-src/index.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 40d6281..adad9a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,4 +38,4 @@ wasm-bindgen-test = "0.3.13" [profile.release] # Tell `rustc` to optimize for small code size. opt-level = "s" -lto = true \ No newline at end of file +lto = true diff --git a/rust-src/lib.rs b/rust-src/lib.rs index cdc3043..ca090fb 100644 --- a/rust-src/lib.rs +++ b/rust-src/lib.rs @@ -138,4 +138,4 @@ pub fn get_positions() -> Array { } return out; -} \ No newline at end of file +} diff --git a/website-src/index.js b/website-src/index.js index 5baa592..18034e3 100644 --- a/website-src/index.js +++ b/website-src/index.js @@ -172,4 +172,4 @@ spawnButton.addEventListener("click", (elem, e) => { trails.push([]); SolarSim.add_body(mass, positionX, positionY, velocityX, velocityY); step(false); -}) \ No newline at end of file +}) From 0f135400a76fed4e2fd176d92c0db4f3fcb20b12 Mon Sep 17 00:00:00 2001 From: Ben Plate Date: Tue, 14 Jun 2022 15:53:30 -0700 Subject: [PATCH 5/5] remove old wasm files on build --- website-src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website-src/package.json b/website-src/package.json index 17aa1d3..b57314b 100644 --- a/website-src/package.json +++ b/website-src/package.json @@ -4,7 +4,7 @@ "description": "Creates the Solar Sim website.", "main": "index.js", "scripts": { - "build": "webpack --config webpack.config.js", + "build": "rm -rf dist/*.wasm && webpack --config webpack.config.js", "start": "webpack-dev-server" }, "keywords": [