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