Skip to content

Commit 49d317e

Browse files
committed
improve mse by 4% to 0.049 from 0.051 (rounded values)
1 parent cfdff8c commit 49d317e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/utils/getTunedTotalCapacity1.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { CapacityMeshNode } from "lib/types/capacity-mesh-types"
1111
* @returns The calculated capacity
1212
*/
1313
export const getTunedTotalCapacity1 = (
14-
nodeOrWidth: CapacityMeshNode | { width: number; availableZ?: number[] },
14+
nodeOrWidth:
15+
| CapacityMeshNode
16+
| { width: number; height?: number; availableZ?: number[] },
1517
maxCapacityFactor = 1,
1618
opts: { viaDiameter?: number; obstacleMargin?: number } = {},
1719
) => {
@@ -20,7 +22,17 @@ export const getTunedTotalCapacity1 = (
2022
const obstacleMargin = opts.obstacleMargin ?? 0.2
2123

2224
const width = "width" in nodeOrWidth ? nodeOrWidth.width : nodeOrWidth
23-
const viaLengthAcross = width / (VIA_DIAMETER / 2 + obstacleMargin)
25+
const height =
26+
"height" in nodeOrWidth && typeof nodeOrWidth.height === "number"
27+
? nodeOrWidth.height
28+
: width
29+
30+
// Use the geometric mean so thin rectangular nodes are assigned less capacity
31+
// than similarly wide square nodes while preserving previous behavior when only
32+
// width is provided.
33+
const effectiveNodeSpan = Math.sqrt(width * height)
34+
const viaLengthAcross =
35+
effectiveNodeSpan / (VIA_DIAMETER / 2 + obstacleMargin)
2436

2537
const tunedTotalCapacity = (viaLengthAcross / 2) ** 1.1 * maxCapacityFactor
2638

@@ -30,7 +42,6 @@ export const getTunedTotalCapacity1 = (
3042

3143
return tunedTotalCapacity
3244
}
33-
3445
/**
3546
* Calculate the optimal subdivision depth to reach a target minimum capacity
3647
* @param initialWidth The initial width of the top-level node

0 commit comments

Comments
 (0)