commonMain.korlibs.math.interpolation.Interpolation.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of korma-jvm Show documentation
Show all versions of korma-jvm Show documentation
Mathematic library for Multiplatform Kotlin 1.3
The newest version!
package korlibs.math.interpolation
import korlibs.datastructure.fastCastTo
import korlibs.math.geom.*
interface Interpolable {
fun interpolateWith(ratio: Ratio, other: T): T
}
interface MutableInterpolable {
fun setToInterpolated(ratio: Ratio, l: T, r: T): T
}
fun Ratio.interpolate(l: Point, r: Point): Point = Point(interpolate(l.x, r.x), interpolate(l.y, r.y))
fun Ratio.interpolate(l: Size, r: Size): Size = Size(interpolate(l.width, r.width), interpolate(l.height, r.height))
fun Ratio.interpolate(l: Scale, r: Scale): Scale = Scale(interpolate(l.scaleX, r.scaleX), interpolate(l.scaleY, r.scaleY))
fun Ratio.interpolate(l: Float, r: Float): Float = (l + (r - l) * valueF)
fun Ratio.interpolate(l: Double, r: Double): Double = (l + (r - l) * valueD)
fun Ratio.interpolate(l: Int, r: Int): Int = (l + (r - l) * valueD).toInt()
fun Ratio.interpolate(l: Long, r: Long): Long = (l + (r - l) * valueD).toLong()
fun Ratio.interpolate(l: Interpolable, r: Interpolable): T = l.interpolateWith(this, r.fastCastTo())
fun > Ratio.interpolate(l: T, r: T): T = l.interpolateWith(this, r)
fun Ratio.interpolate(l: Matrix, r: Matrix): Matrix = Matrix.interpolated(l, r, this)
fun Ratio.interpolate(l: MatrixTransform, r: MatrixTransform): MatrixTransform = MatrixTransform.interpolated(l, r, this)
fun Ratio.interpolate(l: Rectangle, r: Rectangle): Rectangle = Rectangle.interpolated(l, r, this)