Line data Source code
1 : /**
2 : * Calculates the effective brush size based on the base size and hardness.
3 : * As hardness decreases, the effective size increases to allow for a softer falloff.
4 : *
5 : * @param size - The base radius of the brush
6 : * @param hardness - The hardness of the brush (0.0 to 1.0)
7 : * @returns The effective radius of the brush
8 : */
9 848 : export function getEffectiveBrushSize(size: number, hardness: number): number {
10 : // Scale factor for maximum softness
11 : const MAX_SCALE = 1.5
12 : const scale = 1.0 + (1.0 - hardness) * (MAX_SCALE - 1.0)
13 : return size * scale
14 : }
15 :
16 : /**
17 : * Calculates the effective hardness to maintain the visual "hard core" of the brush.
18 : * Since the effective size is larger, we need to adjust the hardness value so that
19 : * the inner hard circle remains at the same physical radius as the original size * hardness.
20 : *
21 : * @param size - The base radius of the brush
22 : * @param hardness - The base hardness of the brush
23 : * @param effectiveSize - The effective radius (calculated by getEffectiveBrushSize)
24 : * @returns The adjusted hardness value (0.0 to 1.0)
25 : */
26 744 : export function getEffectiveHardness(
27 : size: number,
28 : hardness: number,
29 : effectiveSize: number
30 : ): number {
31 744 : if (effectiveSize <= 0) return 0
32 : // Adjust hardness to maintain the physical radius of the hard core
33 744 : return (size * hardness) / effectiveSize
34 : }
|