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-1343 Phase B: WEZ (`monte-carlo --wez`) sweep core, shared by the CLI and the WASM terminal.
84pub mod wez;
85// MBA-1355: turret adjustment-unit conversions (SMOA/IPHY/clicks) and click-value parsing,
86// shared by the CLI and the WASM terminal. No feature gate: must compile for wasm32.
87pub mod adjustment;
88// MBA-1409: cleanroom `.drg` (Doppler drag-curve text file) parser, shared by the CLI and
89// the WASM terminal. No feature gate: must compile for wasm32; parses TEXT only (no
90// std::fs — file I/O stays in main.rs/wasm.rs).
91pub mod drag_file;
92// MBA-1372: SAAMI free-recoil momentum-balance calculator, shared by the CLI and the
93// WASM terminal. No feature gate: must compile for wasm32; pure math, no I/O.
94pub mod recoil;
95// MBA-1372: power-factor arithmetic and per-organization (USPSA/IDPA/SASS) rulebook
96// pass/fail thresholds, shared by the CLI and the WASM terminal. No feature gate: must
97// compile for wasm32; pure math + a data table, no I/O.
98pub mod power_factor;
99pub mod trajectory_observation;
100#[cfg(target_arch = "wasm32")]
101pub mod wasm;
102#[cfg(test)]
103mod wasm_tests;
104// MBA-154: Make constants public for ballistics_rust wrapping
105pub mod atmosphere;
106pub mod constants;
107pub mod drag;
108pub mod wind;
109// MBA-153: Make wind_shear public for ballistics_rust wrapping
110pub mod wind_shear;
111// MBA-154: Make derivatives public for ballistics_rust wrapping
112pub mod derivatives;
113pub mod trajectory_sampling;
114// MBA-154: Make fast_trajectory public for ballistics_rust wrapping
115pub mod fast_trajectory;
116// MBA-155: Add advanced integration methods (RK4, RK45)
117pub mod trajectory_integration;
118// MBA-149 Phase 5 Priority 2: Export enhanced spin_drift
119pub mod pitch_damping;
120pub mod spin_decay;
121pub mod spin_drift;
122pub mod spin_drift_advanced;
123// MBA-149 Phase 5 Priority 2: Export enhanced precession_nutation
124pub mod precession_nutation;
125// MBA-153: Make aerodynamic_jump public for ballistics_rust wrapping
126pub mod aerodynamic_jump;
127// MBA-149 Phase 5 Priority 2: Export enhanced angle_calculations
128pub mod angle_calculations;
129pub mod transonic_drag;
130// MBA-153: Make reynolds public for ballistics_rust wrapping
131pub mod reynolds;
132// MBA-149 Phase 5 Priority 2: Export enhanced form_factor
133pub mod form_factor;
134// MBA-153: Make monte_carlo public for ballistics_rust wrapping
135pub mod bc_estimation;
136pub mod cluster_bc;
137pub mod monte_carlo;
138pub mod stability;
139pub mod stability_advanced;
140
141// Online mode: HTTP client for Flask API (feature-gated)
142#[cfg(feature = "online")]
143pub mod api_client;
144
145// BC5D table auto-download (feature-gated)
146#[cfg(feature = "online")]
147pub mod bc_table_download;
148
149// BC correction table for offline mode
150pub mod bc_table;
151
152// 5D BC correction tables (caliber-specific, ML-derived)
153pub mod bc_table_5d;
154
155// Import of third-party ballistic profile files (.a7p), feature-gated
156#[cfg(feature = "profile-import")]
157pub mod profile_import;
158
159// Internal type alias for compatibility
160pub(crate) type InternalBallisticInputs = BallisticInputs;
161
162// BC segment data for velocity-dependent BC
163#[derive(Debug, Clone)]
164pub struct BCSegmentData {
165    pub velocity_min: f64,
166    pub velocity_max: f64,
167    pub bc_value: f64,
168}