Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Sync from next
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jul 10, 2021
1 parent f2f4e98 commit debcfb1
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ case "`uname`" in
Darwin* )
darwin=true
;;
MINGW* )
MSYS* | MINGW* )
msys=true
;;
NONSTOP* )
Expand Down
10 changes: 7 additions & 3 deletions korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Triangle> {
class TriangleList(val points: PointArrayList, val indices: ShortArray, val numTriangles: Int = indices.size / 3) : Iterable<Triangle> {
val numIndices get() = numTriangles * 3
val pointCount get() = points.size

Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.soywiz.korma.interpolation

import com.soywiz.kds.*

interface Interpolable<T> {
fun interpolateWith(ratio: Double, other: T): T
}
Expand All @@ -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 <T> Double.interpolate(l: Interpolable<T>, r: Interpolable<T>): T = l.interpolateWith(this, r as T)
fun <T> Double.interpolate(l: Interpolable<T>, r: Interpolable<T>): T = l.interpolateWith(this, r.fastCastTo<T>())
fun <T : Interpolable<T>> Double.interpolate(l: T, r: T): T = l.interpolateWith(this, r)
16 changes: 16 additions & 0 deletions korma/src/commonMain/kotlin/com/soywiz/korma/math/Math.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
15 changes: 15 additions & 0 deletions korma/src/commonTest/kotlin/com/soywiz/korma/math/MathTest.kt
Original file line number Diff line number Diff line change
@@ -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))
Expand Down

0 comments on commit debcfb1

Please sign in to comment.