Skip to content

Commit c848695

Browse files
committed
style: apply spotless
1 parent 6238c74 commit c848695

File tree

7 files changed

+26
-39
lines changed

7 files changed

+26
-39
lines changed

demo/src/main/java/io/monstarlab/mosaic/features/SliderDemo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import androidx.compose.ui.tooling.preview.Preview
3939
import androidx.compose.ui.unit.dp
4040
import io.monstarlab.mosaic.slider.Slider
4141
import io.monstarlab.mosaic.slider.SliderColors
42-
import io.monstarlab.mosaic.slider.distribution.SliderValueDistribution
4342
import io.monstarlab.mosaic.slider.distribution.CheckPointsValueDistribution
43+
import io.monstarlab.mosaic.slider.distribution.SliderValueDistribution
4444
import kotlin.math.roundToInt
4545
import androidx.compose.material3.Slider as MaterialSlider
4646

slider/src/main/java/io/monstarlab/mosaic/slider/MathUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ internal fun Float.fractionToValue(rangeStart: Float, rangeEnd: Float): Float =
1818
scale(0f, 1f, this.coerceIn(0f, 1f), rangeStart, rangeEnd)
1919

2020
internal fun Float.fractionToValue(range: ClosedFloatingPointRange<Float>): Float =
21-
scale(0f, 1f, this, range.start, range.endInclusive)
21+
scale(0f, 1f, this, range.start, range.endInclusive)

