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

Commit

Permalink
2.0.0-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Oct 9, 2020
1 parent 47f0a0a commit 5656ff6
Show file tree
Hide file tree
Showing 40 changed files with 1,077 additions and 1,414 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
}

dependencies {
classpath("com.soywiz.korlibs:easy-kotlin-mpp-gradle-plugin:0.9.3") // Kotlin 1.3.72: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin
classpath("com.soywiz.korlibs:easy-kotlin-mpp-gradle-plugin:0.10.3") // Kotlin 1.4.10: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin
}
}

Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ kotlin.code.style=official

# version
group=com.soywiz.korlibs.korma
version=1.11.18-SNAPSHOT
version=2.0.0-SNAPSHOT

# korlibs
kdsVersion=1.10.12
kdsVersion=2.0.0-alpha

# bintray location
project.bintray.org=korlibs
Expand All @@ -23,4 +23,4 @@ project.license.url=https://raw.githubusercontent.com/korlibs/korma/master/LICEN
# gradle
org.gradle.jvmargs=-Xmx3g
kotlin.incremental.multiplatform=true
kotlin.native.ignoreDisabledTargets=true
kotlin.native.ignoreDisabledTargets=true
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-6.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
9 changes: 4 additions & 5 deletions korma/src/commonMain/kotlin/com/soywiz/korma/algo/AStar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.soywiz.korma.algo

import com.soywiz.kds.*
import com.soywiz.korma.geom.*
import com.soywiz.korma.math.*

