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 + Kotlin 1.4.30-RC
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jan 24, 2021
1 parent 7662fb5 commit fe85172
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 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.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
Expand Down
15 changes: 10 additions & 5 deletions korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rectangle>, Interpolable<Rectangle>, 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
Expand Down Expand Up @@ -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() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
15 changes: 15 additions & 0 deletions korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit fe85172

Please sign in to comment.