1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
//! Particular is a crate providing a simple way to simulate N-body gravitational interaction of particles in Rust.
//! The API to setup a simulation is straightforward:
//!
//! ## Implementing the [`Particle`] trait.
//! It can be derived if your type contains both a `position` and a `mu` field.
//! ```
//! #[derive(Particle)]
//! pub struct Body {
//! position: Vec3,
//! mu: f32,
//! ...
//! }
//! ```
//! It can also be implemented manually.
//! ```
//! impl Particle for Body {
//! fn position(&self) -> Vec3 {
//! self.position
//! }
//!
//! fn mu(&self) -> f32 {
//! self.mass * G
//! }
//! }
//! ```
//! ## Setting up the simulation.
//! Using your type implementing [`Particle`], you will need to create a [`ParticleSet`] that will contain the particles. It will only handle the gravitational acceleration calculations.
//!
//! Currently, it stores the particles in two different vectors depending on if the particle has mass or doesn't. This allows optimizations in the case of massless particles (which can represent objects that do not need to affect other objects, like a spaceship).
//! ```
//! let mut particle_set = ParticleSet::new();
//! // If the type cannot be inferred, use the turbofish syntax:
//! let mut particle_set = ParticleSet::<Body>::new();
//! particle_set.add(Body { position, mu });
//! ```
//! ## Computing and using the gravitational acceleration.
//! Finally, using the `result` method of [`ParticleSet`], you can iterate over the computed gravitational acceleration of each particle.
//! ```
//! for (particle, acceleration) in particle_set.result() {
//! ...
//! }
//! ```
//! `body` here being of the type you used for the [`ParticleSet`].
mod particle;
mod particle_set;
pub use particle::*;
pub use particle_set::*;
pub mod prelude {
pub use crate::{Particle, ParticleSet};
pub use particular_derive::Particle;
}
#[cfg(test)]
mod tests {
// TODO!
}