Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Both the click value and clicks-per-mark are adjustable for other scopes/turrets
A full turn is set in **clicks**, so turrets whose turn ends mid-mark work too:
a 100-click 1/8 MOA turret (8 clicks per mark = 12.5 marks per turn) dials
113 clicks as `1 turn · mark 1 · + 5 clicks`. An optional **total elevation
clicks** value flags corrections (⚠) beyond the turret's travel.
clicks** value caps the dial: past it the tables show the max clicks
(`⚠ max`) plus an **Over hold** column with the remainder to hold over on the
reticle (SFP-scaled when applicable).

### Reticle: FFP / SFP

Expand Down
61 changes: 41 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,15 @@ <h1>Target Card</h1>

const overTravel = (clicks, total) => total > 0 && clicks > total;

/* Past the turret's travel the shooter dials the max and holds the remainder on
the reticle. Returned as a reticle reading (SFP-scaled), or null if dialable. */
function overHold(offsetCm, dist, t, o) {
const clicks = clicksFor(offsetCm, dist, t.clickCm);
if (!overTravel(clicks, t.total) || !(dist > 0)) return null;
const restCm = offsetCm - t.total * t.clickCm * dist / 100;
return Math.max(0, restCm) / unitCm(trajUnit, dist) * o.scale;
}

