fix laser utility calculations

This commit is contained in:
makearmy 2026-07-10 17:22:41 -04:00
parent b59e8e54bb
commit 0855724cb0
5 changed files with 58 additions and 131 deletions

View file

@ -29,11 +29,12 @@ export default function Page() {
setGapUm(L > 0 ? (UM_PER_INCH / L).toFixed(2) : "");
}
const overlap = useMemo(() => {
const coverage = useMemo(() => {
const d = num(spotUm);
const g = num(gapUm);
if (d <= 0 || g <= 0) return 0;
return Math.max(0, Math.min(100, 100 * (1 - g / d)));
if (d <= 0 || g <= 0) return { overlap: 0, uncovered: 0 };
const signed = 100 * (1 - g / d);
return { overlap: Math.max(0, signed), uncovered: Math.max(0, -signed) };
}, [spotUm, gapUm]);
const gapMm = (num(gapUm) / 1000) || 0;
@ -68,7 +69,10 @@ export default function Page() {
<CardContent className="grid gap-3 sm:grid-cols-4">
<div>
<div className="text-sm text-muted-foreground">Overlap</div>
<div className="text-lg">{overlap.toFixed(1)}%</div>
<div className="text-lg">{coverage.overlap.toFixed(1)}%</div>
{coverage.uncovered > 0 && (
<div className="text-xs text-amber-600">{coverage.uncovered.toFixed(1)}% uncovered gap</div>
)}
</div>
<div>
<div className="text-sm text-muted-foreground">Gap</div>
@ -83,10 +87,10 @@ export default function Page() {
<div>
<div className="text-sm text-muted-foreground">From LPI</div>
<div className="text-lg">
{(UM_PER_INCH / Math.max(1, num(lpi)) / 1000).toFixed(4)} mm
{num(lpi) > 0 ? (UM_PER_INCH / num(lpi) / 1000).toFixed(4) : "0.0000"} mm
</div>
<div className="text-xs text-muted-foreground">
{(UM_PER_INCH / Math.max(1, num(lpi))).toFixed(1)} µm
{num(lpi) > 0 ? (UM_PER_INCH / num(lpi)).toFixed(1) : "0.0"} µm
</div>
</div>
</CardContent>
@ -94,4 +98,3 @@ export default function Page() {
</ToolShell>
);
}