All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.korlibs.math.geom.Scale.kt Maven / Gradle / Ivy

There is a newer version: 4.0.10
Show newest version
package korlibs.math.geom

import korlibs.math.annotations.*
import korlibs.memory.pack.*

//@KormaValueApi
inline class Scale internal constructor(internal val raw: Float2Pack) {
    val scaleX: Float get() = raw.f0
    val scaleY: Float get() = raw.f1
    val scaleAvg: Float get() = scaleX * .5f + scaleY * .5f

    val avg: Float get() = scaleAvg
    val avgD: Double get() = scaleAvg.toDouble()

    val scaleXD: Double get() = scaleX.toDouble()
    val scaleYD: Double get() = scaleY.toDouble()
    val scaleAvgD: Double get() = scaleAvg.toDouble()

    constructor() : this(1f, 1f)
    constructor(scale: Float) : this(float2PackOf(scale, scale))
    constructor(scale: Double) : this(scale.toFloat())
    constructor(scale: Int) : this(scale.toFloat())
    constructor(scaleX: Float, scaleY: Float) : this(float2PackOf(scaleX, scaleY))
    constructor(scaleX: Double, scaleY: Double) : this(scaleX.toFloat(), scaleY.toFloat())
    constructor(scaleX: Int, scaleY: Int) : this(scaleX.toFloat(), scaleY.toFloat())
}

fun Scale.toPoint(): Point = Point(raw)
fun Scale.toVector2(): Vector2 = Vector2(raw)

@KormaMutableApi
sealed interface IScale {
    val scaleX: Double
    val scaleY: Double
}

@KormaMutableApi
data class MScale(
    override var scaleX: Double,
    override var scaleY: Double,
) : IScale




© 2015 - 2025 Weber Informatics LLC | Privacy Policy