diff --git a/gradle.properties b/gradle.properties index 3284fcf..cb779bc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ group=com.soywiz.korlibs.korma version=2.0.0-SNAPSHOT # korlibs -kdsVersion=2.2.0 +kdsVersion=2.2.1 # bintray location project.bintray.org=korlibs diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..7454180 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 69a9715..05679dc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0..744e882 100755 --- a/gradlew +++ b/gradlew @@ -72,7 +72,7 @@ case "`uname`" in Darwin* ) darwin=true ;; - MINGW* ) + MSYS* | MINGW* ) msys=true ;; NONSTOP* ) 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 47ac493..9978e43 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix.kt @@ -25,6 +25,9 @@ data class Matrix( Matrix(a.toDouble(), b.toDouble(), c.toDouble(), d.toDouble(), tx.toDouble(), ty.toDouble()) operator fun invoke(m: Matrix, out: Matrix = Matrix()): Matrix = out.copyFrom(m) + + fun transformXf(a: Float, b: Float, c: Float, d: Float, tx: Float, ty: Float, px: Float, py: Float): Float = a * px + c * py + tx + fun transformYf(a: Float, b: Float, c: Float, d: Float, tx: Float, ty: Float, px: Float, py: Float): Float = d * py + b * px + ty } var af: Float @@ -73,13 +76,15 @@ data class Matrix( } } - fun setTo(a: Double, b: Double, c: Double, d: Double, tx: Double, ty: Double): Matrix = this.apply { + fun setTo(a: Double, b: Double, c: Double, d: Double, tx: Double, ty: Double): Matrix { this.a = a this.b = b this.c = c this.d = d this.tx = tx this.ty = ty + return this + } 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()) @@ -191,6 +196,7 @@ data class Matrix( fun deltaTransformY(x: Double, y: Double): Double = (x * b) + (y * d) fun identity() = setTo(1.0, 0.0, 0.0, 1.0, 0.0, 0.0) + fun setToNan() = setTo(Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN) fun isIdentity() = getType() == Type.IDENTITY @@ -332,8 +338,6 @@ data class Matrix( rectangle.height = ceil((if (y1 > y3) y1 else y3) - rectangle.y) } - - fun copyFromArray(value: FloatArray, offset: Int = 0): Matrix = setTo( value[offset + 0], value[offset + 1], value[offset + 2], value[offset + 3], value[offset + 4], value[offset + 5] diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/triangle/Triangle.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/triangle/Triangle.kt index 1884869..564ba60 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/triangle/Triangle.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/triangle/Triangle.kt @@ -207,7 +207,7 @@ fun Triangle.edgeIndex(p1: IPoint, p2: IPoint): Int { return -1 } -class TriangleList(val points: PointArrayList, val indices: IntArray, val numTriangles: Int = indices.size / 3) : Iterable { +class TriangleList(val points: PointArrayList, val indices: ShortArray, val numTriangles: Int = indices.size / 3) : Iterable { val numIndices get() = numTriangles * 3 val pointCount get() = points.size @@ -224,9 +224,9 @@ class TriangleList(val points: PointArrayList, val indices: IntArray, val numTri } fun getTriangle(index: Int, out: MutableTriangle = MutableTriangle()): MutableTriangle { - points.getPoint(indices[index * 3 + 0], out.p0) - points.getPoint(indices[index * 3 + 1], out.p1) - points.getPoint(indices[index * 3 + 2], out.p2) + points.getPoint(indices[index * 3 + 0].toInt() and 0xFFFF, out.p0) + points.getPoint(indices[index * 3 + 1].toInt() and 0xFFFF, out.p1) + points.getPoint(indices[index * 3 + 2].toInt() and 0xFFFF, out.p2) return out } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/interpolation/Interpolation.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/interpolation/Interpolation.kt index c69b3b5..8ad58db 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/interpolation/Interpolation.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/interpolation/Interpolation.kt @@ -1,5 +1,7 @@ package com.soywiz.korma.interpolation +import com.soywiz.kds.* + interface Interpolable { fun interpolateWith(ratio: Double, other: T): T } @@ -12,5 +14,5 @@ fun Double.interpolate(l: Float, r: Float): Float = (l + (r - l) * this).toFloat fun Double.interpolate(l: Double, r: Double): Double = (l + (r - l) * this) fun Double.interpolate(l: Int, r: Int): Int = (l + (r - l) * this).toInt() fun Double.interpolate(l: Long, r: Long): Long = (l + (r - l) * this).toLong() -fun Double.interpolate(l: Interpolable, r: Interpolable): T = l.interpolateWith(this, r as T) +fun Double.interpolate(l: Interpolable, r: Interpolable): T = l.interpolateWith(this, r.fastCastTo()) fun > Double.interpolate(l: T, r: T): T = l.interpolateWith(this, r) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/math/Math.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/math/Math.kt index 6179b17..131f6c7 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/math/Math.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/math/Math.kt @@ -64,3 +64,19 @@ fun Long.prevMultipleOf(multiple: Long) = if (this.isMultipleOf(multiple)) this fun Int.isMultipleOf(multiple: Int) = multiple == 0 || (this % multiple) == 0 fun Long.isMultipleOf(multiple: Long) = multiple == 0L || (this % multiple) == 0L + +fun min(a: Int, b: Int, c: Int) = min(min(a, b), c) +fun min(a: Float, b: Float, c: Float) = min(min(a, b), c) +fun min(a: Double, b: Double, c: Double) = min(min(a, b), c) + +fun min(a: Int, b: Int, c: Int, d: Int) = min(min(min(a, b), c), d) +fun min(a: Float, b: Float, c: Float, d: Float) = min(min(min(a, b), c), d) +fun min(a: Double, b: Double, c: Double, d: Double) = min(min(min(a, b), c), d) + +fun max(a: Int, b: Int, c: Int) = max(max(a, b), c) +fun max(a: Float, b: Float, c: Float) = max(max(a, b), c) +fun max(a: Double, b: Double, c: Double) = max(max(a, b), c) + +fun max(a: Int, b: Int, c: Int, d: Int) = max(max(max(a, b), c), d) +fun max(a: Float, b: Float, c: Float, d: Float) = max(max(max(a, b), c), d) +fun max(a: Double, b: Double, c: Double, d: Double) = max(max(max(a, b), c), d) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/triangle/EarCutTriangulator.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/triangle/EarCutTriangulator.kt index 07a0f83..e889f6d 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/triangle/EarCutTriangulator.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/triangle/EarCutTriangulator.kt @@ -15,7 +15,7 @@ object EarCutTriangulator { floats[n * 2 + 1] = points.getY(n).toFloat() } val result = EarCut.earcut(floats, holeIndices, 2) - return TriangleList(points, result.toIntArray()) + return TriangleList(points, result.toShortArray()) } } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/triangle/poly2tri/TriangulateExt.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/triangle/poly2tri/TriangulateExt.kt index 8108075..1e6ee8e 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/triangle/poly2tri/TriangulateExt.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/triangle/poly2tri/TriangulateExt.kt @@ -32,5 +32,5 @@ fun VectorPath.triangulateSafe(doClipper: Boolean = true): TriangleList { points.add(it.p1.x, it.p1.y) points.add(it.p2.x, it.p2.y) } - return TriangleList(points, indices.toIntArray()) + return TriangleList(points, indices.toShortArray()) } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/math/MathTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/math/MathTest.kt index caeb697..4ee2b6d 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/math/MathTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/math/MathTest.kt @@ -1,9 +1,24 @@ package com.soywiz.korma.math +import com.soywiz.kds.rotated import kotlin.math.E import kotlin.test.* class MathTest { + @Test + fun testMinMax34() { + for (n in 0 until 4) { + val list = listOf(1, 2, 3, 4).rotated(n) + assertEquals(1, min(list[0], list[1], list[2], list[3])) + assertEquals(4, max(list[0], list[1], list[2], list[3])) + } + for (n in 0 until 3) { + val list = listOf(1, 2, 3).rotated(n) + assertEquals(1, min(list[0], list[1], list[2])) + assertEquals(3, max(list[0], list[1], list[2])) + } + } + @Test fun testConvertRange() { assertEquals(300.0, 100.0.convertRange(50.0, 150.0, 200.0, 400.0))