(seed: u64)
| 27 | |
| 28 | impl Simulation { |
| 29 | pub fn new(seed: u64) -> Self { |
| 30 | fastrand::seed(seed); |
| 31 | let mut bodies = Vec::new(); |
| 32 | |
| 33 | let n = 3; |
| 34 | for _ in 0..n { |
| 35 | bodies.push(rand_body()); |
| 36 | } |
| 37 | |
| 38 | let vel = bodies.iter().map(|b| b.vel * b.mass).sum::<Vec2>() / n as Real; |
| 39 | let pos = bodies.iter().map(|b| b.pos * b.mass).sum::<Vec2>() / n as Real; |
| 40 | for b in &mut bodies { |
| 41 | b.vel -= vel; |
| 42 | b.pos -= pos; |
| 43 | } |
| 44 | let r = bodies.iter().map(|b| b.pos.mag()).max_by(Real::total_cmp).unwrap(); |
| 45 | for b in &mut bodies { |
| 46 | b.pos /= r; |
| 47 | } |
| 48 | |
| 49 | Self { |
| 50 | bodies, |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | pub fn update(&mut self) { |
| 55 | for i in 0..self.bodies.len() { |
nothing calls this directly
no test coverage detected