Skip to main content

ballistics_engine/
lib.rs

1//! # Ballistics Engine
2//!
3//! High-performance ballistics trajectory calculation engine with comprehensive physics modeling.
4//!
5//! ## Interactive Web Demo
6//!
7//! Try the ballistics engine directly in your browser at [https://ballistics.rs/](https://ballistics.rs/)
8//!
9//! ## Features
10//!
11//! - Professional-grade trajectory calculations with multiple drag models
12//! - Advanced physics including spin drift, Coriolis effect, and Magnus force
13//! - Monte Carlo simulations for uncertainty analysis
14//! - WebAssembly support for browser-based applications
15//! - FFI bindings for iOS and Android development
16
17// Re-export the main types and functions
18pub use cli_api::{
19    calculate_zero_angle, calculate_zero_angle_with_conditions,
20    calculate_zero_angle_with_resolved_conditions, calculate_zero_range_from_angle_with_conditions,
21    calculate_zero_range_from_angle_with_resolved_conditions, estimate_bc_fit,
22    estimate_bc_from_trajectory, interpolate_powder_temp_curve,
23    resolve_powder_adjusted_velocity, run_monte_carlo, run_monte_carlo_adaptive_seeded,
24    run_monte_carlo_with_direction_std_dev,
25    run_monte_carlo_with_wind, run_monte_carlo_with_wind_and_direction_std_dev,
26    run_monte_carlo_with_wind_and_direction_std_dev_seeded, AdaptiveMcReportV1,
27    AtmosphericConditions,
28    BallisticInputs, BallisticsError, BcEstimate, BcFitMode, BcReferenceStandard,
29    DropsReference, McConvergence, McStopReason, MonteCarloParams, MonteCarloResults,
30    TrajectoryPoint, TrajectoryResult,
31    TrajectorySolver,
32    WindConditions, ZeroCrossings, DEFAULT_HIT_RADIUS_M, MAX_TRAJECTORY_POINTS,
33    MC_ADAPTIVE_ASSUMPTIONS_V1, MC_ADAPTIVE_METHOD_V1, MC_ADAPTIVE_SCHEMA_VERSION_V1,
34    ZERO_RANGE_FROM_ANGLE_MAX_RANGE_M,
35    TARGET_NOT_REACHED_SENTINEL_M,
36};
37pub use atmosphere::{AtmoSegment, AtmoSock};
38pub use drag_model::DragModel;
39pub use mc_stats::{wilson_interval, ConfidenceLevel};
40pub use moving_target::{
41    calculate_lead, lead_from_tof, mover_ring, LeadComponents, LeadError, LeadSolution,
42};
43pub use solve_json::{
44    decode_solve_request_v1, ResolvedSolveRequestV1, SolveErrorCodeV1, SolveErrorEnvelopeV1,
45    SolveRequestV1, SolveSuccessV1, MAX_SOLVE_JSON_SAMPLES_V1, SOLVE_JSON_SCHEMA_VERSION_V1,
46};
47pub use solve_v1::solve_v1;
48pub use trajectory_observation::{
49    TrajectoryObservation, TrajectoryObservationError, TrajectoryObservationFlag,
50    TrajectoryTermination,
51};
52pub use trajectory_sampling::MAX_TRAJECTORY_SAMPLES;
53
54// Module declarations
55pub mod cli_api;
56// MBA-1375: deterministic reference-family BC conversion and banded least-squares family
57// recommendation, shared by native and WASM front ends. Pure table math; no filesystem I/O.
58pub mod bc_conversion;
59pub mod moving_target;
60mod drag_model;
61// The C ABI. Gated behind the default-on `ffi` feature so a binary that links two versions of
62// this crate can disable it on one edge and avoid duplicate #[no_mangle] symbols.
63#[cfg(feature = "ffi")]
64pub mod ffi;
65pub mod solve_json;
66pub mod solve_v1;
67// 0.33.0 decision-support Task 2: reverse conversion from a resolved request back into a
68// solvable one (`impl From<&ResolvedSolveRequestV1> for SolveRequestV1`), the direction the
69// perturbation kernel needs to take a resolved request, change one input, and re-solve. No
70// public items of its own -- the trait impl is usable wherever solve_json's public types are.
71mod request_roundtrip;
72pub mod terminal_plot;
73// MBA-1343: multi-observation velocity/BC truing core, shared by the CLI and the WASM terminal.
74pub mod truing;
75// MBA-1346: observation-range experiment design for identifiable MV/BC truing.
76pub mod truing_plan;
77// MBA-1353: opt-in uncertainty-aware joint MV/BC truing.
78pub mod truing_uncertainty;
79// MBA-1357: Mach-keyed DSF (drop-scale-factor) truing table — a drop-only post-processing
80// correction applied to a solved TrajectoryResult. No feature gate: must compile for wasm32;
81// fs-free (profile persistence lives in main.rs).
82pub mod truing_dsf;
83// MBA-1392: back-solve the effective crosswind from an observed horizontal miss (wind-call
84// truing). Carries its own shared table/JSON/CSV formatter so the native CLI and the WASM
85// terminal render identical bytes. No feature gate: must compile for wasm32.
86pub mod truing_wind;
87// MBA-1349: robust hold corridors across named segmented-wind scenarios. No feature gate:
88// must compile for wasm32 (the CLI surface is native-only this train, but the core and its
89// shared formatter are ready for the WASM follow-up); fs-free — file reading stays in
90// main.rs, this module parses TEXT.
91pub mod wind_scenarios;
92// MBA-1361: reticle schema, parametric generators, and the hold-point-in-reticle API,
93// shared by the CLI, the WASM terminal and the FFI. No feature gate: must compile for
94// wasm32; pure math + serde, no I/O (file reading stays in main.rs/wasm.rs).
95pub mod reticle;
96// MBA-1440: import Bero's "Ventum" reticle spec into `reticle::ReticleDescription` so a
97// reticle drawn in that tool can be hold-solved by `reticle::hold_point_in_reticle`. Pure
98// transform + serde, no I/O; must compile for wasm32. Deliberately NOT wired into the
99// CLI / solve-json / WASM / FFI surfaces yet (that exposure is held for review).
100pub mod reticle_import;
101// MBA-1343 Phase B: WEZ (`monte-carlo --wez`) sweep core, shared by the CLI and the WASM terminal.
102pub mod wez;
103// MBA-1355: turret adjustment-unit conversions (SMOA/IPHY/clicks) and click-value parsing,
104// shared by the CLI and the WASM terminal. No feature gate: must compile for wasm32.
105pub mod adjustment;
106// MBA-1409: cleanroom `.drg` (Doppler drag-curve text file) parser, shared by the CLI and
107// the WASM terminal. No feature gate: must compile for wasm32; parses TEXT only (no
108// std::fs — file I/O stays in main.rs/wasm.rs).
109pub mod drag_file;
110// MBA-1372: SAAMI free-recoil momentum-balance calculator, shared by the CLI and the
111// WASM terminal. No feature gate: must compile for wasm32; pure math, no I/O.
112pub mod recoil;
113// MBA-1372: power-factor arithmetic and per-organization (USPSA/IDPA/SASS) rulebook
114// pass/fail thresholds, shared by the CLI and the WASM terminal. No feature gate: must
115// compile for wasm32; pure math + a data table, no I/O.
116pub mod power_factor;
117pub mod trajectory_observation;
118#[cfg(target_arch = "wasm32")]
119pub mod wasm;
120#[cfg(test)]
121mod wasm_tests;
122// MBA-154: Make constants public for ballistics_rust wrapping
123pub mod atmosphere;
124pub mod constants;
125pub mod drag;
126pub mod wind;
127// MBA-153: Make wind_shear public for ballistics_rust wrapping
128pub mod wind_shear;
129// MBA-154: Make derivatives public for ballistics_rust wrapping
130pub mod derivatives;
131pub mod trajectory_sampling;
132// MBA-154: Make fast_trajectory public for ballistics_rust wrapping
133pub mod fast_trajectory;
134// MBA-155: Add advanced integration methods (RK4, RK45)
135pub mod trajectory_integration;
136// MBA-149 Phase 5 Priority 2: Export enhanced spin_drift
137pub mod pitch_damping;
138pub mod spin_decay;
139pub mod spin_drift;
140pub mod spin_drift_advanced;
141// MBA-149 Phase 5 Priority 2: Export enhanced precession_nutation
142pub mod precession_nutation;
143// MBA-153: Make aerodynamic_jump public for ballistics_rust wrapping
144pub mod aerodynamic_jump;
145// MBA-149 Phase 5 Priority 2: Export enhanced angle_calculations
146pub mod angle_calculations;
147pub mod transonic_drag;
148// MBA-153: Make reynolds public for ballistics_rust wrapping
149pub mod reynolds;
150// MBA-149 Phase 5 Priority 2: Export enhanced form_factor
151pub mod form_factor;
152// MBA-153: Make monte_carlo public for ballistics_rust wrapping
153pub mod bc_estimation;
154pub mod cluster_bc;
155// MBA-1352 Task 2: Monte Carlo hit-statistics foundation -- Welford streaming moments and
156// fixed-n Wilson score intervals. The anytime-valid confidence sequence (Task 3) extends this
157// module. No feature gate: must compile for wasm32; pure std math, no randomness.
158pub mod mc_stats;
159pub mod monte_carlo;
160pub mod stability;
161pub mod stability_advanced;
162// 0.33.0 decision-support Phase 1: shared input taxonomy for perturbation kernel and
163// uncertainty propagation. No feature gate: must compile for wasm32 (pure data + serde).
164pub mod perturbation;
165// MBA-1345: explain why two fully resolved solve results differ, by symmetric counterfactual
166// swap of each input group (built on `perturbation`'s Tasks 5-8 kernel). No feature gate: must
167// compile for wasm32 (depends only on perturbation/solve_json/solve_v1, all unconditional).
168pub mod explain;
169// MBA-1347: erf/erfc/normal_cdf for hit-probability integration (mass of a bivariate
170// normal over a target). In-crate rather than a dependency: the crate ships to thirteen
171// platforms including big-endian MIPS and wasm32 and already hand-rolls its statistical
172// constants. No feature gate: must compile for wasm32; pure std float math, no I/O.
173pub mod special;
174// 0.33.0 decision-support Task 10, MBA-1347: propagate declared per-input uncertainty to
175// impact covariance via the perturbation kernel's central differences, and rank sources by
176// variance share into a measurement-priority report. Built on `perturbation` (Tasks 5-8) and
177// reuses `truing_uncertainty::Symmetric2` for the 2x2 covariance/eigenvalue arithmetic. No
178// feature gate: must compile for wasm32 (depends only on perturbation/solve_json/
179// truing_uncertainty, all unconditional).
180pub mod error_budget;
181// 0.33.0 decision-support Task 12, MBA-1350: one-variable tolerance envelopes -- how far a
182// single input may drift from its own current value before the impact leaves an explicit
183// target, by monotone bisection outward from the nominal (`perturbation::bisect_axis`, Task 7).
184// Reuses `error_budget::TargetGeometryV1` and its unavailable-axis classification verbatim. No
185// feature gate: must compile for wasm32 (depends only on perturbation/error_budget/solve_json,
186// all unconditional).
187pub mod tolerance;
188// 0.33.0 decision-support Task 3, MBA-1348: turret + reticle geometry model (click
189// detents/revolutions, zero stop, travel limits, current turret state, reticle hold
190// bounds) that a later dial/hold/hybrid engagement planner will read. Pure data +
191// validation; no feature gate: must compile for wasm32 (depends only on `adjustment`,
192// itself unconditional).
193pub mod optic;
194// 0.33.0 decision-support Task 8: `HoldCurve`, the drop-vs-range interpolation core shared
195// by `mark-to-range`, `bdc-match`, `optimal-zero` and `reticle hold --range`, promoted out of
196// the CLI binary (together with the sampled-trajectory helpers it solves through) so the
197// range-card work its own doc comment already nominates can reuse it as a library dependency.
198// No feature gate: must compile for wasm32 (pure math over already-resolved inputs; no fs, no
199// clap -- CLI argument resolution stays in `main.rs`).
200pub mod hold_curve;
201pub mod card_service;
202// 0.33.0 decision-support Task 9: `CardRow`, the shared display-ready row type behind the
203// come-ups/range-table/wind-card/compare CLI surfaces, replacing four function-local row
204// structs that each said the same thing a different way. Pure data; no feature gate: must
205// compile for wasm32 (no fs, no clap, no pdf -- those stay in main.rs). Task 10 rewrites the
206// PDF dope card on `&[CardRow]`; Task 11 grows an adaptive-card engine here.
207pub mod card;
208// 0.33.0 decision-support Task 10: the PDF dope card, promoted out of the `ballistics`
209// binary (it was `mod pdf_dope_card;`, private to `main.rs`) so it can consume
210// `card::CardRow` directly instead of its own `DopeCardRow { range_yd: u32, .. }` -- that
211// u32-yards field couldn't express the non-integer ranges Task 11's adaptive card engine
212// produces. Feature-gated (unlike `card`): pulls in `printpdf` (PDF generation) and `dirs`
213// (font-file lookup), neither wasm32-safe nor free -- `pdf` is on by default but the
214// wasm32 build always passes `--no-default-features`.
215#[cfg(feature = "pdf")]
216pub mod pdf_dope_card;
217
218// Online mode: HTTP client for Flask API (feature-gated)
219#[cfg(feature = "online")]
220pub mod api_client;
221
222#[cfg(feature = "online")]
223pub mod credentials;
224
225// BC5D table auto-download (feature-gated)
226#[cfg(feature = "online")]
227pub mod bc_table_download;
228
229// BC correction table for offline mode
230pub mod bc_table;
231
232// 5D BC correction tables (caliber-specific, ML-derived)
233pub mod bc_table_5d;
234
235// Saved-profile data model (ProfileData & friends), moved from main.rs so the bridge's
236// profile.validate/profile.normalize/profile.import_a7p commands and the CLI share one
237// serde wire shape. No feature gate: must compile for wasm32; fs-free (profile
238// persistence and unit conversion of loaded profiles stay in main.rs).
239pub mod profile;
240
241// Import of third-party ballistic profile files (.a7p), feature-gated
242#[cfg(feature = "profile-import")]
243pub mod profile_import;
244
245// Versioned JSON command bridge for embedded (mobile/FFI) consumers
246#[cfg(feature = "bridge")]
247pub mod bridge;
248
249// Internal type alias for compatibility
250pub(crate) type InternalBallisticInputs = BallisticInputs;
251
252// BC segment data for velocity-dependent BC
253#[derive(Debug, Clone)]
254pub struct BCSegmentData {
255    pub velocity_min: f64,
256    pub velocity_max: f64,
257    pub bc_value: f64,
258}