diff --git a/gradle.properties b/gradle.properties index 46ae1c3..2875105 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,15 +1,15 @@ # sytleguide kotlin.code.style=official -# Kotlin 1.4.20-RC: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin -easyPluginVersion=0.11.2 +# Kotlin 1.4.20: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin +easyPluginVersion=0.12.0 # version group=com.soywiz.korlibs.korma version=2.0.0-SNAPSHOT # korlibs -kdsVersion=2.0.0-rc3 +kdsVersion=2.0.0 # bintray location project.bintray.org=korlibs diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix.kt index e783b9a..befb844 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix.kt @@ -5,6 +5,7 @@ package com.soywiz.korma.geom import com.soywiz.korma.interpolation.Interpolable import com.soywiz.korma.interpolation.MutableInterpolable import com.soywiz.korma.interpolation.interpolate +import kotlin.jvm.* import kotlin.math.* data class Matrix( @@ -82,8 +83,12 @@ data class Matrix( fun setTo(a: Float, b: Float, c: Float, d: Float, tx: Float, ty: Float): Matrix = setTo(a.toDouble(), b.toDouble(), c.toDouble(), d.toDouble(), tx.toDouble(), ty.toDouble()) fun setTo(a: Int, b: Int, c: Int, d: Int, tx: Int, ty: Int): Matrix = setTo(a.toDouble(), b.toDouble(), c.toDouble(), d.toDouble(), tx.toDouble(), ty.toDouble()) - fun copyFrom(that: Matrix): Matrix { - setTo(that.a, that.b, that.c, that.d, that.tx, that.ty) + fun copyFrom(that: Matrix?): Matrix { + if (that != null) { + setTo(that.a, that.b, that.c, that.d, that.tx, that.ty) + } else { + identity() + } return this } @@ -172,6 +177,17 @@ data class Matrix( l.tx * r.b + l.ty * r.d + r.ty ) + @JvmName("multiplyNullable") + fun multiply(l: Matrix?, r: Matrix?): Matrix { + when { + l != null && r != null -> multiply(l, r) + l != null -> copyFrom(l) + r != null -> copyFrom(r) + else -> identity() + } + return this + } + /** Transform point without translation */ fun deltaTransformPoint(point: IPoint, out: Point = Point()) = deltaTransformPoint(point.x, point.y, out) fun deltaTransformPoint(x: Float, y: Float, out: Point = Point()): Point = deltaTransformPoint(x.toDouble(), y.toDouble(), out) @@ -480,3 +496,4 @@ data class Matrix( override fun toString(): String = "Matrix(a=$a, b=$b, c=$c, d=$d, tx=$tx, ty=$ty)" } + diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt index 0c49652..db18e91 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt @@ -152,6 +152,8 @@ data class Rectangle( //override fun toString(): String = "Rectangle([${left.niceStr}, ${top.niceStr}]-[${right.niceStr}, ${bottom.niceStr}])" override fun toString(): String = "Rectangle(x=${x.niceStr}, y=${y.niceStr}, width=${width.niceStr}, height=${height.niceStr})" fun toStringBounds(): String = "Rectangle([${left.niceStr},${top.niceStr}]-[${right.niceStr},${bottom.niceStr}])" + fun toStringSize(): String = "Rectangle([${left.niceStr},${top.niceStr}],[${width.niceStr},${height.niceStr}])" + fun toStringCompat(): String = "Rectangle(x=${left.niceStr}, y=${top.niceStr}, w=${width.niceStr}, h=${height.niceStr})" override fun interpolateWith(ratio: Double, other: Rectangle): Rectangle = Rectangle().setToInterpolated(ratio, this, other) @@ -167,6 +169,18 @@ data class Rectangle( out.setTo(left + width * anchor.sx, top + height * anchor.sy) fun toInt() = RectangleInt(x, y, width, height) + fun floor(): Rectangle { + setTo(kotlin.math.floor(x), kotlin.math.floor(y), kotlin.math.floor(width), kotlin.math.floor(height)) + return this + } + fun round(): Rectangle { + setTo(kotlin.math.round(x), kotlin.math.round(y), kotlin.math.round(width), kotlin.math.round(height)) + return this + } + fun ceil(): Rectangle { + setTo(kotlin.math.ceil(x), kotlin.math.ceil(y), kotlin.math.ceil(width), kotlin.math.ceil(height)) + return this + } } inline fun Rectangle.setTo(x: Number, y: Number, width: Number, height: Number) =