From fe85172e5f362406a22afd6f4a3efa5bca38feee Mon Sep 17 00:00:00 2001 From: soywiz Date: Sun, 24 Jan 2021 21:55:14 +0100 Subject: [PATCH] Sync from next + Kotlin 1.4.30-RC --- gradle.properties | 6 +++--- .../kotlin/com/soywiz/korma/geom/Rectangle.kt | 15 ++++++++++----- .../com/soywiz/korma/geom/RectangleIntTest.kt | 15 +++++++++++++++ .../kotlin/com/soywiz/korma/geom/RectangleTest.kt | 15 +++++++++++++++ 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/gradle.properties b/gradle.properties index d01ab6b..e3da301 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,15 +1,15 @@ # sytleguide kotlin.code.style=official -# Kotlin 1.4.21: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin -easyPluginVersion=0.12.3 +# Kotlin 1.4.30-RC: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin +easyPluginVersion=0.12.5 # version group=com.soywiz.korlibs.korma version=2.0.0-SNAPSHOT # korlibs -kdsVersion=2.0.3 +kdsVersion=2.0.5 # bintray location project.bintray.org=korlibs 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 73b4f64..562e02a 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt @@ -26,15 +26,15 @@ val IRectangle.top get() = _y val IRectangle.right get() = _x + _width val IRectangle.bottom get() = _y + _height +val IRectangle.topLeft get() = Point(left, top) +val IRectangle.topRight get() = Point(right, top) +val IRectangle.bottomLeft get() = Point(left, bottom) +val IRectangle.bottomRight get() = Point(right, bottom) + data class Rectangle( var x: Double, var y: Double, var width: Double, var height: Double ) : MutableInterpolable, Interpolable, IRectangle, Sizeable { - val topLeft get() = Point(left, top) - val topRight get() = Point(right, top) - val bottomLeft get() = Point(left, bottom) - val bottomRight get() = Point(right, bottom) - override val _x: Double get() = x override val _y: Double get() = y override val _width: Double get() = width @@ -208,6 +208,11 @@ val IRectangleInt.top get() = y val IRectangleInt.right get() = x + width val IRectangleInt.bottom get() = y + height +val IRectangleInt.topLeft get() = PointInt(left, top) +val IRectangleInt.topRight get() = PointInt(right, top) +val IRectangleInt.bottomLeft get() = PointInt(left, bottom) +val IRectangleInt.bottomRight get() = PointInt(right, bottom) + inline class RectangleInt(val rect: Rectangle) : IRectangleInt { override var x: Int set(value) = run { rect.x = value.toDouble() } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleIntTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleIntTest.kt index 07e82a1..3a5c1f1 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleIntTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleIntTest.kt @@ -9,4 +9,19 @@ class RectangleIntTest { assertEquals(SizeInt(25, 100), SizeInt(50, 200).fitTo(container = SizeInt(100, 100))) assertEquals(SizeInt(50, 200), SizeInt(50, 200).fitTo(container = SizeInt(100, 200))) } + + @Test + fun corners() { + val rectangle = RectangleInt(1, 20, 300, 4000) + assertEquals(IPointInt(1, 20), rectangle.topLeft) + assertEquals(IPointInt(301, 20), rectangle.topRight) + assertEquals(IPointInt(1, 4020), rectangle.bottomLeft) + assertEquals(IPointInt(301, 4020), rectangle.bottomRight) + + val iRectangle = IRectangleInt(1000, 200, 30, 4) + assertEquals(IPointInt(1000, 200), iRectangle.topLeft) + assertEquals(IPointInt(1030, 200), iRectangle.topRight) + assertEquals(IPointInt(1000, 204), iRectangle.bottomLeft) + assertEquals(IPointInt(1030, 204), iRectangle.bottomRight) + } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleTest.kt index 9ba8b89..9436560 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleTest.kt @@ -36,4 +36,19 @@ class RectangleTest { val out = Rectangle(0, 0, 100, 100).place(Size(50, 25), Anchor.MIDDLE_CENTER, ScaleMode.SHOW_ALL) assertEquals(Rectangle(0, 25, 100, 50), out) } + + @Test + fun corners() { + val rectangle = Rectangle(1, 20, 300, 4000) + assertEquals(IPoint(1, 20), rectangle.topLeft) + assertEquals(IPoint(301, 20), rectangle.topRight) + assertEquals(IPoint(1, 4020), rectangle.bottomLeft) + assertEquals(IPoint(301, 4020), rectangle.bottomRight) + + val iRectangle = IRectangle(1000, 200, 30, 4) + assertEquals(IPoint(1000, 200), iRectangle.topLeft) + assertEquals(IPoint(1030, 200), iRectangle.topRight) + assertEquals(IPoint(1000, 204), iRectangle.bottomLeft) + assertEquals(IPoint(1030, 204), iRectangle.bottomRight) + } }