All files / tools/src/utilities/draw3D calculateAdaptiveSphereRadius.ts

0% Statements 0/5
0% Branches 0/6
0% Functions 0/1
0% Lines 0/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27                                                     
/**
 * Calculate an adaptive sphere radius based on the diagonal of the volume.
 * This allows the sphere size to scale with the volume size.
 * @param diagonal The diagonal length of the volume in world coordinates.
 * @param config Configuration object with sphere radius settings
 * @returns The calculated adaptive radius, clamped between min and max limits.
 */
export function calculateAdaptiveSphereRadius(
  diagonal: number,
  config: {
    sphereRadius?: number;
    sphereRadiusScale?: number;
    minSphereRadius?: number;
    maxSphereRadius?: number;
  }
): number {
  // Scale radius as a percentage of diagonal (adjustable factor)
  const scaleFactor = config.sphereRadiusScale || 0.01; // 1% of diagonal by default
  const adaptiveRadius = diagonal * scaleFactor;
 
  // Apply min/max limits to prevent too small or too large spheres
  const minRadius = config.minSphereRadius || 2;
  const maxRadius = config.maxSphereRadius || 50;
 
  return Math.max(minRadius, Math.min(maxRadius, adaptiveRadius));
}