Skip to content

Commit 645bc2b

Browse files
committed
Merge remote-tracking branch 'origin/refactor/ui' into refactor/ui
2 parents 1fa3d04 + bb7ff6b commit 645bc2b

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

common/src/main/kotlin/com/lambda/graphics/animation/Animation.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ class Animation(initialValue: Double, val update: (Double) -> Double) {
5757

5858
fun AnimationTicker.exp(min: () -> Double, max: () -> Double, speed: () -> Double, flag: () -> Boolean) =
5959
Animation(min()) {
60-
val min = min()
61-
val max = max()
62-
val target = if (flag()) max else min
60+
val minVal = min()
61+
val maxVal = max()
62+
val target = if (flag()) maxVal else minVal
6363

64-
if (abs(target - it) < CLAMP * abs(max - min)) target
64+
if (abs(target - it) < CLAMP * abs(maxVal - minVal)) target
6565
else lerp(speed(), it, target)
6666
}.apply(::register)
6767

common/src/main/kotlin/com/lambda/gui/impl/clickgui/module/settings/NumberSlider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class NumberSlider <V> (
4242

4343
slider.onSlide {
4444
settingDelegate = settingDelegate.typeConvert(
45-
lerp(it, min, max).roundToStep(setting.step.toDouble())
45+
lerp(it, min, max).roundToStep(setting.step).toDouble()
4646
)
4747
}
4848
}

common/src/main/kotlin/com/lambda/module/modules/client/GuiSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ object GuiSettings : Module(
4848
val shadeBackground by setting("Shade Background", true, visibility = { page == Page.Colors })
4949
val colorWidth by setting("Shade Width", 200.0, 10.0..1000.0, 10.0, visibility = { page == Page.Colors })
5050
val colorHeight by setting("Shade Height", 200.0, 10.0..1000.0, 10.0, visibility = { page == Page.Colors })
51-
val colorSpeed by setting("Color Speed", 1.0, 0.1..10.0, 0.1, visibility = { page == Page.Colors })
51+
val colorSpeed by setting("Color Speed", 1.0, 0.1..5.0, 0.1, visibility = { page == Page.Colors })
5252

5353
val mainColor: Color get() = if (shade) Color.WHITE else primaryColor
5454

common/src/main/kotlin/com/lambda/util/math/MathUtils.kt

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,17 @@ object MathUtils {
4040
fun Double.ceilToInt() = ceil(this).toInt()
4141

4242
fun <T : Number> T.roundToStep(step: T): T {
43-
val stepD = step.toDouble()
44-
if (stepD == 0.0) return this
45-
46-
var value = round(toDouble() / stepD) * stepD
47-
value = value.roundToPlaces(stepD.decimals)
48-
if (abs(value) == 0.0) value = 0.0
49-
50-
return typeConvert(value)
43+
val valueBD = BigDecimal(toString())
44+
val stepBD = BigDecimal(step.toString())
45+
if (stepBD.compareTo(BigDecimal.ZERO) == 0) return this
46+
val scaled = valueBD.divide(stepBD, stepBD.scale(), RoundingMode.HALF_UP)
47+
.setScale(0, RoundingMode.HALF_UP)
48+
.multiply(stepBD)
49+
.setScale(stepBD.scale(), RoundingMode.HALF_UP)
50+
51+
return typeConvert(scaled.toDouble())
5152
}
5253

53-
private fun Double.roundToPlaces(places: Int) =
54-
BigDecimal(this).setScale(places, RoundingMode.HALF_EVEN).toDouble()
55-
56-
private val Double.decimals: Int
57-
get() = BigDecimal.valueOf(this).scale()
58-
5954
fun <T : Number> T.typeConvert(valueIn: Double): T {
6055
@Suppress("UNCHECKED_CAST")
6156
return when (this) {

0 commit comments

Comments
 (0)