ballistics-engine 0.25.0 → 0.26.0

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.
@@ -1,534 +0,0 @@
1
- /**
2
- * Object-oriented calculator for programmatic use
3
- * Provides a type-safe, fluent API alternative to the CLI interface
4
- */
5
- export class Calculator {
6
- static __wrap(ptr) {
7
- ptr = ptr >>> 0;
8
- const obj = Object.create(Calculator.prototype);
9
- obj.__wbg_ptr = ptr;
10
- CalculatorFinalization.register(obj, obj.__wbg_ptr, obj);
11
- return obj;
12
- }
13
- __destroy_into_raw() {
14
- const ptr = this.__wbg_ptr;
15
- this.__wbg_ptr = 0;
16
- CalculatorFinalization.unregister(this);
17
- return ptr;
18
- }
19
- free() {
20
- const ptr = this.__destroy_into_raw();
21
- wasm.__wbg_calculator_free(ptr, 0);
22
- }
23
- /**
24
- * Add a downrange wind segment: `speed_mph` from `direction_deg`
25
- * (wind-FROM: 0 = headwind, 90 = from the right) out to `until_yards`.
26
- * Each segment applies from the previous boundary to `until_yards`; wind is
27
- * zero beyond the last segment. When any segment is added it overrides the
28
- * scalar `setWind` value. Repeatable.
29
- * @param {number} speed_mph
30
- * @param {number} direction_deg
31
- * @param {number} until_yards
32
- * @returns {Calculator}
33
- */
34
- addWindSegment(speed_mph, direction_deg, until_yards) {
35
- const ptr = this.__destroy_into_raw();
36
- const ret = wasm.calculator_addWindSegment(ptr, speed_mph, direction_deg, until_yards);
37
- return Calculator.__wrap(ret);
38
- }
39
- /**
40
- * Calculate trajectory and return result as JavaScript object
41
- * Returns: { range_yards, drop_inches, windage_inches, velocity_fps, energy_ftlb, time_sec }
42
- * @param {number} range_yards
43
- * @returns {any}
44
- */
45
- calculateTrajectory(range_yards) {
46
- const ret = wasm.calculator_calculateTrajectory(this.__wbg_ptr, range_yards);
47
- if (ret[2]) {
48
- throw takeFromExternrefTable0(ret[1]);
49
- }
50
- return takeFromExternrefTable0(ret[0]);
51
- }
52
- /**
53
- * Remove all downrange wind segments (reverts to the scalar `setWind`).
54
- * @returns {Calculator}
55
- */
56
- clearWindSegments() {
57
- const ptr = this.__destroy_into_raw();
58
- const ret = wasm.calculator_clearWindSegments(ptr);
59
- return Calculator.__wrap(ret);
60
- }
61
- /**
62
- * @param {boolean} enabled
63
- * @param {number | null} [latitude]
64
- * @returns {Calculator}
65
- */
66
- enableCoriolis(enabled, latitude) {
67
- const ptr = this.__destroy_into_raw();
68
- const ret = wasm.calculator_enableCoriolis(ptr, enabled, !isLikeNone(latitude), isLikeNone(latitude) ? 0 : latitude);
69
- return Calculator.__wrap(ret);
70
- }
71
- /**
72
- * @param {boolean} enabled
73
- * @param {number | null} [twist_rate]
74
- * @returns {Calculator}
75
- */
76
- enableSpinDrift(enabled, twist_rate) {
77
- const ptr = this.__destroy_into_raw();
78
- const ret = wasm.calculator_enableSpinDrift(ptr, enabled, !isLikeNone(twist_rate), isLikeNone(twist_rate) ? 0 : twist_rate);
79
- return Calculator.__wrap(ret);
80
- }
81
- /**
82
- * Get full trajectory table as array of points
83
- * Returns array of: [{ range_yards, drop_inches, windage_inches, velocity_fps, energy_ftlb, time_sec }, ...]
84
- * @returns {any}
85
- */
86
- getFullTrajectory() {
87
- const ret = wasm.calculator_getFullTrajectory(this.__wbg_ptr);
88
- if (ret[2]) {
89
- throw takeFromExternrefTable0(ret[1]);
90
- }
91
- return takeFromExternrefTable0(ret[0]);
92
- }
93
- /**
94
- * Create a new calculator with default values
95
- * Defaults: .308 Winchester 168gr at 2700 fps, standard atmosphere
96
- */
97
- constructor() {
98
- const ret = wasm.calculator_new();
99
- this.__wbg_ptr = ret >>> 0;
100
- CalculatorFinalization.register(this, this.__wbg_ptr, this);
101
- return this;
102
- }
103
- /**
104
- * @param {number} altitude_ft
105
- * @returns {Calculator}
106
- */
107
- setAltitude(altitude_ft) {
108
- const ptr = this.__destroy_into_raw();
109
- const ret = wasm.calculator_setAltitude(ptr, altitude_ft);
110
- return Calculator.__wrap(ret);
111
- }
112
- /**
113
- * @param {number} bc
114
- * @returns {Calculator}
115
- */
116
- setBC(bc) {
117
- const ptr = this.__destroy_into_raw();
118
- const ret = wasm.calculator_setBC(ptr, bc);
119
- return Calculator.__wrap(ret);
120
- }
121
- /**
122
- * @param {number} diameter_inches
123
- * @returns {Calculator}
124
- */
125
- setDiameter(diameter_inches) {
126
- const ptr = this.__destroy_into_raw();
127
- const ret = wasm.calculator_setDiameter(ptr, diameter_inches);
128
- return Calculator.__wrap(ret);
129
- }
130
- /**
131
- * @param {string} model
132
- * @returns {Calculator}
133
- */
134
- setDragModel(model) {
135
- const ptr = this.__destroy_into_raw();
136
- const ptr0 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
137
- const len0 = WASM_VECTOR_LEN;
138
- const ret = wasm.calculator_setDragModel(ptr, ptr0, len0);
139
- return Calculator.__wrap(ret);
140
- }
141
- /**
142
- * @param {number} humidity
143
- * @returns {Calculator}
144
- */
145
- setHumidity(humidity) {
146
- const ptr = this.__destroy_into_raw();
147
- const ret = wasm.calculator_setHumidity(ptr, humidity);
148
- return Calculator.__wrap(ret);
149
- }
150
- /**
151
- * @param {number} mass_grains
152
- * @returns {Calculator}
153
- */
154
- setMass(mass_grains) {
155
- const ptr = this.__destroy_into_raw();
156
- const ret = wasm.calculator_setMass(ptr, mass_grains);
157
- return Calculator.__wrap(ret);
158
- }
159
- /**
160
- * @param {number} range_yards
161
- * @returns {Calculator}
162
- */
163
- setMaxRange(range_yards) {
164
- const ptr = this.__destroy_into_raw();
165
- const ret = wasm.calculator_setMaxRange(ptr, range_yards);
166
- return Calculator.__wrap(ret);
167
- }
168
- /**
169
- * @param {number} pressure_inhg
170
- * @returns {Calculator}
171
- */
172
- setPressure(pressure_inhg) {
173
- const ptr = this.__destroy_into_raw();
174
- const ret = wasm.calculator_setPressure(ptr, pressure_inhg);
175
- return Calculator.__wrap(ret);
176
- }
177
- /**
178
- * @param {number} height_inches
179
- * @returns {Calculator}
180
- */
181
- setSightHeight(height_inches) {
182
- const ptr = this.__destroy_into_raw();
183
- const ret = wasm.calculator_setSightHeight(ptr, height_inches);
184
- return Calculator.__wrap(ret);
185
- }
186
- /**
187
- * @param {number} temp_f
188
- * @returns {Calculator}
189
- */
190
- setTemperature(temp_f) {
191
- const ptr = this.__destroy_into_raw();
192
- const ret = wasm.calculator_setTemperature(ptr, temp_f);
193
- return Calculator.__wrap(ret);
194
- }
195
- /**
196
- * @param {number} velocity_fps
197
- * @returns {Calculator}
198
- */
199
- setVelocity(velocity_fps) {
200
- const ptr = this.__destroy_into_raw();
201
- const ret = wasm.calculator_setVelocity(ptr, velocity_fps);
202
- return Calculator.__wrap(ret);
203
- }
204
- /**
205
- * @param {number} speed_mph
206
- * @param {number} direction_deg
207
- * @returns {Calculator}
208
- */
209
- setWind(speed_mph, direction_deg) {
210
- const ptr = this.__destroy_into_raw();
211
- const ret = wasm.calculator_setWind(ptr, speed_mph, direction_deg);
212
- return Calculator.__wrap(ret);
213
- }
214
- /**
215
- * @param {number} range_yards
216
- * @returns {Calculator}
217
- */
218
- setZeroRange(range_yards) {
219
- const ptr = this.__destroy_into_raw();
220
- const ret = wasm.calculator_setZeroRange(ptr, range_yards);
221
- return Calculator.__wrap(ret);
222
- }
223
- }
224
- if (Symbol.dispose) Calculator.prototype[Symbol.dispose] = Calculator.prototype.free;
225
-
226
- export class WasmBallistics {
227
- __destroy_into_raw() {
228
- const ptr = this.__wbg_ptr;
229
- this.__wbg_ptr = 0;
230
- WasmBallisticsFinalization.unregister(this);
231
- return ptr;
232
- }
233
- free() {
234
- const ptr = this.__destroy_into_raw();
235
- wasm.__wbg_wasmballistics_free(ptr, 0);
236
- }
237
- /**
238
- * Report whether a BC5D table is currently loaded.
239
- * @returns {boolean}
240
- */
241
- hasBc5dTable() {
242
- const ret = wasm.wasmballistics_hasBc5dTable(this.__wbg_ptr);
243
- return ret !== 0;
244
- }
245
- /**
246
- * Report whether a custom drag table is currently loaded.
247
- * @returns {boolean}
248
- */
249
- hasDragTable() {
250
- const ret = wasm.wasmballistics_hasDragTable(this.__wbg_ptr);
251
- return ret !== 0;
252
- }
253
- /**
254
- * Load a BC5D correction table from the raw bytes of a `bc5d_<caliber>.bin`
255
- * file. The host (browser `fetch()` or Node `fs`/`fetch`) is responsible
256
- * for retrieving the file — WASM has no filesystem or network — and passes
257
- * the bytes here.
258
- *
259
- * Once loaded, any `trajectory` run that includes `--use-bc-segments` will
260
- * apply velocity-dependent BC segments synthesized from this table. Load a
261
- * table matching the bullet's caliber (e.g. `bc5d_308.bin` for a .308).
262
- *
263
- * Returns a short human-readable summary of the loaded table. Replaces any
264
- * previously loaded table.
265
- * @param {Uint8Array} bytes
266
- * @returns {string}
267
- */
268
- loadBc5dTable(bytes) {
269
- let deferred3_0;
270
- let deferred3_1;
271
- try {
272
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
273
- const len0 = WASM_VECTOR_LEN;
274
- const ret = wasm.wasmballistics_loadBc5dTable(this.__wbg_ptr, ptr0, len0);
275
- var ptr2 = ret[0];
276
- var len2 = ret[1];
277
- if (ret[3]) {
278
- ptr2 = 0; len2 = 0;
279
- throw takeFromExternrefTable0(ret[2]);
280
- }
281
- deferred3_0 = ptr2;
282
- deferred3_1 = len2;
283
- return getStringFromWasm0(ptr2, len2);
284
- } finally {
285
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
286
- }
287
- }
288
- /**
289
- * Load a custom Mach:Cd drag table (MBA-1328) — a measured or manufacturer-published
290
- * drag curve (Hornady CDM data, a Lapua/Doppler-radar-derived deck, or your own) — from
291
- * the raw bytes of a CSV file. The host (browser `fetch()` or Node `fs`/`fetch`) is
292
- * responsible for retrieving the file — WASM has no filesystem or network — and passes
293
- * the bytes here, mirroring [`Self::load_bc5d_table`].
294
- *
295
- * The bytes must be valid UTF-8 CSV text; parsing is delegated to
296
- * [`crate::drag::DragTable::from_csv_str`] — the SAME parser native `--drag-table`
297
- * uses — so the accepted format is identical: two columns `mach,cd` per line, blank
298
- * lines and `#` comments ignored, a single leading textual header row tolerated, Mach
299
- * strictly ascending with at least 2 points, Cd finite and > 0.
300
- *
301
- * Once loaded, EVERY subsequent `trajectory`, `zero`, `lead`, and `monte-carlo` run
302
- * applies the table automatically — no `--use-*` gate flag is needed (unlike a loaded
303
- * BC5D table, which only takes effect with `--use-bc-segments`). A loaded table is a
304
- * full physical substitute for the G-model + BC (see `calculate_drag_coefficient`):
305
- * `-b`/`--bc` may still be supplied but is ignored for drag once a table is active
306
- * (matching the native `--drag-table` CLI semantics documented in CLI_USAGE.md).
307
- *
308
- * Returns a short human-readable summary of the loaded table (point count + Mach
309
- * range). Replaces any previously loaded table.
310
- * @param {Uint8Array} bytes
311
- * @returns {string}
312
- */
313
- loadDragTable(bytes) {
314
- let deferred3_0;
315
- let deferred3_1;
316
- try {
317
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
318
- const len0 = WASM_VECTOR_LEN;
319
- const ret = wasm.wasmballistics_loadDragTable(this.__wbg_ptr, ptr0, len0);
320
- var ptr2 = ret[0];
321
- var len2 = ret[1];
322
- if (ret[3]) {
323
- ptr2 = 0; len2 = 0;
324
- throw takeFromExternrefTable0(ret[2]);
325
- }
326
- deferred3_0 = ptr2;
327
- deferred3_1 = len2;
328
- return getStringFromWasm0(ptr2, len2);
329
- } finally {
330
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
331
- }
332
- }
333
- constructor() {
334
- const ret = wasm.wasmballistics_new();
335
- this.__wbg_ptr = ret >>> 0;
336
- WasmBallisticsFinalization.register(this, this.__wbg_ptr, this);
337
- return this;
338
- }
339
- /**
340
- * Run a command and return the output
341
- * @param {string} command
342
- * @returns {string}
343
- */
344
- runCommand(command) {
345
- let deferred3_0;
346
- let deferred3_1;
347
- try {
348
- const ptr0 = passStringToWasm0(command, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
349
- const len0 = WASM_VECTOR_LEN;
350
- const ret = wasm.wasmballistics_runCommand(this.__wbg_ptr, ptr0, len0);
351
- var ptr2 = ret[0];
352
- var len2 = ret[1];
353
- if (ret[3]) {
354
- ptr2 = 0; len2 = 0;
355
- throw takeFromExternrefTable0(ret[2]);
356
- }
357
- deferred3_0 = ptr2;
358
- deferred3_1 = len2;
359
- return getStringFromWasm0(ptr2, len2);
360
- } finally {
361
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
362
- }
363
- }
364
- }
365
- if (Symbol.dispose) WasmBallistics.prototype[Symbol.dispose] = WasmBallistics.prototype.free;
366
- export function __wbg___wbindgen_throw_39bc967c0e5a9b58(arg0, arg1) {
367
- throw new Error(getStringFromWasm0(arg0, arg1));
368
- }
369
- export function __wbg_getRandomValues_cc7f052a444bb2ce() { return handleError(function (arg0, arg1) {
370
- globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
371
- }, arguments); }
372
- export function __wbg_new_cbee8c0d5c479eac() {
373
- const ret = new Array();
374
- return ret;
375
- }
376
- export function __wbg_new_ed69e637b553a997() {
377
- const ret = new Object();
378
- return ret;
379
- }
380
- export function __wbg_push_a6f9488ffd3fae3b(arg0, arg1) {
381
- const ret = arg0.push(arg1);
382
- return ret;
383
- }
384
- export function __wbg_set_bad5c505cc70b5f8() { return handleError(function (arg0, arg1, arg2) {
385
- const ret = Reflect.set(arg0, arg1, arg2);
386
- return ret;
387
- }, arguments); }
388
- export function __wbindgen_cast_0000000000000001(arg0) {
389
- // Cast intrinsic for `F64 -> Externref`.
390
- const ret = arg0;
391
- return ret;
392
- }
393
- export function __wbindgen_cast_0000000000000002(arg0, arg1) {
394
- // Cast intrinsic for `Ref(String) -> Externref`.
395
- const ret = getStringFromWasm0(arg0, arg1);
396
- return ret;
397
- }
398
- export function __wbindgen_init_externref_table() {
399
- const table = wasm.__wbindgen_externrefs;
400
- const offset = table.grow(4);
401
- table.set(0, undefined);
402
- table.set(offset + 0, undefined);
403
- table.set(offset + 1, null);
404
- table.set(offset + 2, true);
405
- table.set(offset + 3, false);
406
- }
407
- const CalculatorFinalization = (typeof FinalizationRegistry === 'undefined')
408
- ? { register: () => {}, unregister: () => {} }
409
- : new FinalizationRegistry(ptr => wasm.__wbg_calculator_free(ptr >>> 0, 1));
410
- const WasmBallisticsFinalization = (typeof FinalizationRegistry === 'undefined')
411
- ? { register: () => {}, unregister: () => {} }
412
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmballistics_free(ptr >>> 0, 1));
413
-
414
- function addToExternrefTable0(obj) {
415
- const idx = wasm.__externref_table_alloc();
416
- wasm.__wbindgen_externrefs.set(idx, obj);
417
- return idx;
418
- }
419
-
420
- function getArrayU8FromWasm0(ptr, len) {
421
- ptr = ptr >>> 0;
422
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
423
- }
424
-
425
- function getStringFromWasm0(ptr, len) {
426
- ptr = ptr >>> 0;
427
- return decodeText(ptr, len);
428
- }
429
-
430
- let cachedUint8ArrayMemory0 = null;
431
- function getUint8ArrayMemory0() {
432
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
433
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
434
- }
435
- return cachedUint8ArrayMemory0;
436
- }
437
-
438
- function handleError(f, args) {
439
- try {
440
- return f.apply(this, args);
441
- } catch (e) {
442
- const idx = addToExternrefTable0(e);
443
- wasm.__wbindgen_exn_store(idx);
444
- }
445
- }
446
-
447
- function isLikeNone(x) {
448
- return x === undefined || x === null;
449
- }
450
-
451
- function passArray8ToWasm0(arg, malloc) {
452
- const ptr = malloc(arg.length * 1, 1) >>> 0;
453
- getUint8ArrayMemory0().set(arg, ptr / 1);
454
- WASM_VECTOR_LEN = arg.length;
455
- return ptr;
456
- }
457
-
458
- function passStringToWasm0(arg, malloc, realloc) {
459
- if (realloc === undefined) {
460
- const buf = cachedTextEncoder.encode(arg);
461
- const ptr = malloc(buf.length, 1) >>> 0;
462
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
463
- WASM_VECTOR_LEN = buf.length;
464
- return ptr;
465
- }
466
-
467
- let len = arg.length;
468
- let ptr = malloc(len, 1) >>> 0;
469
-
470
- const mem = getUint8ArrayMemory0();
471
-
472
- let offset = 0;
473
-
474
- for (; offset < len; offset++) {
475
- const code = arg.charCodeAt(offset);
476
- if (code > 0x7F) break;
477
- mem[ptr + offset] = code;
478
- }
479
- if (offset !== len) {
480
- if (offset !== 0) {
481
- arg = arg.slice(offset);
482
- }
483
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
484
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
485
- const ret = cachedTextEncoder.encodeInto(arg, view);
486
-
487
- offset += ret.written;
488
- ptr = realloc(ptr, len, offset, 1) >>> 0;
489
- }
490
-
491
- WASM_VECTOR_LEN = offset;
492
- return ptr;
493
- }
494
-
495
- function takeFromExternrefTable0(idx) {
496
- const value = wasm.__wbindgen_externrefs.get(idx);
497
- wasm.__externref_table_dealloc(idx);
498
- return value;
499
- }
500
-
501
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
502
- cachedTextDecoder.decode();
503
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
504
- let numBytesDecoded = 0;
505
- function decodeText(ptr, len) {
506
- numBytesDecoded += len;
507
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
508
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
509
- cachedTextDecoder.decode();
510
- numBytesDecoded = len;
511
- }
512
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
513
- }
514
-
515
- const cachedTextEncoder = new TextEncoder();
516
-
517
- if (!('encodeInto' in cachedTextEncoder)) {
518
- cachedTextEncoder.encodeInto = function (arg, view) {
519
- const buf = cachedTextEncoder.encode(arg);
520
- view.set(buf);
521
- return {
522
- read: arg.length,
523
- written: buf.length
524
- };
525
- };
526
- }
527
-
528
- let WASM_VECTOR_LEN = 0;
529
-
530
-
531
- let wasm;
532
- export function __wbg_set_wasm(val) {
533
- wasm = val;
534
- }