Added bodies

This commit is contained in:
Verox001 2025-05-04 00:02:35 +02:00
parent 0b12eb7384
commit be15311c55
3 changed files with 27 additions and 13 deletions

View File

@ -1,3 +1,10 @@
use solar_engine::Body;
fn main() { fn main() {
println!("Hello, world!"); 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);
} }

18
solar_engine/src/body.rs Normal file
View File

@ -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,
}
}
}

View File

@ -1,14 +1,3 @@
pub fn add(left: u64, right: u64) -> u64 { mod body;
left + right pub use body::Body;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}