diff --git a/src/components/DimensionsView.tsx b/src/components/DimensionsView.tsx index 1bfa81f..d1a5680 100644 --- a/src/components/DimensionsView.tsx +++ b/src/components/DimensionsView.tsx @@ -110,14 +110,14 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat }, [groups, showOnlyInconsistent]); const nearDuplicateClusters = useMemo((): NearDuplicateCluster[] => { - // Two groups are "similar" if every sorted dimension pair differs by ≤15% + // Two groups are "similar" if every sorted dimension pair differs by < 1 cm absolute // (keys are already sorted ascending, e.g. "15x20x29") - const THRESHOLD = 0.15; + const MAX_DIFF_CM = 1; - const maxRelativeDiff = (keyA: string, keyB: string): number => { + const maxAbsDiff = (keyA: string, keyB: string): number => { const a = keyA.split('x').map(Number); const b = keyB.split('x').map(Number); - return Math.max(...a.map((v, i) => Math.abs(v - b[i]) / Math.max(v, b[i], 0.001))); + return Math.max(...a.map((v, i) => Math.abs(v - b[i]))); }; const validGroups = groups.filter(g => g.volume > 0); @@ -135,8 +135,8 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat const b = validGroups[j]; if (assignedKeys.has(b.key)) continue; - // b must be similar to every group already in the cluster - const isSimilar = cluster.every(g => maxRelativeDiff(g.key, b.key) <= THRESHOLD); + // b must be within 1 cm on every axis of every group already in the cluster + const isSimilar = cluster.every(g => maxAbsDiff(g.key, b.key) < MAX_DIFF_CM); if (isSimilar) { cluster.push(b); assignedKeys.add(b.key); @@ -145,11 +145,11 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat if (cluster.length >= 2) { const volumes = cluster.map(g => g.volume); - // Max dimension-wise diff across all pairs in the cluster + // Max absolute diff (cm) across all pairs in the cluster let maxDiffPct = 0; for (let x = 0; x < cluster.length; x++) { for (let y = x + 1; y < cluster.length; y++) { - maxDiffPct = Math.max(maxDiffPct, maxRelativeDiff(cluster[x].key, cluster[y].key) * 100); + maxDiffPct = Math.max(maxDiffPct, maxAbsDiff(cluster[x].key, cluster[y].key)); } } clusters.push({ groups: cluster, volumes, maxDiffPct }); @@ -254,7 +254,7 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat Possible data entry errors - {nearDuplicateClusters.length} cluster{nearDuplicateClusters.length !== 1 ? 's' : ''} with similar dimensions (≤15% per axis) + {nearDuplicateClusters.length} cluster{nearDuplicateClusters.length !== 1 ? 's' : ''} with dimensions differing <1 cm per axis {nearDuplicateClusters.map((cluster, ci) => ( @@ -276,7 +276,7 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat ))} - — max axis diff {cluster.maxDiffPct.toFixed(1)}% + — max diff {cluster.maxDiffPct.toFixed(1)} cm