Skip to main content

rockets_engine/
lib.rs

1//! Powered, three-dimensional point-mass flight, using SI units and simulation time.
2//!
3//! Prescribed motors supply thrust and consume propellant in proportion to impulse;
4//! [`Stage`]s add serial or parallel staging with scheduled separations. [`Simulator`]
5//! integrates translation while [`ForceModel`] supplies environmental acceleration and
6//! [`Guidance`] supplies optional control commands. [`UniformGravity`] covers local
7//! flat-frame flight and [`CentralGravity`] covers planet-scale arcs; the default
8//! `ballistics` feature reuses ballistics-engine's atmosphere and drag kernel.
9//!
10//! Coordinates are right-handed; the conventional local frame is X/downrange, Y/up,
11//! Z/lateral, but [`CentralGravity`] works in an Earth-centered frame of the caller's
12//! choosing. No time compression occurs inside this crate. This is a point-mass model,
13//! not an attitude, actuator or aerodynamic-lift simulation.
14//!
15//! See the README and `examples/boost_coast.rs` for integration and model assumptions.
16
17// wasm-bindgen generates unsafe blocks, so the wasm build cannot keep the forbid.
18#![cfg_attr(not(feature = "wasm"), forbid(unsafe_code))]
19#![warn(missing_docs)]
20#![doc = include_str!("../README.md")]
21
22#[cfg(feature = "ballistics")]
23pub mod ballistics;
24#[cfg(any(feature = "cli", feature = "wasm"))]
25pub mod command;
26mod error;
27mod flight;
28mod guidance;
29mod motor;
30#[cfg(feature = "wasm")]
31pub mod wasm;
32
33pub use error::{Error, Result};
34pub use flight::{
35    AltitudeSwitch, CentralGravity, FlightState, ForceModel, IntegratorSettings, Simulator,
36    StepResult, UniformGravity, EARTH_MU_M3_S2,
37};
38pub use guidance::{ControlInput, FixedDirection, Guidance, GuidanceContext};
39pub use motor::{
40    Motor, MotorPhase, MotorSample, Rocket, RocketSample, Stage, ThrustCurve, ThrustPoint,
41};
42
43/// Three-dimensional SI vector in the fixed world frame.
44pub type Vec3 = nalgebra::Vector3<f64>;
45
46pub(crate) fn finite_vec(value: &Vec3) -> bool {
47    value.iter().all(|x| x.is_finite())
48}
49
50pub(crate) fn nonnegative(value: f64, field: &'static str) -> Result<()> {
51    if !value.is_finite() || value < 0.0 {
52        return Err(Error::invalid(field, "must be finite and nonnegative"));
53    }
54    Ok(())
55}
56
57pub(crate) fn positive(value: f64, field: &'static str) -> Result<()> {
58    if !value.is_finite() || value <= 0.0 {
59        return Err(Error::invalid(field, "must be finite and positive"));
60    }
61    Ok(())
62}