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;
56pub mod moving_target;
57mod drag_model;
58// The C ABI. Gated behind the default-on `ffi` feature so a binary that links two versions of
59// this crate can disable it on one edge and avoid duplicate #[no_mangle] symbols.
60#[cfg(feature = "ffi")]
61pub mod ffi;
62pub mod solve_json;
63pub mod solve_v1;
64// 0.33.0 decision-support Task 2: reverse conversion from a resolved request back into a
65// solvable one (`impl From<&ResolvedSolveRequestV1> for SolveRequestV1`), the direction the
66// perturbation kernel needs to take a resolved request, change one input, and re-solve. No
67// public items of its own -- the trait impl is usable wherever solve_json's public types are.
68mod request_roundtrip;
69pub mod terminal_plot;
70// MBA-1343: multi-observation velocity/BC truing core, shared by the CLI and the WASM terminal.
71pub mod truing;
72// MBA-1346: observation-range experiment design for identifiable MV/BC truing.
73pub mod truing_plan;
74// MBA-1353: opt-in uncertainty-aware joint MV/BC truing.
75pub mod truing_uncertainty;
76// MBA-1357: Mach-keyed DSF (drop-scale-factor) truing table — a drop-only post-processing
77// correction applied to a solved TrajectoryResult. No feature gate: must compile for wasm32;
78// fs-free (profile persistence lives in main.rs).
79pub mod truing_dsf;
80// MBA-1392: back-solve the effective crosswind from an observed horizontal miss (wind-call
81// truing). Carries its own shared table/JSON/CSV formatter so the native CLI and the WASM
82// terminal render identical bytes. No feature gate: must compile for wasm32.
83pub mod truing_wind;
84// MBA-1349: robust hold corridors across named segmented-wind scenarios. No feature gate:
85// must compile for wasm32 (the CLI surface is native-only this train, but the core and its
86// shared formatter are ready for the WASM follow-up); fs-free — file reading stays in
87// main.rs, this module parses TEXT.
88pub mod wind_scenarios;
89// MBA-1361: reticle schema, parametric generators, and the hold-point-in-reticle API,
90// shared by the CLI, the WASM terminal and the FFI. No feature gate: must compile for
91// wasm32; pure math + serde, no I/O (file reading stays in main.rs/wasm.rs).
92pub mod reticle;
93// MBA-1440: import Bero's "Ventum" reticle spec into `reticle::ReticleDescription` so a
94// reticle drawn in that tool can be hold-solved by `reticle::hold_point_in_reticle`. Pure
95// transform + serde, no I/O; must compile for wasm32. Deliberately NOT wired into the
96// CLI / solve-json / WASM / FFI surfaces yet (that exposure is held for review).
97pub mod reticle_import;
98// MBA-1343 Phase B: WEZ (`monte-carlo --wez`) sweep core, shared by the CLI and the WASM terminal.
99pub mod wez;
100// MBA-1355: turret adjustment-unit conversions (SMOA/IPHY/clicks) and click-value parsing,
101// shared by the CLI and the WASM terminal. No feature gate: must compile for wasm32.
102pub mod adjustment;
103// MBA-1409: cleanroom `.drg` (Doppler drag-curve text file) parser, shared by the CLI and
104// the WASM terminal. No feature gate: must compile for wasm32; parses TEXT only (no
105// std::fs — file I/O stays in main.rs/wasm.rs).
106pub mod drag_file;
107// MBA-1372: SAAMI free-recoil momentum-balance calculator, shared by the CLI and the
108// WASM terminal. No feature gate: must compile for wasm32; pure math, no I/O.
109pub mod recoil;
110// MBA-1372: power-factor arithmetic and per-organization (USPSA/IDPA/SASS) rulebook
111// pass/fail thresholds, shared by the CLI and the WASM terminal. No feature gate: must
112// compile for wasm32; pure math + a data table, no I/O.
113pub mod power_factor;
114pub mod trajectory_observation;
115#[cfg(target_arch = "wasm32")]
116pub mod wasm;
117#[cfg(test)]
118mod wasm_tests;
119// MBA-154: Make constants public for ballistics_rust wrapping
120pub mod atmosphere;
121pub mod constants;
122pub mod drag;
123pub mod wind;
124// MBA-153: Make wind_shear public for ballistics_rust wrapping
125pub mod wind_shear;
126// MBA-154: Make derivatives public for ballistics_rust wrapping
127pub mod derivatives;
128pub mod trajectory_sampling;
129// MBA-154: Make fast_trajectory public for ballistics_rust wrapping
130pub mod fast_trajectory;
131// MBA-155: Add advanced integration methods (RK4, RK45)
132pub mod trajectory_integration;
133// MBA-149 Phase 5 Priority 2: Export enhanced spin_drift
134pub mod pitch_damping;
135pub mod spin_decay;
136pub mod spin_drift;
137pub mod spin_drift_advanced;
138// MBA-149 Phase 5 Priority 2: Export enhanced precession_nutation
139pub mod precession_nutation;
140// MBA-153: Make aerodynamic_jump public for ballistics_rust wrapping
141pub mod aerodynamic_jump;
142// MBA-149 Phase 5 Priority 2: Export enhanced angle_calculations
143pub mod angle_calculations;
144pub mod transonic_drag;
145// MBA-153: Make reynolds public for ballistics_rust wrapping
146pub mod reynolds;
147// MBA-149 Phase 5 Priority 2: Export enhanced form_factor
148pub mod form_factor;
149// MBA-153: Make monte_carlo public for ballistics_rust wrapping
150pub mod bc_estimation;
151pub mod cluster_bc;
152// MBA-1352 Task 2: Monte Carlo hit-statistics foundation -- Welford streaming moments and
153// fixed-n Wilson score intervals. The anytime-valid confidence sequence (Task 3) extends this
154// module. No feature gate: must compile for wasm32; pure std math, no randomness.
155pub mod mc_stats;
156pub mod monte_carlo;
157pub mod stability;
158pub mod stability_advanced;
159// 0.33.0 decision-support Phase 1: shared input taxonomy for perturbation kernel and
160// uncertainty propagation. No feature gate: must compile for wasm32 (pure data + serde).
161pub mod perturbation;
162// MBA-1345: explain why two fully resolved solve results differ, by symmetric counterfactual
163// swap of each input group (built on `perturbation`'s Tasks 5-8 kernel). No feature gate: must
164// compile for wasm32 (depends only on perturbation/solve_json/solve_v1, all unconditional).
165pub mod explain;
166// MBA-1347: erf/erfc/normal_cdf for hit-probability integration (mass of a bivariate
167// normal over a target). In-crate rather than a dependency: the crate ships to thirteen
168// platforms including big-endian MIPS and wasm32 and already hand-rolls its statistical
169// constants. No feature gate: must compile for wasm32; pure std float math, no I/O.
170pub mod special;
171// 0.33.0 decision-support Task 10, MBA-1347: propagate declared per-input uncertainty to
172// impact covariance via the perturbation kernel's central differences, and rank sources by
173// variance share into a measurement-priority report. Built on `perturbation` (Tasks 5-8) and
174// reuses `truing_uncertainty::Symmetric2` for the 2x2 covariance/eigenvalue arithmetic. No
175// feature gate: must compile for wasm32 (depends only on perturbation/solve_json/
176// truing_uncertainty, all unconditional).
177pub mod error_budget;
178// 0.33.0 decision-support Task 12, MBA-1350: one-variable tolerance envelopes -- how far a
179// single input may drift from its own current value before the impact leaves an explicit
180// target, by monotone bisection outward from the nominal (`perturbation::bisect_axis`, Task 7).
181// Reuses `error_budget::TargetGeometryV1` and its unavailable-axis classification verbatim. No
182// feature gate: must compile for wasm32 (depends only on perturbation/error_budget/solve_json,
183// all unconditional).
184pub mod tolerance;
185// 0.33.0 decision-support Task 3, MBA-1348: turret + reticle geometry model (click
186// detents/revolutions, zero stop, travel limits, current turret state, reticle hold
187// bounds) that a later dial/hold/hybrid engagement planner will read. Pure data +
188// validation; no feature gate: must compile for wasm32 (depends only on `adjustment`,
189// itself unconditional).
190pub mod optic;
191// 0.33.0 decision-support Task 8: `HoldCurve`, the drop-vs-range interpolation core shared
192// by `mark-to-range`, `bdc-match`, `optimal-zero` and `reticle hold --range`, promoted out of
193// the CLI binary (together with the sampled-trajectory helpers it solves through) so the
194// range-card work its own doc comment already nominates can reuse it as a library dependency.
195// No feature gate: must compile for wasm32 (pure math over already-resolved inputs; no fs, no
196// clap -- CLI argument resolution stays in `main.rs`).
197pub mod hold_curve;
198// 0.33.0 decision-support Task 9: `CardRow`, the shared display-ready row type behind the
199// come-ups/range-table/wind-card/compare CLI surfaces, replacing four function-local row
200// structs that each said the same thing a different way. Pure data; no feature gate: must
201// compile for wasm32 (no fs, no clap, no pdf -- those stay in main.rs). Task 10 rewrites the
202// PDF dope card on `&[CardRow]`; Task 11 grows an adaptive-card engine here.
203pub mod card;
204// 0.33.0 decision-support Task 10: the PDF dope card, promoted out of the `ballistics`
205// binary (it was `mod pdf_dope_card;`, private to `main.rs`) so it can consume
206// `card::CardRow` directly instead of its own `DopeCardRow { range_yd: u32, .. }` -- that
207// u32-yards field couldn't express the non-integer ranges Task 11's adaptive card engine
208// produces. Feature-gated (unlike `card`): pulls in `printpdf` (PDF generation) and `dirs`
209// (font-file lookup), neither wasm32-safe nor free -- `pdf` is on by default but the
210// wasm32 build always passes `--no-default-features`.
211#[cfg(feature = "pdf")]
212pub mod pdf_dope_card;
213
214// Online mode: HTTP client for Flask API (feature-gated)
215#[cfg(feature = "online")]
216pub mod api_client;
217
218#[cfg(feature = "online")]
219pub mod credentials;
220
221// BC5D table auto-download (feature-gated)
222#[cfg(feature = "online")]
223pub mod bc_table_download;
224
225// BC correction table for offline mode
226pub mod bc_table;
227
228// 5D BC correction tables (caliber-specific, ML-derived)
229pub mod bc_table_5d;
230
231// Import of third-party ballistic profile files (.a7p), feature-gated
232#[cfg(feature = "profile-import")]
233pub mod profile_import;
234
235// Internal type alias for compatibility
236pub(crate) type InternalBallisticInputs = BallisticInputs;
237
238// BC segment data for velocity-dependent BC
239#[derive(Debug, Clone)]
240pub struct BCSegmentData {
241 pub velocity_min: f64,
242 pub velocity_max: f64,
243 pub bc_value: f64,
244}