From a478407e8f7087a3ce40d38b99992e0c291007f8 Mon Sep 17 00:00:00 2001 From: Reinholds Zviedris Date: Sat, 15 Aug 2026 19:55:27 +0300 Subject: [PATCH] added target card --- README.md | 19 ++- index.html | 361 ++++++++++++++++++++++++++++++++++++++++++----------- test.js | 51 ++++++++ 3 files changed, 356 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index d805728..86c6ed8 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,26 @@ aware) into the wind/drift column. > Note: this is a helper/estimator. Verify against real dope before relying on it. +## Target card + +A third section builds a **dial-up card for a set of known targets** instead of an +even range ladder. Add a row per target (minimum one), type its distance, and get +the correction for each — rows are lettered **A, B, C, …** so they match how you +range and call them. + +It reuses the load, atmosphere, wind and turret settings from the sections above, +so the numbers agree with the trajectory table. For every target it shows drop +(cm + MRAD/MOA), elevation clicks to dial UP, drift with the side it pushes to, +windage clicks with the direction to dial, time of flight and remaining velocity. +Targets are kept in the order you entered them, and any distance the bullet can't +reach is reported as *no solution* rather than silently estimated. + ## Tests -`test.js` extracts the app's ` diff --git a/test.js b/test.js index 348afd1..ad0beb3 100644 --- a/test.js +++ b/test.js @@ -142,6 +142,57 @@ test('denser air = more drop', () => { const thick = simulate({ ...P, rho: rho * 1.2 }, a1, [800])[0]; assert(thick.y < thin.y); }); + +console.log('target card:'); +const TURRET = { clickCm: 0.25, perMark: 4, perTurn: 36 }; +const CTX = { p: { ...P }, angle: findZeroAngle({ ...P }), sg: 1.7, massKg: 175 * GRAIN_TO_KG }; + +test('row labels run A, B, C ... Z, AA, AB', () => { + assert.deepStrictEqual([0, 1, 4, 25, 26, 27, 51, 52].map(targetLabel), + ['A', 'B', 'E', 'Z', 'AA', 'AB', 'AZ', 'BA']); +}); +test('clicksFor matches the README example', () => + assert.strictEqual(clicksFor(40.14, 300, 0.25), 54)); +test('fmtClicks renders a dialable breakdown', () => { + assert.strictEqual(fmtClicks(54, 4, 36), '54 (13m+2)'); + assert.strictEqual(fmtClicks(150, 4, 36), '150 (1t 1m+2)'); +}); +test('one target row solves', () => { + const s = solveShots(CTX, [300], TURRET); + assert.strictEqual(s.length, 1); + assert(s[0].dropCm > 40 && s[0].eClk > 0); +}); +test('target order is preserved even when distances are unsorted', () => { + const s = solveShots(CTX, [600, 200, 400], TURRET); + assert.deepStrictEqual(s.map(x => x.dist), [600, 200, 400]); +}); +test('duplicate distances both get a solution', () => { + const s = solveShots(CTX, [300, 300], TURRET); + assert.strictEqual(s.length, 2); + approx(s[0].dropCm, s[1].dropCm, 1e-9); +}); +test('unreachable and missing distances come back null, neighbours still solve', () => { + const s = solveShots(CTX, [300, 20000, NaN, 0], TURRET); + assert(s[0] && s[0].eClk > 0); + assert.strictEqual(s[1], null); + assert.strictEqual(s[2], null); + assert.strictEqual(s[3], null); +}); +test('farther target needs more elevation', () => { + const [a, b] = solveShots(CTX, [300, 600], TURRET); + assert(b.dropCm > a.dropCm && b.eClk > a.eClk); +}); +test('spin drift is folded into the target wind column', () => { + twistDir = 'R'; + const spun = solveShots(CTX, [800], TURRET)[0]; + const flat = solveShots({ ...CTX, sg: null }, [800], TURRET)[0]; + approx(flat.windCm, 0, 1e-9, 'no wind, no spin'); + assert(spun.windCm > 0 && spun.side === 'R'); +}); +test('crosswind target drifts to the correct side', () => { + const s = solveShots({ ...CTX, p: { ...P, windZ: -4 }, sg: null }, [500], TURRET)[0]; + assert(s.windCm < 0 && s.side === 'L' && s.wClk > 0); +}); `; eval(src + suite);