Skip to main content

rockets_engine/
lib.rs

1//! Powered, three-dimensional point-mass flight, using SI units and simulation time.
2//!
3//! A prescribed motor supplies thrust and consumes propellant in proportion to impulse.
4//! [`Simulator`] integrates translation while [`ForceModel`] supplies environmental
5//! acceleration and [`Guidance`] supplies optional control commands. The default
6//! `ballistics` feature reuses ballistics-engine's gravity, atmosphere and drag kernel.
7//!
8//! Coordinates are fixed, right-handed X/downrange, Y/up, Z/lateral. With the ballistics
9//! adapter, Y is altitude above sea level. No time compression occurs inside this crate.
10//! This is a point-mass model, not an attitude, actuator or aerodynamic-lift simulation.
11//!
12//! See the README and `examples/boost_coast.rs` for integration and model assumptions.
13
14#![forbid(unsafe_code)]
15#![warn(missing_docs)]
16#![doc = include_str!("../README.md")]
17
18#[cfg(feature = "ballistics")]
19pub mod ballistics;
20mod error;
21mod flight;
22mod guidance;
23mod motor;
24
25pub use error::{Error, Result};
26pub use flight::{
27    FlightState, ForceModel, IntegratorSettings, Simulator, StepResult, UniformGravity,
28};
29pub use guidance::{ControlInput, FixedDirection, Guidance, GuidanceContext};
30pub use motor::{Motor, MotorPhase, MotorSample, Rocket, RocketSample, ThrustCurve, ThrustPoint};
31
32/// Three-dimensional SI vector in the fixed world frame.
33pub type Vec3 = nalgebra::Vector3<f64>;
34
35pub(crate) fn finite_vec(value: &Vec3) -> bool {
36    value.iter().all(|x| x.is_finite())
37}
38
39pub(crate) fn nonnegative(value: f64, field: &'static str) -> Result<()> {
40    if !value.is_finite() || value < 0.0 {
41        return Err(Error::invalid(field, "must be finite and nonnegative"));
42    }
43    Ok(())
44}
45
46pub(crate) fn positive(value: f64, field: &'static str) -> Result<()> {
47    if !value.is_finite() || value <= 0.0 {
48        return Err(Error::invalid(field, "must be finite and positive"));
49    }
50    Ok(())
51}