Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix function moveToward #649

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions kt/godot-library/src/main/kotlin/godot/global/GDMath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import godot.util.isEqualApprox
import godot.util.isZeroApprox
import godot.util.toRealT
import kotlin.math.pow
import kotlin.math.abs
import kotlin.math.sign

//Necessary for stepDecimal function
const val MAX_N = 10
Expand Down Expand Up @@ -348,19 +350,19 @@ internal interface GDMath {

/** Moves from toward to by the delta value.
* Use a negative delta value to move away. */
fun moveToward(from: Int, to: Int, delta: Int) = from + kotlin.math.min(to - from, delta)
fun moveToward(from: Int, to: Int, delta: Int) = if (abs(to - from) <= delta) to else from + (to - from).sign * delta

/** Moves from toward to by the delta value.
* Use a negative delta value to move away. */
fun moveToward(from: Long, to: Long, delta: Long) = from + kotlin.math.min(to - from, delta)
fun moveToward(from: Long, to: Long, delta: Long) = if (abs(to - from) <= delta) to else from + (to - from).sign * delta

/** Moves from toward to by the delta value.
* Use a negative delta value to move away. */
fun moveToward(from: Float, to: Float, delta: Float) = from + kotlin.math.min(to - from, delta)
fun moveToward(from: Float, to: Float, delta: Float) = if (abs(to - from) <= delta) to else from + (to - from).sign * delta

/** Moves from toward to by the delta value.
* Use a negative delta value to move away. */
fun moveToward(from: Double, to: Double, delta: Double) = from + kotlin.math.min(to - from, delta)
fun moveToward(from: Double, to: Double, delta: Double) = if (abs(to - from) <= delta) to else from + (to - from).sign * delta


/** Returns the nearest larger power of 2 for integer value. */
Expand Down
Loading