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