slider/src/main/java/io/monstarlab/mosaic/slider/SliderState.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ public class SliderState(
6565
* the "real" position of the thumb
6666
*/
6767
internal val offsetAsFraction: Float
68-
get() = if (totalWidth == 0f) 0f else {
68+
get() = if (totalWidth == 0f) {
69+
0f
70+
} else {
6971
val valueFraction = value.valueToFraction(range)
70-
valueDistribution.inverse(valueFraction).coerceIn(0f,1f)
72+
valueDistribution.inverse(valueFraction).coerceIn(0f, 1f)
7173
}
7274

73-
7475
internal val disabledRangeAsFractions: ClosedFloatingPointRange<Float>
7576
get() = coerceRangeIntoFractions(disabledRange)
7677

@@ -127,7 +128,9 @@ public class SliderState(
127128
*/
128129
private fun scaleToOffset(value: Float): Float {
129130
val valueAsFraction = coerceUserValue(value).valueToFraction(range)
130-
return valueDistribution.inverse(valueAsFraction).fractionToValue(0f, totalWidth)
131+
return valueDistribution
132+
.inverse(valueAsFraction)
133+
.fractionToValue(0f, totalWidth)
131134
}
132135

133136
internal fun coerceUserValue(value: Float): Float {
@@ -137,10 +140,11 @@ public class SliderState(
137140
}
138141

139142
private fun Float.coerceIntoDisabledRange(): Float {
140-
if (disabledRange.isEmpty() || !disabledRange.contains(this)) return this
141-
if (this - disabledRange.start < disabledRange.endInclusive - this) disabledRange.start else disabledRange.endInclusive
142-
// check if disabled range is on the left or right
143+
if (disabledRange.isEmpty() || !disabledRange.contains(this)) {
144+
return this
145+
}
143146

147+
// check if disabled range is on the left or right
144148
return if (disabledRange.start == range.start) {
145149
coerceAtLeast(disabledRange.endInclusive)
146150
} else {

slider/src/main/java/io/monstarlab/mosaic/slider/distribution/CheckPointsValueDistribution.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package io.monstarlab.mosaic.slider.distribution
33
import io.monstarlab.mosaic.slider.valueToFraction
44

55
public class CheckPointsValueDistribution(
6-
valuesMap: List<Pair<Float, Float>>
6+
valuesMap: List<Pair<Float, Float>>,
77
) :
88
SliderValueDistribution {
99

@@ -42,25 +42,22 @@ public class CheckPointsValueDistribution(
4242
}
4343
}
4444

45-
4645
override fun interpolate(value: Float): Float {
4746
val equation = equations.firstOrNull { it.offsetRange.contains(value) }?.equation
4847
checkNotNull(equation) { "No equation found for value $value during interpolate" }
4948
return equation.valueFromOffset(value)
5049
}
5150

52-
5351
override fun inverse(value: Float): Float {
5452
val equation = equations.firstOrNull { it.valueRange.contains(value) }?.equation
5553
checkNotNull(equation) { "No equation found for value $value during inverse" }
5654
return equation.offsetFromValue(value)
5755
}
5856

59-
6057
public class DecreasingValueException(progressValuePair: Pair<Float, Float>) :
6158
IllegalStateException(
6259
"Values must be always increasing with increasing progress," +
63-
" item at progress ${progressValuePair.first} with value " +
64-
"${progressValuePair.second} is breaking this rule "
60+
" item at progress ${progressValuePair.first} with value " +
61+
"${progressValuePair.second} is breaking this rule ",
6562
)
66-
}
63+
}

slider/src/main/java/io/monstarlab/mosaic/slider/distribution/LinearEquation.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ public data class LinearEquation(
99
public fun offsetFromValue(value: Float): Float = (value - c) / m
1010

1111
public companion object {
12-
public fun fromTwoPoints(
13-
x1: Float, y1: Float,
14-
x2: Float, y2: Float
15-
): LinearEquation {
12+
public fun fromTwoPoints(x1: Float, y1: Float, x2: Float, y2: Float): LinearEquation {
1613
require(x2 != x1) { "can't calc equation from points with similar x value" }
1714
val slope = (y2 - y1) / (x2 - x1)
1815
val c = y2 - slope * x2

slider/src/main/java/io/monstarlab/mosaic/slider/distribution/SliderValueDistribution.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.monstarlab.mosaic.slider.distribution
22

33
import androidx.annotation.FloatRange
4-
import kotlin.math.sqrt
54

65
/**
76
* Determines how the values will be distributed across the slider
@@ -36,11 +35,7 @@ public interface SliderValueDistribution {
3635
* @param c constant term in the parabolic equation
3736
* @return a [SliderValueDistribution] instance with a parabolic distribution strategy
3837
*/
39-
public fun parabolic(
40-
a: Float,
41-
b: Float = 0f,
42-
c: Float = 0f,
43-
): SliderValueDistribution {
38+
public fun parabolic(a: Float, b: Float = 0f, c: Float = 0f): SliderValueDistribution {
4439
return ParabolicValueDistribution(a, b, c)
4540
}
4641

slider/src/test/java/io/monstarlab/mosaic/slider/CheckPointsValueDistributionTest.kt

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
package io.monstarlab.mosaic.slider
22

33
import io.monstarlab.mosaic.slider.distribution.CheckPointsValueDistribution
4-
import org.junit.Assert.*
5-
64
import org.junit.After
5+
import org.junit.Assert.assertEquals
6+
import org.junit.Assert.assertThrows
77
import org.junit.Before
88
import org.junit.Test
99

1010
class CheckPointsValueDistributionTest {
1111

12-
private lateinit var checkPointsValueDistribution : CheckPointsValueDistribution
12+
private lateinit var checkPointsValueDistribution: CheckPointsValueDistribution
1313
private val accuracy = 0.0001f
1414

1515
@Before
1616
fun setUp() {
17-
18-
checkPointsValueDistribution = CheckPointsValueDistribution(
17+
checkPointsValueDistribution = CheckPointsValueDistribution(
1918
listOf(
2019
0f to 0f,
2120
25f to 25f,
2221
50f to 75f,
2322
100f to 100f,
24-
)
23+
),
2524
)
2625
}
2726

@@ -38,15 +37,13 @@ class CheckPointsValueDistributionTest {
3837
5f to 10f,
3938
8f to 16f,
4039
7f to 20f,
41-
)
40+
),
4241
)
4342
}
44-
4543
}
4644

4745
@Test
4846
fun `create from pairs and interpolate`() {
49-
5047
val points = listOf(
5148
0.1f to 0.1f,
5249
0.2f to 0.2f,
@@ -58,12 +55,10 @@ class CheckPointsValueDistributionTest {
5855
points.forEach {
5956
assertEquals(it.second, checkPointsValueDistribution.interpolate(it.first), accuracy)
6057
}
61-
6258
}
6359

6460
@Test
6561
fun `create from pairs and inverse`() {
66-
6762
val points = listOf(
6863
0.1f to 0.1f,
6964
0.2f to 0.2f,
@@ -75,6 +70,5 @@ class CheckPointsValueDistributionTest {
7570
points.forEach {
7671
assertEquals(it.first, checkPointsValueDistribution.inverse(it.second), accuracy)
7772
}
78-
7973
}
80-
}
74+
}

0 commit comments

Comments
 (0)