From be15311c55507e7383ff959da6fd1189810c348c Mon Sep 17 00:00:00 2001 From: Verox001 Date: Sun, 4 May 2025 00:02:35 +0200 Subject: [PATCH] Added bodies --- simulator/src/main.rs | 7 +++++++ solar_engine/src/body.rs | 18 ++++++++++++++++++ solar_engine/src/lib.rs | 15 ++------------- 3 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 solar_engine/src/body.rs diff --git a/simulator/src/main.rs b/simulator/src/main.rs index e7a11a9..ab168c9 100644 --- a/simulator/src/main.rs +++ b/simulator/src/main.rs @@ -1,3 +1,10 @@ +use solar_engine::Body; + fn main() { println!("Hello, world!"); + let earth = Body::new("Earth", 5.972e24, [1.496e11, 0.0], [0.0, 0.0]); + println!("Created body: {:?}", earth); + + let sun = Body::new("Sun", 1.989e30, [0.0, 0.0], [0.0, 0.0]); + println!("Created body: {:?}", sun); } diff --git a/solar_engine/src/body.rs b/solar_engine/src/body.rs new file mode 100644 index 0000000..5de5a52 --- /dev/null +++ b/solar_engine/src/body.rs @@ -0,0 +1,18 @@ +#[derive(Debug)] +pub struct Body { + pub name: String, + pub mass: f64, + pub position: [f64; 2], + pub velocity: [f64; 2], +} + +impl Body { + pub fn new(name: &str, mass: f64, position: [f64; 2], velocity: [f64; 2]) -> Self { + Self { + name: name.to_string(), + mass, + position, + velocity, + } + } +} \ No newline at end of file diff --git a/solar_engine/src/lib.rs b/solar_engine/src/lib.rs index b93cf3f..9eb7368 100644 --- a/solar_engine/src/lib.rs +++ b/solar_engine/src/lib.rs @@ -1,14 +1,3 @@ -pub fn add(left: u64, right: u64) -> u64 { - left + right -} +mod body; +pub use body::Body; -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -}