Add next calculators set with flow, magnetism, and EV conversions

This commit is contained in:
Codex Agent
2026-03-08 01:55:19 +00:00
parent e9e5adce42
commit 5e974ea9c7
4 changed files with 174 additions and 89 deletions

View File

@@ -199,30 +199,71 @@ export function solve(
const slug = calc.slug;
const formatAwg = (g: number) => isFinite(g) ? fmt(g) : '';
const awgIsInput = calc.labels.in1.toLowerCase().includes('awg');
const isCircular = slug.includes('circular-mils');
const isArea = slug.includes('square-millimeters');
if (slug.includes('circular-mils')) {
if (source === 1) {
out.val2 = !isNaN(v1) ? fmt(awgToCircularMils(v1)) : '';
if (isCircular) {
if (awgIsInput) {
if (source === 1) out.val2 = !isNaN(v1) ? fmt(awgToCircularMils(v1)) : '';
else out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(circularMilsToAwg(v2)) : '';
} else {
out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(circularMilsToAwg(v2)) : '';
if (source === 1) out.val2 = (!isNaN(v1) && v1 > 0) ? formatAwg(circularMilsToAwg(v1)) : '';
else out.val1 = !isNaN(v2) ? fmt(awgToCircularMils(v2)) : '';
}
} else if (slug.includes('square-millimeters')) {
if (source === 1) {
out.val2 = !isNaN(v1) ? fmt(awgToAreaMm2(v1)) : '';
} else if (isArea) {
if (awgIsInput) {
if (source === 1) out.val2 = !isNaN(v1) ? fmt(awgToAreaMm2(v1)) : '';
else out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(areaMm2ToAwg(v2)) : '';
} else {
out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(areaMm2ToAwg(v2)) : '';
if (source === 1) out.val2 = (!isNaN(v1) && v1 > 0) ? formatAwg(areaMm2ToAwg(v1)) : '';
else out.val1 = !isNaN(v2) ? fmt(awgToAreaMm2(v2)) : '';
}
} else {
// diameter in millimeters
if (source === 1) {
out.val2 = !isNaN(v1) ? fmt(awgToDiameterMm(v1)) : '';
if (awgIsInput) {
if (source === 1) out.val2 = !isNaN(v1) ? fmt(awgToDiameterMm(v1)) : '';
else out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(diameterMmToAwg(v2)) : '';
} else {
out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(diameterMmToAwg(v2)) : '';
if (source === 1) out.val2 = (!isNaN(v1) && v1 > 0) ? formatAwg(diameterMmToAwg(v1)) : '';
else out.val1 = !isNaN(v2) ? fmt(awgToDiameterMm(v2)) : '';
}
}
break;
}
case 'ev-lux': {
const isEvFirst = calc.labels.in1.toLowerCase().includes('ev');
const toLux = (ev: number) => 2.5 * Math.pow(2, ev);
const toEv = (lux: number) => lux > 0 ? Math.log(lux / 2.5) / Math.log(2) : NaN;
if (isEvFirst) {
if (source === 1) out.val2 = !isNaN(v1) ? fmt(toLux(v1)) : '';
else out.val1 = (!isNaN(v2) && v2 > 0) ? fmt(toEv(v2)) : '';
} else {
if (source === 1) out.val2 = (!isNaN(v1) && v1 > 0) ? fmt(toEv(v1)) : '';
else out.val1 = !isNaN(v2) ? fmt(toLux(v2)) : '';
}
break;
}
case 'aov': {
const sensorWidth = 36; // mm, full-frame horizontal
const isFocalFirst = calc.labels.in1.toLowerCase().includes('focal');
const toAov = (f: number) => f > 0 ? (2 * Math.atan(sensorWidth / (2 * f)) * 180 / Math.PI) : NaN;
const toFocal = (angle: number) => {
const radians = angle * Math.PI / 180;
return Math.tan(radians / 2) !== 0 ? sensorWidth / (2 * Math.tan(radians / 2)) : NaN;
};
if (isFocalFirst) {
if (source === 1) out.val2 = (!isNaN(v1) && v1 !== 0) ? fmt(toAov(v1)) : '';
else out.val1 = (!isNaN(v2) && v2 !== 0) ? fmt(toFocal(v2)) : '';
} else {
if (source === 1) out.val2 = (!isNaN(v1) && v1 !== 0) ? fmt(toFocal(v1)) : '';
else out.val1 = (!isNaN(v2) && v2 !== 0) ? fmt(toAov(v2)) : '';
}
break;
}
case 'brinell-rockwell': {
// Approximate correlation for steels:
// BHN = (1520000 - 4500 * HRC) / (100 - HRC)^2