ballistics-engine 0.13.4 → 0.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -250
- package/ballistics_engine.d.ts +113 -103
- package/ballistics_engine.js +9 -610
- package/ballistics_engine_bg.js +552 -0
- package/ballistics_engine_bg.wasm +0 -0
- package/package.json +12 -5
package/README.md
CHANGED
|
@@ -1,294 +1,131 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ballistics-engine (WASM)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
WebAssembly build of [`ballistics-engine`](https://github.com/ajokela/ballistics-engine), a
|
|
4
|
+
high-performance ballistics trajectory engine (RK4 integration, wind/Coriolis/spin-drift/Magnus
|
|
5
|
+
effects, custom drag tables, Monte Carlo, and more). This package exposes the same CLI-style
|
|
6
|
+
command surface as the native Rust binary, plus a small object-oriented `Calculator` class, to
|
|
7
|
+
JavaScript/TypeScript.
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
Built with `wasm-pack` and `--no-default-features` — the native crate's default `pdf`/`online`
|
|
10
|
+
features pull in dependencies that don't compile for `wasm32-unknown-unknown`, so the PDF dope-card
|
|
11
|
+
export and the online BC-estimation API are not available from WASM.
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
> This package is built from `pkg/` (the `wasm-pack --target bundler` output) via
|
|
14
|
+
> `scripts/build-npm.sh` in the source repo. The same script also produces a `pkg-web/` build
|
|
15
|
+
> (`--target web`) for use without a bundler — see "Browser without a bundler" below.
|
|
8
16
|
|
|
9
|
-
|
|
10
|
-
npm install ballistics-engine
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Quick Start
|
|
14
|
-
|
|
15
|
-
### ES Modules (Browser/Bundler)
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
import init, { Calculator } from 'ballistics-engine';
|
|
19
|
-
|
|
20
|
-
// Initialize the WASM module first
|
|
21
|
-
await init();
|
|
22
|
-
|
|
23
|
-
// Create a calculator with default values (.308 Win, 168gr at 2700 fps)
|
|
24
|
-
const calc = new Calculator();
|
|
25
|
-
|
|
26
|
-
// Configure your load
|
|
27
|
-
calc
|
|
28
|
-
.setVelocity(2700) // fps
|
|
29
|
-
.setBC(0.475) // G1 ballistic coefficient
|
|
30
|
-
.setMass(168) // grains
|
|
31
|
-
.setDiameter(0.308) // inches
|
|
32
|
-
.setZeroRange(200) // zero at 200 yards
|
|
33
|
-
.setWind(10, 90); // 10 mph from the right
|
|
34
|
-
|
|
35
|
-
// Calculate trajectory at a specific range
|
|
36
|
-
const result = calc.calculateTrajectory(500);
|
|
37
|
-
console.log(result);
|
|
38
|
-
// { range_yards: 500, drop_inches: -48.2, windage_inches: 15.3, velocity_fps: 2145, energy_ftlb: 1715, time_sec: 0.62 }
|
|
39
|
-
|
|
40
|
-
// Get full trajectory table
|
|
41
|
-
const trajectory = calc.getFullTrajectory();
|
|
42
|
-
console.log(trajectory);
|
|
43
|
-
// Array of trajectory points from 0 to max range
|
|
44
|
-
|
|
45
|
-
// Clean up when done
|
|
46
|
-
calc.free();
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### With TypeScript
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
import init, { Calculator } from 'ballistics-engine';
|
|
53
|
-
|
|
54
|
-
async function main() {
|
|
55
|
-
await init();
|
|
56
|
-
|
|
57
|
-
const calc = new Calculator()
|
|
58
|
-
.setVelocity(3000)
|
|
59
|
-
.setBC(0.620)
|
|
60
|
-
.setMass(140)
|
|
61
|
-
.setDiameter(0.264)
|
|
62
|
-
.setDragModel('g7')
|
|
63
|
-
.setZeroRange(100);
|
|
64
|
-
|
|
65
|
-
const result = calc.calculateTrajectory(1000);
|
|
66
|
-
console.log(`Drop at 1000 yards: ${result.drop_inches.toFixed(1)} inches`);
|
|
67
|
-
|
|
68
|
-
calc.free();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
main();
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## API Reference
|
|
75
|
-
|
|
76
|
-
### Calculator Class
|
|
17
|
+
## Install
|
|
77
18
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
#### Constructor
|
|
81
|
-
|
|
82
|
-
```javascript
|
|
83
|
-
const calc = new Calculator();
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
Creates a calculator with sensible defaults:
|
|
87
|
-
- .308 Winchester 168gr at 2700 fps
|
|
88
|
-
- G1 drag model
|
|
89
|
-
- Standard atmosphere (59°F, 29.92 inHg)
|
|
90
|
-
|
|
91
|
-
#### Configuration Methods
|
|
92
|
-
|
|
93
|
-
All methods return `this` for chaining.
|
|
94
|
-
|
|
95
|
-
| Method | Parameters | Description |
|
|
96
|
-
|--------|------------|-------------|
|
|
97
|
-
| `setVelocity(fps)` | `number` | Muzzle velocity in feet per second |
|
|
98
|
-
| `setBC(bc)` | `number` | Ballistic coefficient (G1 or G7) |
|
|
99
|
-
| `setMass(grains)` | `number` | Bullet weight in grains |
|
|
100
|
-
| `setDiameter(inches)` | `number` | Bullet diameter in inches |
|
|
101
|
-
| `setDragModel(model)` | `'g1'` \| `'g7'` | Drag model to use |
|
|
102
|
-
| `setZeroRange(yards)` | `number` | Zero distance in yards |
|
|
103
|
-
| `setSightHeight(inches)` | `number` | Scope height above bore |
|
|
104
|
-
| `setMaxRange(yards)` | `number` | Maximum calculation range |
|
|
105
|
-
| `setWind(mph, degrees)` | `number, number` | Wind speed and direction (0°=headwind, 90°=from right) |
|
|
106
|
-
| `setTemperature(fahrenheit)` | `number` | Ambient temperature |
|
|
107
|
-
| `setPressure(inHg)` | `number` | Barometric pressure |
|
|
108
|
-
| `setHumidity(percent)` | `number` | Relative humidity (0-100) |
|
|
109
|
-
| `setAltitude(feet)` | `number` | Shooting altitude |
|
|
110
|
-
| `enableSpinDrift(enabled, twistRate?)` | `boolean, number?` | Enable spin drift (twist rate in inches) |
|
|
111
|
-
| `enableCoriolis(enabled, latitude?)` | `boolean, number?` | Enable Coriolis effect |
|
|
112
|
-
|
|
113
|
-
#### Calculation Methods
|
|
114
|
-
|
|
115
|
-
```javascript
|
|
116
|
-
// Calculate at specific range
|
|
117
|
-
const point = calc.calculateTrajectory(500);
|
|
118
|
-
|
|
119
|
-
// Get full trajectory table
|
|
120
|
-
const trajectory = calc.getFullTrajectory();
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
#### Result Object
|
|
124
|
-
|
|
125
|
-
```typescript
|
|
126
|
-
interface TrajectoryPoint {
|
|
127
|
-
range_yards: number; // Distance from muzzle
|
|
128
|
-
drop_inches: number; // Bullet drop (negative = below line of sight)
|
|
129
|
-
windage_inches: number; // Wind deflection (positive = right)
|
|
130
|
-
velocity_fps: number; // Remaining velocity
|
|
131
|
-
energy_ftlb: number; // Remaining energy
|
|
132
|
-
time_sec: number; // Time of flight
|
|
133
|
-
}
|
|
19
|
+
```bash
|
|
20
|
+
npm install @SCOPE/ballistics-engine
|
|
134
21
|
```
|
|
135
22
|
|
|
136
|
-
|
|
23
|
+
`@SCOPE` is a placeholder — see the source repo's `README.md` ("WASM / npm Package" section) for
|
|
24
|
+
the real published name once one exists.
|
|
137
25
|
|
|
138
|
-
|
|
26
|
+
## Quick start (bundler: webpack, Vite, Rollup, Parcel)
|
|
139
27
|
|
|
140
|
-
|
|
141
|
-
|
|
28
|
+
This package's `main` entry imports its `.wasm` file as a native ES module, which is how
|
|
29
|
+
`wasm-pack --target bundler` output is meant to be consumed. It works out of the box with Vite and
|
|
30
|
+
Rollup (`@rollup/plugin-wasm`), and with webpack once `experiments.asyncWebAssembly` (or
|
|
31
|
+
`experiments.syncWebAssembly`) is enabled — check your bundler's WASM docs if the import fails.
|
|
142
32
|
|
|
143
|
-
|
|
33
|
+
```js
|
|
34
|
+
import { WasmBallistics } from '@SCOPE/ballistics-engine';
|
|
144
35
|
|
|
145
|
-
const
|
|
36
|
+
const calc = new WasmBallistics();
|
|
146
37
|
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
38
|
+
// The command surface mirrors the native CLI (see CLI_USAGE.md in the source repo for the full
|
|
39
|
+
// flag reference): .308 Winchester, 168gr @ 2700 fps, zeroed at 200 yd, table out to 500 yd.
|
|
40
|
+
const table = calc.runCommand(
|
|
41
|
+
'trajectory -v 2700 -b 0.475 -m 168 -d 0.308 --max-range 500 --auto-zero 200',
|
|
150
42
|
);
|
|
151
|
-
|
|
152
|
-
console.log(JSON.parse(output));
|
|
153
|
-
|
|
154
|
-
ballistics.free();
|
|
43
|
+
console.log(table);
|
|
155
44
|
```
|
|
156
45
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
### Long-Range Trajectory
|
|
160
|
-
|
|
161
|
-
```javascript
|
|
162
|
-
const calc = new Calculator()
|
|
163
|
-
.setVelocity(2850)
|
|
164
|
-
.setBC(0.690) // G7 BC
|
|
165
|
-
.setMass(230)
|
|
166
|
-
.setDiameter(0.338)
|
|
167
|
-
.setDragModel('g7')
|
|
168
|
-
.setZeroRange(100)
|
|
169
|
-
.setMaxRange(1500)
|
|
170
|
-
.setWind(10, 270) // 10 mph from left
|
|
171
|
-
.setAltitude(5000) // High altitude
|
|
172
|
-
.setTemperature(75);
|
|
46
|
+
### Custom drag tables (`loadDragTable`)
|
|
173
47
|
|
|
174
|
-
|
|
48
|
+
Supply a measured or manufacturer-published Mach:Cd drag curve (Hornady CDM data, a Lapua/Doppler
|
|
49
|
+
deck, or your own) instead of a G1/G7 model + BC. Once loaded it's applied automatically to every
|
|
50
|
+
`trajectory`, `zero`, `lead`, and `monte-carlo` run — no extra flag needed.
|
|
175
51
|
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
### Environmental Effects
|
|
182
|
-
|
|
183
|
-
```javascript
|
|
184
|
-
// Hot day, high altitude
|
|
185
|
-
const calc = new Calculator()
|
|
186
|
-
.setVelocity(2700)
|
|
187
|
-
.setBC(0.475)
|
|
188
|
-
.setMass(168)
|
|
189
|
-
.setDiameter(0.308)
|
|
190
|
-
.setTemperature(95) // Hot day
|
|
191
|
-
.setAltitude(8000) // Mountain shooting
|
|
192
|
-
.setPressure(24.5) // Lower pressure at altitude
|
|
193
|
-
.setHumidity(20); // Dry air
|
|
194
|
-
|
|
195
|
-
// Velocity will stay higher due to thinner air
|
|
196
|
-
```
|
|
52
|
+
```js
|
|
53
|
+
const csv = 'mach,cd\n0.5,0.220\n0.8,0.230\n1.0,0.520\n1.2,0.480\n1.5,0.400\n2.0,0.330\n2.5,0.300\n';
|
|
54
|
+
calc.loadDragTable(new TextEncoder().encode(csv));
|
|
55
|
+
calc.hasDragTable(); // true
|
|
197
56
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
```javascript
|
|
201
|
-
const calc = new Calculator()
|
|
202
|
-
.setVelocity(2700)
|
|
203
|
-
.setBC(0.475)
|
|
204
|
-
.setMass(168)
|
|
205
|
-
.setDiameter(0.308)
|
|
206
|
-
.enableSpinDrift(true, 10) // 1:10" twist, right-hand
|
|
207
|
-
.setZeroRange(100)
|
|
208
|
-
.setMaxRange(1000);
|
|
209
|
-
|
|
210
|
-
// Spin drift adds to windage at long range
|
|
211
|
-
const point = calc.calculateTrajectory(1000);
|
|
212
|
-
console.log(`Spin drift at 1000: ${point.windage_inches.toFixed(1)}"`);
|
|
57
|
+
calc.runCommand('trajectory -v 2700 -b 0.475 -m 168 -d 0.308 --max-range 500');
|
|
213
58
|
```
|
|
214
59
|
|
|
215
|
-
|
|
60
|
+
`loadDragTable` takes raw bytes because WASM has no filesystem access — fetch the CSV yourself
|
|
61
|
+
(`fetch()` in the browser, `fs.readFileSync` in Node) and pass the bytes in. The CSV format is
|
|
62
|
+
documented in the source repo's `CLI_USAGE.md` ("Custom Drag Tables"); a matching
|
|
63
|
+
`loadBc5dTable(bytes)` / `hasBc5dTable()` pair exists for BC5D correction tables.
|
|
216
64
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
```javascript
|
|
220
|
-
import init, { Calculator } from 'ballistics-engine';
|
|
221
|
-
|
|
222
|
-
async function setupBallistics() {
|
|
223
|
-
await init();
|
|
224
|
-
// Ready to use
|
|
225
|
-
}
|
|
226
|
-
```
|
|
65
|
+
## Browser without a bundler
|
|
227
66
|
|
|
228
|
-
|
|
67
|
+
For a plain `<script type="module">` page (no build step), use the `pkg-web/` build instead —
|
|
68
|
+
produced by the same `scripts/build-npm.sh`, and the same build already deployed at
|
|
69
|
+
[ballistics.sh](https://ballistics.sh). It ships an explicit async `init()` you call once before
|
|
70
|
+
constructing `WasmBallistics`:
|
|
229
71
|
|
|
230
72
|
```html
|
|
231
73
|
<script type="module">
|
|
232
|
-
import init, {
|
|
74
|
+
import init, { WasmBallistics } from './ballistics_engine.js';
|
|
233
75
|
|
|
234
|
-
init().
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
});
|
|
76
|
+
await init(); // fetches and instantiates ballistics_engine_bg.wasm relative to this file
|
|
77
|
+
const calc = new WasmBallistics();
|
|
78
|
+
console.log(calc.runCommand('trajectory -v 2700 -b 0.475 -m 168 -d 0.308 --max-range 500'));
|
|
238
79
|
</script>
|
|
239
80
|
```
|
|
240
81
|
|
|
241
|
-
|
|
82
|
+
Serve `ballistics_engine.js` and `ballistics_engine_bg.wasm` from the same directory, and make sure
|
|
83
|
+
your host serves `.wasm` with `Content-Type: application/wasm` (all major static hosts and CDNs do
|
|
84
|
+
this by default).
|
|
242
85
|
|
|
243
|
-
|
|
86
|
+
This `pkg-web/` build is not published to npm as part of this package in the current release —
|
|
87
|
+
it's built locally alongside `pkg/` for direct use or self-hosting. If you need it from npm, either
|
|
88
|
+
vendor the files from `pkg-web/` yourself or publish it as a second package.
|
|
244
89
|
|
|
245
|
-
|
|
246
|
-
- Full trajectory table (1500 points): ~5ms
|
|
247
|
-
- Zero calculation: ~2ms
|
|
90
|
+
### Node.js without a bundler
|
|
248
91
|
|
|
249
|
-
|
|
92
|
+
Plain Node `import`/`require` cannot load this package's bundler-target `.wasm` import directly.
|
|
93
|
+
Use the `pkg-web/` build instead, passing the file bytes explicitly (Node's `fetch()` does not
|
|
94
|
+
support `file://` URLs):
|
|
250
95
|
|
|
251
|
-
|
|
96
|
+
```js
|
|
97
|
+
import { readFileSync } from 'node:fs';
|
|
98
|
+
import init, { WasmBallistics } from './pkg-web/ballistics_engine.js';
|
|
252
99
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
## Memory Management
|
|
258
|
-
|
|
259
|
-
The Calculator and WasmBallistics classes allocate memory in the WASM heap. Call `.free()` when done to prevent memory leaks:
|
|
100
|
+
const wasmBytes = readFileSync(new URL('./pkg-web/ballistics_engine_bg.wasm', import.meta.url));
|
|
101
|
+
await init({ module_or_path: wasmBytes });
|
|
260
102
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
try {
|
|
264
|
-
// Use calculator
|
|
265
|
-
const result = calc.calculateTrajectory(500);
|
|
266
|
-
} finally {
|
|
267
|
-
calc.free();
|
|
268
|
-
}
|
|
103
|
+
const calc = new WasmBallistics();
|
|
104
|
+
console.log(calc.runCommand('trajectory -v 2700 -b 0.475 -m 168 -d 0.308 --max-range 500'));
|
|
269
105
|
```
|
|
270
106
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
```typescript
|
|
274
|
-
{
|
|
275
|
-
using calc = new Calculator();
|
|
276
|
-
const result = calc.calculateTrajectory(500);
|
|
277
|
-
} // Automatically freed
|
|
278
|
-
```
|
|
107
|
+
If you need a CommonJS (`require()`) Node build, generate one yourself:
|
|
108
|
+
`wasm-pack build --target nodejs --no-default-features`.
|
|
279
109
|
|
|
280
|
-
##
|
|
110
|
+
## Caveats
|
|
281
111
|
|
|
282
|
-
- **
|
|
283
|
-
|
|
284
|
-
- **
|
|
112
|
+
- **Size**: the `.wasm` binary is roughly 430 KB (about 175 KB gzipped). It is not code-split or
|
|
113
|
+
lazily loaded — the whole engine loads up front.
|
|
114
|
+
- **Single-threaded**: no SIMD/threads assumptions; no `SharedArrayBuffer` or
|
|
115
|
+
cross-origin-isolation (COOP/COEP) headers required.
|
|
116
|
+
- **No filesystem/network**: table loaders (`loadDragTable`, `loadBc5dTable`) and any file-based
|
|
117
|
+
CLI flags (e.g. native `--drag-table <FILE>`) need the host to fetch bytes and hand them in; see
|
|
118
|
+
`loadDragTable` above.
|
|
119
|
+
- **`pdf`/`online` features are unavailable**: this build excludes them (see above), so
|
|
120
|
+
PDF dope-card export and the online BC-estimation API are not part of the WASM surface.
|
|
121
|
+
- Full API surface (including the `Calculator` builder class) is documented in the bundled
|
|
122
|
+
`.d.ts`; the full CLI flag reference `runCommand` accepts is documented in the source repo's
|
|
123
|
+
`CLI_USAGE.md`.
|
|
285
124
|
|
|
286
125
|
## License
|
|
287
126
|
|
|
288
|
-
MIT OR Apache-2.0
|
|
127
|
+
MIT OR Apache-2.0 — see `LICENSE` and `LICENSE-APACHE` in this package.
|
|
289
128
|
|
|
290
|
-
##
|
|
129
|
+
## Source
|
|
291
130
|
|
|
292
|
-
|
|
293
|
-
- [GitHub Repository](https://github.com/ajokela/ballistics-engine)
|
|
294
|
-
- [Live Demo](https://ballistics.sh/)
|
|
131
|
+
https://github.com/ajokela/ballistics-engine
|
package/ballistics_engine.d.ts
CHANGED
|
@@ -1,113 +1,123 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Object-oriented calculator for programmatic use
|
|
5
6
|
* Provides a type-safe, fluent API alternative to the CLI interface
|
|
6
7
|
*/
|
|
7
8
|
export class Calculator {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
9
|
+
free(): void;
|
|
10
|
+
[Symbol.dispose](): void;
|
|
11
|
+
/**
|
|
12
|
+
* Add a downrange wind segment: `speed_mph` from `direction_deg`
|
|
13
|
+
* (wind-FROM: 0 = headwind, 90 = from the right) out to `until_yards`.
|
|
14
|
+
* Each segment applies from the previous boundary to `until_yards`; wind is
|
|
15
|
+
* zero beyond the last segment. When any segment is added it overrides the
|
|
16
|
+
* scalar `setWind` value. Repeatable.
|
|
17
|
+
*/
|
|
18
|
+
addWindSegment(speed_mph: number, direction_deg: number, until_yards: number): Calculator;
|
|
19
|
+
/**
|
|
20
|
+
* Calculate trajectory and return result as JavaScript object
|
|
21
|
+
* Returns: { range_yards, drop_inches, windage_inches, velocity_fps, energy_ftlb, time_sec }
|
|
22
|
+
*/
|
|
23
|
+
calculateTrajectory(range_yards: number): any;
|
|
24
|
+
/**
|
|
25
|
+
* Remove all downrange wind segments (reverts to the scalar `setWind`).
|
|
26
|
+
*/
|
|
27
|
+
clearWindSegments(): Calculator;
|
|
28
|
+
enableCoriolis(enabled: boolean, latitude?: number | null): Calculator;
|
|
29
|
+
enableSpinDrift(enabled: boolean, twist_rate?: number | null): Calculator;
|
|
30
|
+
/**
|
|
31
|
+
* Get full trajectory table as array of points
|
|
32
|
+
* Returns array of: [{ range_yards, drop_inches, windage_inches, velocity_fps, energy_ftlb, time_sec }, ...]
|
|
33
|
+
*/
|
|
34
|
+
getFullTrajectory(): any;
|
|
35
|
+
/**
|
|
36
|
+
* Create a new calculator with default values
|
|
37
|
+
* Defaults: .308 Winchester 168gr at 2700 fps, standard atmosphere
|
|
38
|
+
*/
|
|
39
|
+
constructor();
|
|
40
|
+
setAltitude(altitude_ft: number): Calculator;
|
|
41
|
+
setBC(bc: number): Calculator;
|
|
42
|
+
setDiameter(diameter_inches: number): Calculator;
|
|
43
|
+
setDragModel(model: string): Calculator;
|
|
44
|
+
setHumidity(humidity: number): Calculator;
|
|
45
|
+
setMass(mass_grains: number): Calculator;
|
|
46
|
+
setMaxRange(range_yards: number): Calculator;
|
|
47
|
+
setPressure(pressure_inhg: number): Calculator;
|
|
48
|
+
setSightHeight(height_inches: number): Calculator;
|
|
49
|
+
setTemperature(temp_f: number): Calculator;
|
|
50
|
+
setVelocity(velocity_fps: number): Calculator;
|
|
51
|
+
setWind(speed_mph: number, direction_deg: number): Calculator;
|
|
52
|
+
setZeroRange(range_yards: number): Calculator;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
55
|
+
export class WasmBallistics {
|
|
56
|
+
free(): void;
|
|
57
|
+
[Symbol.dispose](): void;
|
|
58
|
+
/**
|
|
59
|
+
* Unload any custom drag table previously installed via [`Self::load_drag_table`],
|
|
60
|
+
* reverting every subsequent `trajectory`, `zero`, `lead`, and `monte-carlo` run to the
|
|
61
|
+
* standard G-model + BC drag (the `-b`/`--bc` value with the selected G1/G7 curve).
|
|
62
|
+
*
|
|
63
|
+
* The inverse of `loadDragTable`. It lets a single engine instance alternate between a
|
|
64
|
+
* measured-curve (CDM) solve and a plain G7-BC solve without constructing a second
|
|
65
|
+
* instance: `load → solve CDM → clear → solve G7`, with the G7 half uncontaminated —
|
|
66
|
+
* the same load/clear pattern `clearWindSegments` provides for segmented wind.
|
|
67
|
+
*
|
|
68
|
+
* Returns `true` if a table was loaded (and is now cleared), `false` if none was loaded
|
|
69
|
+
* (a harmless no-op). Idempotent.
|
|
70
|
+
*/
|
|
71
|
+
clearDragTable(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Report whether a BC5D table is currently loaded.
|
|
74
|
+
*/
|
|
75
|
+
hasBc5dTable(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Report whether a custom drag table is currently loaded.
|
|
78
|
+
*/
|
|
79
|
+
hasDragTable(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Load a BC5D correction table from the raw bytes of a `bc5d_<caliber>.bin`
|
|
82
|
+
* file. The host (browser `fetch()` or Node `fs`/`fetch`) is responsible
|
|
83
|
+
* for retrieving the file — WASM has no filesystem or network — and passes
|
|
84
|
+
* the bytes here.
|
|
85
|
+
*
|
|
86
|
+
* Once loaded, any `trajectory` run that includes `--use-bc-segments` will
|
|
87
|
+
* apply velocity-dependent BC segments synthesized from this table. Load a
|
|
88
|
+
* table matching the bullet's caliber (e.g. `bc5d_308.bin` for a .308).
|
|
89
|
+
*
|
|
90
|
+
* Returns a short human-readable summary of the loaded table. Replaces any
|
|
91
|
+
* previously loaded table.
|
|
92
|
+
*/
|
|
93
|
+
loadBc5dTable(bytes: Uint8Array): string;
|
|
94
|
+
/**
|
|
95
|
+
* Load a custom Mach:Cd drag table (MBA-1328) — a measured or manufacturer-published
|
|
96
|
+
* drag curve (Hornady CDM data, a Lapua/Doppler-radar-derived deck, or your own) — from
|
|
97
|
+
* the raw bytes of a CSV file. The host (browser `fetch()` or Node `fs`/`fetch`) is
|
|
98
|
+
* responsible for retrieving the file — WASM has no filesystem or network — and passes
|
|
99
|
+
* the bytes here, mirroring [`Self::load_bc5d_table`].
|
|
100
|
+
*
|
|
101
|
+
* The bytes must be valid UTF-8 CSV text; parsing is delegated to
|
|
102
|
+
* [`crate::drag::DragTable::from_csv_str`] — the SAME parser native `--drag-table`
|
|
103
|
+
* uses — so the accepted format is identical: two columns `mach,cd` per line, blank
|
|
104
|
+
* lines and `#` comments ignored, a single leading textual header row tolerated, Mach
|
|
105
|
+
* strictly ascending with at least 2 points, Cd finite and > 0.
|
|
106
|
+
*
|
|
107
|
+
* Once loaded, EVERY subsequent `trajectory`, `zero`, `lead`, and `monte-carlo` run
|
|
108
|
+
* applies the table automatically — no `--use-*` gate flag is needed (unlike a loaded
|
|
109
|
+
* BC5D table, which only takes effect with `--use-bc-segments`). A loaded table is a
|
|
110
|
+
* full physical substitute for the G-model + BC (see `calculate_drag_coefficient`):
|
|
111
|
+
* `-b`/`--bc` may still be supplied but is ignored for drag once a table is active
|
|
112
|
+
* (matching the native `--drag-table` CLI semantics documented in CLI_USAGE.md).
|
|
113
|
+
*
|
|
114
|
+
* Returns a short human-readable summary of the loaded table (point count + Mach
|
|
115
|
+
* range). Replaces any previously loaded table.
|
|
116
|
+
*/
|
|
117
|
+
loadDragTable(bytes: Uint8Array): string;
|
|
118
|
+
constructor();
|
|
119
|
+
/**
|
|
120
|
+
* Run a command and return the output
|
|
121
|
+
*/
|
|
122
|
+
runCommand(command: string): string;
|
|
92
123
|
}
|
|
93
|
-
|
|
94
|
-
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
95
|
-
/**
|
|
96
|
-
* Instantiates the given `module`, which can either be bytes or
|
|
97
|
-
* a precompiled `WebAssembly.Module`.
|
|
98
|
-
*
|
|
99
|
-
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
100
|
-
*
|
|
101
|
-
* @returns {InitOutput}
|
|
102
|
-
*/
|
|
103
|
-
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
107
|
-
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
108
|
-
*
|
|
109
|
-
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
110
|
-
*
|
|
111
|
-
* @returns {Promise<InitOutput>}
|
|
112
|
-
*/
|
|
113
|
-
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|