@@ -3,6 +3,7 @@ package com.lambda.graphics.animation
33import com.lambda.Lambda.mc
44import com.lambda.util.math.MathUtils.lerp
55import com.lambda.util.primitives.extension.partialTicks
6+ import kotlin.math.abs
67import kotlin.reflect.KProperty
78
89class Animation (initialValue : Double , val update : (Double ) -> Double ) {
@@ -24,16 +25,29 @@ class Animation(initialValue: Double, val update: (Double) -> Double) {
2425
2526 companion object {
2627 fun AnimationTicker.exp (min : Double , max : Double , speed : Double , flag : () -> Boolean ) =
27- Animation (min) {
28- val target = if (flag()) max else min
29- lerp(it, target, speed)
28+ exp({ min }, { max }, speed, flag)
29+
30+ fun AnimationTicker.exp (min : () -> Double , max : () -> Double , speed : Double , flag : () -> Boolean ) =
31+ Animation (min()) {
32+ val target = if (flag()) max() else min()
33+ if (abs(target - it) < CLAMP ) target
34+ else lerp(it, target, speed)
3035 }.apply (::register)
3136
3237 fun AnimationTicker.linear (min : Double , max : Double , step : Double , flag : () -> Boolean ) =
3338 Animation (min) {
3439 val target = if (flag()) max else min
3540 target.coerceIn(it - step, it + step)
3641 }.apply (::register)
42+
43+ fun AnimationTicker.linear (min : () -> Double , max : () -> Double , step : Double , flag : () -> Boolean ) =
44+ Animation (min()) {
45+ val target = if (flag()) max() else min()
46+ target.coerceIn(it - step, it + step)
47+ }.apply (::register)
48+
49+ // Exponent animation will never reach target value
50+ private const val CLAMP = 0.01
3751 }
3852}
3953
0 commit comments