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_with_direction_std_dev,
24    run_monte_carlo_with_wind, run_monte_carlo_with_wind_and_direction_std_dev,
25    run_monte_carlo_with_wind_and_direction_std_dev_seeded, AtmosphericConditions,
26    BallisticInputs, BallisticsError, BcEstimate, BcFitMode, BcReferenceStandard,
27    DropsReference, MonteCarloParams, MonteCarloResults, TrajectoryPoint, TrajectoryResult,
28    TrajectorySolver,
29    WindConditions, ZeroCrossings, DEFAULT_HIT_RADIUS_M, MAX_TRAJECTORY_POINTS,
30    ZERO_RANGE_FROM_ANGLE_MAX_RANGE_M,
31    TARGET_NOT_REACHED_SENTINEL_M,
32};
33pub use atmosphere::{AtmoSegment, AtmoSock};
34pub use drag_model::DragModel;
35pub use moving_target::{
36    calculate_lead, lead_from_tof, mover_ring, LeadComponents, LeadError, LeadSolution,
37};
38pub use solve_json::{
39    decode_solve_request_v1, ResolvedSolveRequestV1, SolveErrorCodeV1, SolveErrorEnvelopeV1,
40    SolveRequestV1, SolveSuccessV1, MAX_SOLVE_JSON_SAMPLES_V1, SOLVE_JSON_SCHEMA_VERSION_V1,
41};
42pub use solve_v1::solve_v1;
43pub use trajectory_observation::{
44    TrajectoryObservation, TrajectoryObservationError, TrajectoryObservationFlag,
45    TrajectoryTermination,
46};
47pub use trajectory_sampling::MAX_TRAJECTORY_SAMPLES;
48
49// Module declarations
50pub mod cli_api;
51pub mod moving_target;
52mod drag_model;
53// The C ABI. Gated behind the default-on `ffi` feature so a binary that links two versions of
54// this crate can disable it on one edge and avoid duplicate #[no_mangle] symbols.
55#[cfg(feature = "ffi")]
56pub mod ffi;
57pub mod solve_json;
58pub mod solve_v1;
59pub mod terminal_plot;
60// MBA-1343: multi-observation velocity/BC truing core, shared by the CLI and the WASM terminal.
61pub mod truing;
62// MBA-1346: observation-range experiment design for identifiable MV/BC truing.
63pub mod truing_plan;
64// MBA-1353: opt-in uncertainty-aware joint MV/BC truing.
65pub mod truing_uncertainty;
66// MBA-1357: Mach-keyed DSF (drop-scale-factor) truing table — a drop-only post-processing
67// correction applied to a solved TrajectoryResult. No feature gate: must compile for wasm32;
68// fs-free (profile persistence lives in main.rs).
69pub mod truing_dsf;
70// MBA-1392: back-solve the effective crosswind from an observed horizontal miss (wind-call
71// truing). Carries its own shared table/JSON/CSV formatter so the native CLI and the WASM
72// terminal render identical bytes. No feature gate: must compile for wasm32.
73pub mod truing_wind;
74// MBA-1349: robust hold corridors across named segmented-wind scenarios. No feature gate:
75// must compile for wasm32 (the CLI surface is native-only this train, but the core and its
76// shared formatter are ready for the WASM follow-up); fs-free — file reading stays in
77// main.rs, this module parses TEXT.
78pub mod wind_scenarios;
79// MBA-1361: reticle schema, parametric generators, and the hold-point-in-reticle API,
80// shared by the CLI, the WASM terminal and the FFI. No feature gate: must compile for
81// wasm32; pure math + serde, no I/O (file reading stays in main.rs/wasm.rs).
82pub mod reticle;
83// MBA-1440: import Bero's "Ventum" reticle spec into `reticle::ReticleDescription` so a
84// reticle drawn in that tool can be hold-solved by `reticle::hold_point_in_reticle`. Pure
85// transform + serde, no I/O; must compile for wasm32. Deliberately NOT wired into the
86// CLI / solve-json / WASM / FFI surfaces yet (that exposure is held for review).
87pub mod reticle_import;
88// MBA-1343 Phase B: WEZ (`monte-carlo --wez`) sweep core, shared by the CLI and the WASM terminal.
89pub mod wez;
90// MBA-1355: turret adjustment-unit conversions (SMOA/IPHY/clicks) and click-value parsing,
91// shared by the CLI and the WASM terminal. No feature gate: must compile for wasm32.
92pub mod adjustment;
93// MBA-1409: cleanroom `.drg` (Doppler drag-curve text file) parser, shared by the CLI and
94// the WASM terminal. No feature gate: must compile for wasm32; parses TEXT only (no
95// std::fs — file I/O stays in main.rs/wasm.rs).
96pub mod drag_file;
97// MBA-1372: SAAMI free-recoil momentum-balance calculator, shared by the CLI and the
98// WASM terminal. No feature gate: must compile for wasm32; pure math, no I/O.
99pub mod recoil;
100// MBA-1372: power-factor arithmetic and per-organization (USPSA/IDPA/SASS) rulebook
101// pass/fail thresholds, shared by the CLI and the WASM terminal. No feature gate: must
102// compile for wasm32; pure math + a data table, no I/O.
103pub mod power_factor;
104pub mod trajectory_observation;
105#[cfg(target_arch = "wasm32")]
106pub mod wasm;
107#[cfg(test)]
108mod wasm_tests;
109// MBA-154: Make constants public for ballistics_rust wrapping
110pub mod atmosphere;
111pub mod constants;
112pub mod drag;
113pub mod wind;
114// MBA-153: Make wind_shear public for ballistics_rust wrapping
115pub mod wind_shear;
116// MBA-154: Make derivatives public for ballistics_rust wrapping
117pub mod derivatives;
118pub mod trajectory_sampling;
119// MBA-154: Make fast_trajectory public for ballistics_rust wrapping
120pub mod fast_trajectory;
121// MBA-155: Add advanced integration methods (RK4, RK45)
122pub mod trajectory_integration;
123// MBA-149 Phase 5 Priority 2: Export enhanced spin_drift
124pub mod pitch_damping;
125pub mod spin_decay;
126pub mod spin_drift;
127pub mod spin_drift_advanced;
128// MBA-149 Phase 5 Priority 2: Export enhanced precession_nutation
129pub mod precession_nutation;
130// MBA-153: Make aerodynamic_jump public for ballistics_rust wrapping
131pub mod aerodynamic_jump;
132// MBA-149 Phase 5 Priority 2: Export enhanced angle_calculations
133pub mod angle_calculations;
134pub mod transonic_drag;
135// MBA-153: Make reynolds public for ballistics_rust wrapping
136pub mod reynolds;
137// MBA-149 Phase 5 Priority 2: Export enhanced form_factor
138pub mod form_factor;
139// MBA-153: Make monte_carlo public for ballistics_rust wrapping
140pub mod bc_estimation;
141pub mod cluster_bc;
142pub mod monte_carlo;
143pub mod stability;
144pub mod stability_advanced;
145
146// Online mode: HTTP client for Flask API (feature-gated)
147#[cfg(feature = "online")]
148pub mod api_client;
149
150#[cfg(feature = "online")]
151pub mod credentials;
152
153// BC5D table auto-download (feature-gated)
154#[cfg(feature = "online")]
155pub mod bc_table_download;
156
157// BC correction table for offline mode
158pub mod bc_table;
159
160// 5D BC correction tables (caliber-specific, ML-derived)
161pub mod bc_table_5d;
162
163// Import of third-party ballistic profile files (.a7p), feature-gated
164#[cfg(feature = "profile-import")]
165pub mod profile_import;
166
167// Internal type alias for compatibility
168pub(crate) type InternalBallisticInputs = BallisticInputs;
169
170// BC segment data for velocity-dependent BC
171#[derive(Debug, Clone)]
172pub struct BCSegmentData {
173    pub velocity_min: f64,
174    pub velocity_max: f64,
175    pub bc_value: f64,
176}