(baseThreshold: number, spanFrac: number)
| 117 | * Target grows ~ 1/spanFrac but capped to prevent excessive memory. |
| 118 | */ |
| 119 | const computeZoomAwareTarget = (baseThreshold: number, spanFrac: number): number => { |
| 120 | // Mirrors createRenderCoordinator’s behavior (see examples/sampling/main.ts): |
| 121 | // - baseline target is samplingThreshold at full span |
| 122 | // - zooming in increases target ~ 1/spanFrac |
| 123 | // - capped to avoid pathological allocations |
| 124 | const MIN_TARGET_POINTS = 2; |
| 125 | const MAX_TARGET_POINTS_ABS = 200_000; |
| 126 | const MAX_TARGET_MULTIPLIER = 32; |
| 127 | |
| 128 | const spanFracSafe = Math.max(1e-3, Math.min(1, spanFrac)); |
| 129 | const baseT = Number.isFinite(baseThreshold) ? Math.max(1, baseThreshold | 0) : 1; |
| 130 | const maxTarget = Math.min(MAX_TARGET_POINTS_ABS, Math.max(MIN_TARGET_POINTS, baseT * MAX_TARGET_MULTIPLIER)); |
| 131 | |
| 132 | const v = Math.round(baseT / spanFracSafe); |
| 133 | return clamp(v | 0, MIN_TARGET_POINTS, maxTarget); |
| 134 | }; |
| 135 | |
| 136 | /** |
| 137 | * Estimates points rendered after sampling. |
no test coverage detected