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    MonteCarloParams, MonteCarloResults, TrajectoryPoint, TrajectoryResult, TrajectorySolver,
28    WindConditions, ZeroCrossings, DEFAULT_HIT_RADIUS_M, MAX_TRAJECTORY_POINTS,
29    ZERO_RANGE_FROM_ANGLE_MAX_RANGE_M,
30    TARGET_NOT_REACHED_SENTINEL_M,
31};
32pub use atmosphere::{AtmoSegment, AtmoSock};
33pub use drag_model::DragModel;
34pub use moving_target::{
35    calculate_lead, lead_from_tof, mover_ring, LeadComponents, LeadError, LeadSolution,
36};
37pub use solve_json::{
38    decode_solve_request_v1, ResolvedSolveRequestV1, SolveErrorCodeV1, SolveErrorEnvelopeV1,
39    SolveRequestV1, SolveSuccessV1, MAX_SOLVE_JSON_SAMPLES_V1, SOLVE_JSON_SCHEMA_VERSION_V1,
40};
41pub use solve_v1::solve_v1;
42pub use trajectory_observation::{
43    TrajectoryObservation, TrajectoryObservationError, TrajectoryObservationFlag,
44    TrajectoryTermination,
45};
46pub use trajectory_sampling::MAX_TRAJECTORY_SAMPLES;
47
48// Module declarations
49pub mod cli_api;
50pub mod moving_target;
51mod drag_model;
52// The C ABI. Gated behind the default-on `ffi` feature so a binary that links two versions of
53// this crate can disable it on one edge and avoid duplicate #[no_mangle] symbols.
54#[cfg(feature = "ffi")]
55pub mod ffi;
56pub mod solve_json;
57pub mod solve_v1;
58pub mod terminal_plot;
59// MBA-1343: multi-observation velocity/BC truing core, shared by the CLI and the WASM terminal.
60pub mod truing;
61// MBA-1346: observation-range experiment design for identifiable MV/BC truing.
62pub mod truing_plan;
63// MBA-1353: opt-in uncertainty-aware joint MV/BC truing.
64pub mod truing_uncertainty;
65// MBA-1357: Mach-keyed DSF (drop-scale-factor) truing table — a drop-only post-processing
66// correction applied to a solved TrajectoryResult. No feature gate: must compile for wasm32;
67// fs-free (profile persistence lives in main.rs).
68pub mod truing_dsf;
69// MBA-1343 Phase B: WEZ (`monte-carlo --wez`) sweep core, shared by the CLI and the WASM terminal.
70pub mod wez;
71// MBA-1355: turret adjustment-unit conversions (SMOA/IPHY/clicks) and click-value parsing,
72// shared by the CLI and the WASM terminal. No feature gate: must compile for wasm32.
73pub mod adjustment;
74// MBA-1409: cleanroom `.drg` (Doppler drag-curve text file) parser, shared by the CLI and
75// the WASM terminal. No feature gate: must compile for wasm32; parses TEXT only (no
76// std::fs — file I/O stays in main.rs/wasm.rs).
77pub mod drag_file;
78// MBA-1372: SAAMI free-recoil momentum-balance calculator, shared by the CLI and the
79// WASM terminal. No feature gate: must compile for wasm32; pure math, no I/O.
80pub mod recoil;
81// MBA-1372: power-factor arithmetic and per-organization (USPSA/IDPA/SASS) rulebook
82// pass/fail thresholds, shared by the CLI and the WASM terminal. No feature gate: must
83// compile for wasm32; pure math + a data table, no I/O.
84pub mod power_factor;
85pub mod trajectory_observation;
86#[cfg(target_arch = "wasm32")]
87pub mod wasm;
88#[cfg(test)]
89mod wasm_tests;
90// MBA-154: Make constants public for ballistics_rust wrapping
91pub mod atmosphere;
92pub mod constants;
93pub mod drag;
94pub mod wind;
95// MBA-153: Make wind_shear public for ballistics_rust wrapping
96pub mod wind_shear;
97// MBA-154: Make derivatives public for ballistics_rust wrapping
98pub mod derivatives;
99pub mod trajectory_sampling;
100// MBA-154: Make fast_trajectory public for ballistics_rust wrapping
101pub mod fast_trajectory;
102// MBA-155: Add advanced integration methods (RK4, RK45)
103pub mod trajectory_integration;
104// MBA-149 Phase 5 Priority 2: Export enhanced spin_drift
105pub mod pitch_damping;
106pub mod spin_decay;
107pub mod spin_drift;
108pub mod spin_drift_advanced;
109// MBA-149 Phase 5 Priority 2: Export enhanced precession_nutation
110pub mod precession_nutation;
111// MBA-153: Make aerodynamic_jump public for ballistics_rust wrapping
112pub mod aerodynamic_jump;
113// MBA-149 Phase 5 Priority 2: Export enhanced angle_calculations
114pub mod angle_calculations;
115pub mod transonic_drag;
116// MBA-153: Make reynolds public for ballistics_rust wrapping
117pub mod reynolds;
118// MBA-149 Phase 5 Priority 2: Export enhanced form_factor
119pub mod form_factor;
120// MBA-153: Make monte_carlo public for ballistics_rust wrapping
121pub mod bc_estimation;
122pub mod cluster_bc;
123pub mod monte_carlo;
124pub mod stability;
125pub mod stability_advanced;
126
127// Online mode: HTTP client for Flask API (feature-gated)
128#[cfg(feature = "online")]
129pub mod api_client;
130
131// BC5D table auto-download (feature-gated)
132#[cfg(feature = "online")]
133pub mod bc_table_download;
134
135// BC correction table for offline mode
136pub mod bc_table;
137
138// 5D BC correction tables (caliber-specific, ML-derived)
139pub mod bc_table_5d;
140
141// Import of third-party ballistic profile files (.a7p), feature-gated
142#[cfg(feature = "profile-import")]
143pub mod profile_import;
144
145// Internal type alias for compatibility
146pub(crate) type InternalBallisticInputs = BallisticInputs;
147
148// BC segment data for velocity-dependent BC
149#[derive(Debug, Clone)]
150pub struct BCSegmentData {
151    pub velocity_min: f64,
152    pub velocity_max: f64,
153    pub bc_value: f64,
154}