/* ---- Reticle ----
An SFP reticle only subtends its nominal value at one magnification; at zoom M
each division covers nominal × cal / M, so a hold of A reads as A × M / cal
Expand Down Expand Up @@ -800,19 +809,22 @@ <h1>Target Card</h1>
detailEl.textContent = '';
return;
}
outEl.innerHTML = r.clicks + ' <span>clicks</span>';
const b = breakdownClicks(r.clicks, t.perMark, t.perTurn);
const o = opticSettings();
const rest = overHold(r.offsetCm, dist, t, o);
const dial = rest == null ? r.clicks : t.total;
outEl.innerHTML = dial + ` <span>clicks${rest == null ? '' : ' (max)'}</span>`;
const b = breakdownClicks(dial, t.perMark, t.perTurn);
const parts = [];
if (b) {
if (b.turns > 0) parts.push(`${b.turns} turn${b.turns !== 1 ? 's' : ''}`);
parts.push(`mark ${b.mark}`);
parts.push(`+ ${b.rem} click${b.rem !== 1 ? 's' : ''}`);
}
breakdownEl.textContent = parts.join(' · ');
if (overTravel(r.clicks, t.total)) {
breakdownEl.innerHTML += `<div style="color:var(--danger)">⚠ beyond the turret's ${t.total} clicks of travel — hold the rest</div>`;
if (rest != null) {
breakdownEl.innerHTML += `<div style="color:var(--danger)">⚠ needs ${r.clicks} clicks, turret has ${t.total} — ` +
`dial max and hold over <b>${rest.toFixed(2)} ${trajUnit}</b>${holdTag(o) ? ' ' + holdTag(o) : ''}</div>`;
}
const o = opticSettings();
const hold = r.offsetCm / unitCm(trajUnit, dist) * o.scale;
detailEl.textContent =
`${labelWord} = ${r.offsetCm.toFixed(2)} cm · 1 click = ${r.clickCmAtDist.toFixed(3)} cm @ ${dist} m · raw ${r.rawClicks.toFixed(2)}` +
Expand Down Expand Up @@ -1137,16 +1149,19 @@ <h1>Target Card</h1>
return clickCmAtDist > 0 ? Math.round(offsetCm / clickCmAtDist) : 0;
}

// "54 (13m+2)" or "150 (1t 1m+2)" — dialable directly on the turret; ⚠ past `total`.
// "54 (13m+2)" or "150 (1t 1m+2)" — dialable directly on the turret.
// Past `total` it shows the max that can be dialed, flagged "⚠ max".
function fmtClicks(n, perMark, perTurn, total) {
const a = Math.abs(n);
const over = overTravel(Math.abs(n), total);
const a = over ? total : Math.abs(n);
const b = breakdownClicks(a, perMark, perTurn);
const warn = overTravel(a, total) ? ' ⚠' : '';
const warn = over ? ' ⚠ max' : '';
if (!b) return a + warn;
return a + ' (' + (b.turns > 0 ? b.turns + 't ' : '') + b.mark + 'm+' + b.rem + ')' + warn;
}

const TRAVEL_NOTE = t => `⚠ = beyond the turret's ${t.total} clicks of elevation travel — hold the rest on the reticle.`;
const TRAVEL_NOTE = (t, u) => `⚠ max = needs more than the turret's ${t.total} clicks of elevation — ` +
`dial the max and hold the "Over hold ${u}" value on the reticle.`;

const angOf = (offsetCm, dist) => dist > 0 ? offsetCm / unitCm(trajUnit, dist) : 0;

Expand Down Expand Up @@ -1273,38 +1288,41 @@ <h1>Target Card</h1>
const uLabel = trajUnit;
const o = opticSettings();
const sfp = o.plane === 'SFP';
const shots = raw.map(r => deriveShot(ctx, r, t));
const over = shots.some(s => overTravel(s.eClk, t.total));
let html = '<table><thead><tr>' +
'<th>Dist m</th><th>Vel m/s</th><th>Energy J</th><th>ToF s</th>' +
`<th>Drop cm</th><th>Drop ${uLabel}</th>${sfp ? '<th>Elev hold</th>' : ''}<th>Elev clk</th>` +
(over ? `<th>Over hold ${uLabel}</th>` : '') +
`<th>Wind cm</th><th>Wind ${uLabel}</th>${sfp ? '<th>Wind hold</th>' : ''}<th>Wind clk</th>` +
'</tr></thead><tbody>';
let cards = '';
let over = false;

for (const raw_r of raw) {
const s = deriveShot(ctx, raw_r, t);
for (const s of shots) {
const dist = s.dist;
const rest = overHold(s.dropCm, dist, t, o);
html += '<tr>' +
`<td>${dist}</td><td>${s.v.toFixed(0)}</td><td>${s.energy.toFixed(0)}</td><td>${s.tof.toFixed(2)}</td>` +
`<td>${s.dropCm.toFixed(1)}</td><td>${angOf(s.dropCm, dist).toFixed(2)}</td>` +
(sfp ? `<td>${(angOf(s.dropCm, dist) * o.scale).toFixed(2)}</td>` : '') +
`<td>${fmtClicks(s.eClk, t.perMark, t.perTurn, t.total)}</td>` +
(over ? `<td>${rest == null ? '–' : rest.toFixed(2)}</td>` : '') +
`<td>${Math.abs(s.windCm).toFixed(1)} ${s.side}</td><td>${Math.abs(angOf(s.windCm, dist)).toFixed(2)}</td>` +
(sfp ? `<td>${Math.abs(angOf(s.windCm, dist) * o.scale).toFixed(2)}</td>` : '') +
`<td>${fmtClicks(s.wClk, t.perMark, t.perTurn)} ${s.side}</td>` +
'</tr>';
if (overTravel(s.eClk, t.total)) over = true;
cards +=
`<div class="tcard"><div class="d">${dist} m</div>` +
`<div>Drop ${s.dropCm.toFixed(1)} cm · ${angOf(s.dropCm, dist).toFixed(2)} ${uLabel}${sfp ? ` (hold ${(angOf(s.dropCm, dist) * o.scale).toFixed(2)})` : ''} · dial UP ${fmtClicks(s.eClk, t.perMark, t.perTurn, t.total)}</div>` +
`<div>Drop ${s.dropCm.toFixed(1)} cm · ${angOf(s.dropCm, dist).toFixed(2)} ${uLabel}${sfp ? ` (hold ${(angOf(s.dropCm, dist) * o.scale).toFixed(2)})` : ''} · dial UP ${fmtClicks(s.eClk, t.perMark, t.perTurn, t.total)}` +
`${rest == null ? '' : ` + hold over ${rest.toFixed(2)} ${uLabel}`}</div>` +
`<div>Wind ${Math.abs(s.windCm).toFixed(1)} cm ${s.side} · ${Math.abs(angOf(s.windCm, dist)).toFixed(2)} ${uLabel}${sfp ? ` (hold ${Math.abs(angOf(s.windCm, dist) * o.scale).toFixed(2)})` : ''} · dial ${s.side === 'R' ? 'LEFT' : 'RIGHT'} ${fmtClicks(s.wClk, t.perMark, t.perTurn)}</div>` +
`<div class="m">${s.v.toFixed(0)} m/s · ${s.energy.toFixed(0)} J · ${s.tof.toFixed(2)} s</div></div>`;
}
html += '</tbody></table>';
wrap.innerHTML = html;
cardsEl.innerHTML = cards;
wrap.dataset.has = '1';
noteEl.textContent = [noteEl.textContent, over ? TRAVEL_NOTE(t) : '',
noteEl.textContent = [noteEl.textContent, over ? TRAVEL_NOTE(t, uLabel) : '',
sfp ? `Hold columns are reticle readings ${holdTag(o)}.` : ''].filter(Boolean).join(' ');
}

Expand Down Expand Up @@ -1374,11 +1392,12 @@ <h1>Target Card</h1>
const uLabel = trajUnit;
const o = opticSettings();
const sfp = o.plane === 'SFP';
let over = false;
const over = shots.some(s => s && overTravel(s.eClk, t.total));

let html = '<table><thead><tr>' +
'<th>Target</th><th>Dist m</th>' +
`<th>Drop cm</th><th>Elev ${uLabel}</th>${sfp ? '<th>Elev hold</th>' : ''}<th>Elev clk (UP)</th>` +
(over ? `<th>Over hold ${uLabel}</th>` : '') +
`<th>Drift cm</th><th>Wind ${uLabel}</th>${sfp ? '<th>Wind hold</th>' : ''}<th>Wind clk (dial)</th>` +
'<th>ToF s</th><th>Vel m/s</th>' +
'</tr></thead><tbody>';
Expand All @@ -1391,28 +1410,30 @@ <h1>Target Card</h1>
unreachable.push(name);
const shown = dists[i] > 0 ? Math.round(dists[i]) : '–';
html += `<tr><td>${name}</td><td>${shown}</td>` +
'<td>–</td>'.repeat(sfp ? 10 : 8) + '</tr>';
'<td>–</td>'.repeat(8 + (sfp ? 2 : 0) + (over ? 1 : 0)) + '</tr>';
cards += `<div class="tcard"><div class="d">${name} · ${shown} m</div>` +
'<div class="m">No solution — set a distance the bullet can reach.</div></div>';
return;
}
const dist = s.dist;
const dialSide = s.side === 'R' ? 'LEFT' : 'RIGHT';
const rest = overHold(s.dropCm, dist, t, o);
html += '<tr>' +
`<td>${name}</td><td>${dist}</td>` +
`<td>${s.dropCm.toFixed(1)}</td><td>${angOf(s.dropCm, dist).toFixed(2)}</td>` +
(sfp ? `<td>${(angOf(s.dropCm, dist) * o.scale).toFixed(2)}</td>` : '') +
`<td>${fmtClicks(s.eClk, t.perMark, t.perTurn, t.total)}</td>` +
(over ? `<td>${rest == null ? '–' : rest.toFixed(2)}</td>` : '') +
`<td>${Math.abs(s.windCm).toFixed(1)} ${s.side}</td>` +
`<td>${Math.abs(angOf(s.windCm, dist)).toFixed(2)}</td>` +
(sfp ? `<td>${Math.abs(angOf(s.windCm, dist) * o.scale).toFixed(2)}</td>` : '') +
`<td>${fmtClicks(s.wClk, t.perMark, t.perTurn)} ${dialSide.charAt(0)}</td>` +
`<td>${s.tof.toFixed(2)}</td><td>${s.v.toFixed(0)}</td>` +
'</tr>';
if (overTravel(s.eClk, t.total)) over = true;
cards +=
`<div class="tcard"><div class="d">${name} · ${dist} m</div>` +
`<div>Drop ${s.dropCm.toFixed(1)} cm · ${angOf(s.dropCm, dist).toFixed(2)} ${uLabel}${sfp ? ` (hold ${(angOf(s.dropCm, dist) * o.scale).toFixed(2)})` : ''} · dial UP ${fmtClicks(s.eClk, t.perMark, t.perTurn, t.total)}</div>` +
`<div>Drop ${s.dropCm.toFixed(1)} cm · ${angOf(s.dropCm, dist).toFixed(2)} ${uLabel}${sfp ? ` (hold ${(angOf(s.dropCm, dist) * o.scale).toFixed(2)})` : ''} · dial UP ${fmtClicks(s.eClk, t.perMark, t.perTurn, t.total)}` +
`${rest == null ? '' : ` + hold over ${rest.toFixed(2)} ${uLabel}`}</div>` +
`<div>Wind ${Math.abs(s.windCm).toFixed(1)} cm ${s.side} · ${Math.abs(angOf(s.windCm, dist)).toFixed(2)} ${uLabel}${sfp ? ` (hold ${Math.abs(angOf(s.windCm, dist) * o.scale).toFixed(2)})` : ''} · dial ${dialSide} ${fmtClicks(s.wClk, t.perMark, t.perTurn)}</div>` +
`<div class="m">${s.v.toFixed(0)} m/s · ${s.energy.toFixed(0)} J · ${s.tof.toFixed(2)} s</div></div>`;
});
Expand All @@ -1425,7 +1446,7 @@ <h1>Target Card</h1>
noteEl.textContent = `No solution for target${unreachable.length > 1 ? 's' : ''} ` +
`${unreachable.join(', ')} — distance missing or beyond this load's reach.`;
}
noteEl.textContent = [noteEl.textContent, over ? TRAVEL_NOTE(t) : '',
noteEl.textContent = [noteEl.textContent, over ? TRAVEL_NOTE(t, uLabel) : '',
sfp ? `Hold columns are reticle readings ${holdTag(o)}.` : ''].filter(Boolean).join(' ');
}

Expand Down
13 changes: 12 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,20 @@ test('travel limit is flagged only when set and exceeded', () => {
assert.strictEqual(overTravel(120, 100), true);
assert.strictEqual(overTravel(100, 100), false);
assert.strictEqual(overTravel(120, 0), false);
assert.strictEqual(fmtClicks(113, 8, 100, 100), '113 (1t 1m+5) ⚠');
assert.strictEqual(fmtClicks(113, 8, 100, 100), '100 (1t 0m+0) ⚠ max');
assert.strictEqual(fmtClicks(54, 4, 144, 200), '54 (13m+2)');
});
test('past max travel: dial the max, hold the rest on the reticle', () => {
trajUnit = 'MOA';
const t = { clickCm: clickCmFrom('MOA', '0.125', ''), total: 100 }; // 100 x 1/8 MOA = 12.5 MOA
const ffp = { scale: 1 }, sfp = { scale: reticleScale('SFP', 20, 40) };
const at = 500, cm = 15 * unitCm('MOA', at); // 15 MOA of drop
approx(overHold(cm, at, t, ffp), 2.5, 1e-9, 'FFP holds 15 - 12.5 MOA');
approx(overHold(cm, at, t, sfp), 1.25, 1e-9, 'SFP @ 20x of 40x halves it');
assert.strictEqual(overHold(10 * unitCm('MOA', at), at, t, ffp), null, '10 MOA fits the turret');
assert.strictEqual(overHold(cm, at, { ...t, total: 0 }, ffp), null, 'no limit set');
trajUnit = 'MRAD';
});
test('SFP reticle scale: true at cal mag, halves at half zoom; FFP always 1', () => {
assert.strictEqual(reticleScale('SFP', 40, 40), 1);
assert.strictEqual(reticleScale('SFP', 20, 40), 0.5);
Expand Down
Loading