class AStar(val width: Int, val height: Int, val isBlocking: (x: Int, y: Int) -> Boolean) {
companion object {
Expand All @@ -24,7 +23,7 @@ class AStar(val width: Int, val height: Int, val isBlocking: (x: Int, y: Int) ->
// Reset
queue.clear()
for (n in weights.indices) weights[n] = Int.MAX_VALUE
for (n in prev.indices) prev[n] = NULL.index
for (n in prev.indices) prev[n] = NIL.index

val first = getNode(x0, y0)
val dest = getNode(x1, y1)
Expand Down Expand Up @@ -54,19 +53,19 @@ class AStar(val width: Int, val height: Int, val isBlocking: (x: Int, y: Int) ->

if (findClosest || closest == dest) {
var current: AStarNode = closest
while (current != NULL) {
while (current != NIL) {
emit(current.posX, current.posY)
current = current.prev
}
}
}

private val NULL = AStarNode(-1)
private val NIL = AStarNode(-1)

private val posX = IntArray(width * height) { it % width }
private val posY = IntArray(width * height) { it / width }
private val weights = IntArray(width * height) { Int.MAX_VALUE }
private val prev = IntArray(width * height) { NULL.index }
private val prev = IntArray(width * height) { NIL.index }
private val queue = IntPriorityQueue { a, b -> AStarNode(a).weight - AStarNode(b).weight }

private fun inside(x: Int, y: Int): Boolean = (x in 0 until width) && (y in 0 until height)
Expand Down
3 changes: 0 additions & 3 deletions korma/src/commonMain/kotlin/com/soywiz/korma/geom/Anchor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ data class Anchor(val sx: Double, val sy: Double) : Interpolable<Anchor> {
operator fun invoke(sx: Int, sy: Int) = Anchor(sx.toDouble(), sy.toDouble())
operator fun invoke(sx: Float, sy: Float) = Anchor(sx.toDouble(), sy.toDouble())

@Deprecated("Kotlin/Native boxes inline + Number")
inline operator fun invoke(sx: Number, sy: Number) = Anchor(sx.toDouble(), sy.toDouble())

val TOP_LEFT = Anchor(0.0, 0.0)
val TOP_CENTER = Anchor(0.5, 0.0)
val TOP_RIGHT = Anchor(1.0, 0.0)
Expand Down
23 changes: 5 additions & 18 deletions korma/src/commonMain/kotlin/com/soywiz/korma/geom/Angle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ inline class Angle(val radians: Double) : Comparable<Angle> {
fun fromRadians(radians: Int) = fromRadians(radians.toDouble())
fun fromDegrees(degrees: Int) = fromDegrees(degrees.toDouble())

@Deprecated("Kotlin/Native boxes Number in inline")
inline fun fromRadians(radians: Number) = fromRadians(radians.toDouble())
@Deprecated("Kotlin/Native boxes Number in inline")
inline fun fromDegrees(degrees: Number) = fromDegrees(degrees.toDouble())

internal const val PI2 = PI * 2

internal const val DEG2RAD = PI / 180.0
Expand Down Expand Up @@ -67,8 +62,8 @@ inline class Angle(val radians: Double) : Comparable<Angle> {
return if (angle < 0) Angle(angle + PI2) else Angle(angle)
}

@Deprecated("Kotlin/Native boxes Number in inline")
inline fun between(x0: Number, y0: Number, x1: Number, y1: Number): Angle = between(x0.toDouble(), y0.toDouble(), x1.toDouble(), y1.toDouble())
fun between(x0: Int, y0: Int, x1: Int, y1: Int): Angle = between(x0.toDouble(), y0.toDouble(), x1.toDouble(), y1.toDouble())
fun between(x0: Float, y0: Float, x1: Float, y1: Float): Angle = between(x0.toDouble(), y0.toDouble(), x1.toDouble(), y1.toDouble())

fun between(p0: IPoint, p1: IPoint): Angle = between(p0.x, p0.y, p1.x, p1.y)
}
Expand All @@ -79,6 +74,7 @@ inline class Angle(val radians: Double) : Comparable<Angle> {
inline fun cos(angle: Angle): Double = kotlin.math.cos(angle.radians)
inline fun sin(angle: Angle): Double = kotlin.math.sin(angle.radians)
inline fun tan(angle: Angle): Double = kotlin.math.tan(angle.radians)
inline fun abs(angle: Angle): Angle = Angle.fromRadians(angle.radians.absoluteValue)

val Angle.cosine get() = cos(this)
val Angle.sine get() = sin(this)
Expand All @@ -91,15 +87,11 @@ fun Angle.longDistanceTo(other: Angle): Angle = Angle.longDistanceTo(this, other

operator fun Angle.times(scale: Double): Angle = Angle(this.radians * scale)
operator fun Angle.div(scale: Double): Angle = Angle(this.radians / scale)

operator fun Angle.times(scale: Float): Angle = this * scale.toDouble()
operator fun Angle.div(scale: Float): Angle = this / scale.toDouble()
operator fun Angle.times(scale: Int): Angle = this * scale.toDouble()
operator fun Angle.div(scale: Int): Angle = this / scale.toDouble()

@Deprecated("Kotlin/Native boxes Number in inline")
inline operator fun Angle.times(scale: Number): Angle = this * scale.toDouble()
@Deprecated("Kotlin/Native boxes Number in inline")
inline operator fun Angle.div(scale: Number): Angle = this / scale.toDouble()

operator fun Angle.div(other: Angle): Double = this.radians / other.radians // Ratio
operator fun Angle.plus(other: Angle): Angle = Angle(this.radians + other.radians)
operator fun Angle.minus(other: Angle): Angle = Angle(this.radians - other.radians)
Expand Down Expand Up @@ -134,11 +126,6 @@ val Int.radians get() = Angle.fromRadians(this)
val Float.degrees get() = Angle.fromDegrees(this)
val Float.radians get() = Angle.fromRadians(this)

@Deprecated("Kotlin/Native boxes Number in inline")
inline val Number.degrees get() = Angle.fromDegrees(this)
@Deprecated("Kotlin/Native boxes Number in inline")
inline val Number.radians get() = Angle.fromRadians(this)

val Angle.normalized get() = Angle(radians umod Angle.MAX_RADIANS)

fun Double.interpolate(l: Angle, r: Angle): Angle = this.interpolate(l.radians, r.radians).radians
76 changes: 45 additions & 31 deletions korma/src/commonMain/kotlin/com/soywiz/korma/geom/BoundsBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,56 @@ class BoundsBuilder {
}

fun add(x: Double, y: Double): BoundsBuilder {
xmin = kotlin.math.min(xmin, x)
xmax = kotlin.math.max(xmax, x)
ymin = kotlin.math.min(ymin, y)
ymax = kotlin.math.max(ymax, y)
if (x < xmin) xmin = x
if (x > xmax) xmax = x
if (y < ymin) ymin = y
if (y > ymax) ymax = y
npoints++
//println("add($x, $y) -> ($xmin,$ymin)-($xmax,$ymax)")
return this
}

fun add(x: Double, y: Double, transform :Matrix): BoundsBuilder =
add(transform.transformX(x, y), transform.transformY(x, y))
fun add(x: Int, y: Int): BoundsBuilder = add(x.toDouble(), y.toDouble())
fun add(x: Float, y: Float): BoundsBuilder = add(x.toDouble(), y.toDouble())

fun add(x: Double, y: Double, transform: Matrix): BoundsBuilder = add(transform.transformX(x, y), transform.transformY(x, y))
fun add(x: Int, y: Int, transform: Matrix): BoundsBuilder = add(x.toDouble(), y.toDouble(), transform)
fun add(x: Float, y: Float, transform: Matrix): BoundsBuilder = add(x.toDouble(), y.toDouble(), transform)

fun add(point: IPoint): BoundsBuilder = add(point.x, point.y)
fun add(point: IPoint, transform: Matrix): BoundsBuilder = add(point.x, point.y, transform)

fun add(ps: Iterable<IPoint>): BoundsBuilder {
for (p in ps) add(p)
return this
}
fun add(ps: IPointArrayList): BoundsBuilder {
for (n in 0 until ps.size) add(ps.getX(n), ps.getY(n))
return this
}
fun add(rect: Rectangle): BoundsBuilder {
if (rect.isNotEmpty) {
add(rect.left, rect.top)
add(rect.right, rect.bottom)
}
return this
}

fun add(ps: Iterable<IPoint>, transform: Matrix): BoundsBuilder {
for (p in ps) add(p, transform)
return this
}
fun add(ps: IPointArrayList, transform: Matrix): BoundsBuilder {
for (n in 0 until ps.size) add(ps.getX(n), ps.getY(n), transform)
return this
}
fun add(rect: Rectangle, transform: Matrix): BoundsBuilder {
if (rect.isNotEmpty) {
add(rect.left, rect.top, transform)
add(rect.right, rect.bottom, transform)
}
return this
}

fun getBoundsOrNull(out: Rectangle = Rectangle()): Rectangle? = if (npoints == 0) null else out.setBounds(xmin, ymin, xmax, ymax)

Expand All @@ -47,28 +86,3 @@ class BoundsBuilder {
return out
}
}

fun BoundsBuilder.add(x: Int, y: Int) = add(x.toDouble(), y.toDouble())

@Deprecated("Kotlin/Native boxes Number in inline")
inline fun BoundsBuilder.add(x: Number, y: Number) = add(x.toDouble(), y.toDouble())

fun BoundsBuilder.add(p: IPoint) = add(p.x, p.y)
fun BoundsBuilder.add(ps: Iterable<IPoint>) = this.apply { for (p in ps) add(p) }
fun BoundsBuilder.add(ps: IPointArrayList) = run { for (n in 0 until ps.size) add(ps.getX(n), ps.getY(n)) }
fun BoundsBuilder.add(rect: Rectangle) = this.apply {
if (rect.isNotEmpty) {
add(rect.left, rect.top)
add(rect.right, rect.bottom)
}
}

fun BoundsBuilder.add(p: IPoint, transform: Matrix) = add(p.x, p.y, transform)
fun BoundsBuilder.add(ps: Iterable<IPoint>, transform: Matrix) = this.apply { for (p in ps) add(p, transform) }
fun BoundsBuilder.add(ps: IPointArrayList, transform: Matrix) = run { for (n in 0 until ps.size) add(ps.getX(n), ps.getY(n), transform) }
fun BoundsBuilder.add(rect: Rectangle, transform: Matrix) = this.apply {
if (rect.isNotEmpty) {
add(rect.left, rect.top, transform)
add(rect.right, rect.bottom, transform)
}
}
42 changes: 42 additions & 0 deletions korma/src/commonMain/kotlin/com/soywiz/korma/geom/EulerRotation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.soywiz.korma.geom

data class EulerRotation(
var x: Angle = 0.degrees,
var y: Angle = 0.degrees,
var z: Angle = 0.degrees
) {
companion object {
fun toQuaternion(roll: Angle, pitch: Angle, yaw: Angle, out: Quaternion = Quaternion()): Quaternion {
val cr = cos(roll * 0.5)
val sr = sin(roll * 0.5)
val cp = cos(pitch * 0.5)
val sp = sin(pitch * 0.5)
val cy = cos(yaw * 0.5)
val sy = sin(yaw * 0.5)
return out.setTo(
(cy * cp * sr - sy * sp * cr),
(sy * cp * sr + cy * sp * cr),
(sy * cp * cr - cy * sp * sr),
(cy * cp * cr + sy * sp * sr)
)
}
fun toQuaternion(euler: EulerRotation, out: Quaternion = Quaternion()): Quaternion = toQuaternion(euler.x, euler.y, euler.z, out)
}

fun toQuaternion(out: Quaternion = Quaternion()): Quaternion = toQuaternion(this, out)

fun setQuaternion(x: Double, y: Double, z: Double, w: Double): EulerRotation = Quaternion.toEuler(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), this)
fun setQuaternion(x: Int, y: Int, z: Int, w: Int): EulerRotation = Quaternion.toEuler(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), this)
fun setQuaternion(x: Float, y: Float, z: Float, w: Float): EulerRotation = Quaternion.toEuler(x, y, z, w, this)

fun setQuaternion(quaternion: Quaternion): EulerRotation = Quaternion.toEuler(quaternion.x, quaternion.y, quaternion.z, quaternion.w, this)
fun setTo(x: Angle, y: Angle, z: Angle): EulerRotation = this
.apply { this.x = x }
.apply { this.y = y }
.apply { this.z = z }

fun setTo(other: EulerRotation): EulerRotation = setTo(other.x, other.y, other.z)

private val tempQuat: Quaternion by lazy { Quaternion() }
fun toMatrix(out: Matrix3D = Matrix3D()): Matrix3D = tempQuat.setEuler(this).toMatrix(out)
}
Loading

0 comments on commit 5656ff6

Please sign in to comment.