@@ -2,18 +2,47 @@ package io.monstarlab.mosaic.slider
2
2
3
3
import kotlin.math.sqrt
4
4
5
+ /* *
6
+ * Determines how the values will be distributed across the slider
7
+ * Usually the values are distributed in a linear fashion, this interfaces allows
8
+ * to control the distribution using simple math expressions
9
+ * @see ParabolicValueDistribution to see how values can be distributed using parabolic curve
10
+ */
5
11
public interface SliderValueDistribution {
6
12
13
+ /* *
14
+ * Interpolates a value based on the distribution strategy.
15
+ * @param value the input value to interpolate
16
+ * @return the interpolated value based on the distribution strategy
17
+ */
7
18
public fun interpolate (value : Float ): Float
8
19
20
+ /* *
21
+ * Inversely interpolates a value from the output range to the input range based on the distribution strategy.
22
+ *
23
+ * @param value the output value to inverse interpolate
24
+ * @return the inverse interpolated value based on the distribution strategy
25
+ */
9
26
public fun inverse (value : Float ): Float
10
27
11
28
public companion object {
12
29
30
+ /* *
31
+ * Creates a [SliderValueDistribution] with a parabolic distribution strategy.
32
+ *
33
+ * @param a coefficient of the x^2 term in the parabolic equation
34
+ * @param b coefficient of the x term in the parabolic equation
35
+ * @param c constant term in the parabolic equation
36
+ * @return a [SliderValueDistribution] instance with a parabolic distribution strategy
37
+ */
13
38
public fun parabolic (a : Float , b : Float , c : Float ): SliderValueDistribution {
14
39
return ParabolicValueDistribution (a, b, c)
15
40
}
16
41
42
+ /* *
43
+ * A linear distribution strategy where the input value is directly mapped to the output value.
44
+ * Used in [Slider] by default
45
+ */
17
46
public val Linear : SliderValueDistribution = object : SliderValueDistribution {
18
47
override fun interpolate (value : Float ): Float {
19
48
return value
@@ -26,6 +55,18 @@ public interface SliderValueDistribution {
26
55
}
27
56
}
28
57
58
+
59
+ /* *
60
+ * Represents a parabolic distribution strategy for slider values.
61
+ *
62
+ * This strategy calculates interpolated and inversely interpolated values based on a parabolic equation:
63
+ * f(x) = a * x^2 + b * x + c
64
+ *
65
+ * @property a coefficient of the x^2 term in the parabolic equation
66
+ * @property b coefficient of the x term in the parabolic equation
67
+ * @property c constant term in the parabolic equation
68
+ * @constructor Creates a ParabolicValueDistribution with the given coefficients.
69
+ */
29
70
public class ParabolicValueDistribution (
30
71
private val a : Float ,
31
72
private val b : Float ,
0 commit comments