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

Commit

Permalink
Prepare for 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Nov 23, 2020
1 parent 83a7b5e commit 684dee8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 19 additions & 2 deletions korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -480,3 +496,4 @@ data class Matrix(

override fun toString(): String = "Matrix(a=$a, b=$b, c=$c, d=$d, tx=$tx, ty=$ty)"
}

14 changes: 14 additions & 0 deletions korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) =
Expand Down

0 comments on commit 684dee8

Please sign in to comment.