diff --git a/gradle.properties b/gradle.properties index e3da301..e315bba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,15 +1,15 @@ # sytleguide kotlin.code.style=official -# Kotlin 1.4.30-RC: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin -easyPluginVersion=0.12.5 +# Kotlin 1.4.30: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin +easyPluginVersion=0.13.0 # version group=com.soywiz.korlibs.korma version=2.0.0-SNAPSHOT # korlibs -kdsVersion=2.0.5 +kdsVersion=2.0.6 # bintray location project.bintray.org=korlibs diff --git a/korma-shape/src/commonMain/kotlin/com.soywiz.korma.triangle/internal/Poly2Tri.kt b/korma-shape/src/commonMain/kotlin/com.soywiz.korma.triangle/internal/Poly2Tri.kt index 08e6eed..fddfdb3 100644 --- a/korma-shape/src/commonMain/kotlin/com.soywiz.korma.triangle/internal/Poly2Tri.kt +++ b/korma-shape/src/commonMain/kotlin/com.soywiz.korma.triangle/internal/Poly2Tri.kt @@ -42,6 +42,7 @@ entities. package com.soywiz.korma.triangle.internal +import com.soywiz.kds.* import com.soywiz.korma.geom.* import com.soywiz.korma.geom.triangle.* import kotlin.math.* @@ -855,7 +856,7 @@ internal data class PolyTriangle internal constructor( override var p1: IPoint, override var p2: IPoint ) : Triangle { - val neighbors: ArrayList = ArrayList(3).apply { add(null); add(null); add(null) } as ArrayList // Neighbor list + val neighbors: FastArrayList = FastArrayList(3).apply { add(null); add(null); add(null) } // Neighbor list var interior: Boolean = false // Has this triangle been marked as an interior triangle? val constrained_edge = BooleanArray(3) // Flags to determine if an edge is a Constrained edge val delaunay_edge = BooleanArray(3) // Flags to determine if an edge is a Delauney edge diff --git a/korma-shape/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/Clipper.kt b/korma-shape/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/Clipper.kt index 76e0975..7e48aa1 100644 --- a/korma-shape/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/Clipper.kt +++ b/korma-shape/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/Clipper.kt @@ -778,7 +778,7 @@ internal class ClipperOffset(private val miterLimit: Double = 2.0, private val a private fun doRound(j: Int, k: Int) { val a = atan2(inA, normals[k].x * normals[j].x + normals[k].y * normals[j].y) - val steps = kotlin.math.max(round(stepsPerRad * abs(a)).toInt(), 1) + val steps = max2(round(stepsPerRad * abs(a)).toInt(), 1) var x = normals[k].x var y = normals[k].y @@ -2826,19 +2826,19 @@ internal class DefaultClipper(initOptions: Int = 0) : ClipperBase(Clipper.PRESER ): Boolean { if (a1 < a2) { if (b1 < b2) { - Left[0] = kotlin.math.max(a1, b1) - Right[0] = kotlin.math.min(a2, b2) + Left[0] = max2(a1, b1) + Right[0] = min2(a2, b2) } else { - Left[0] = kotlin.math.max(a1, b2) - Right[0] = kotlin.math.min(a2, b1) + Left[0] = max2(a1, b2) + Right[0] = min2(a2, b1) } } else { if (b1 < b2) { - Left[0] = kotlin.math.max(a2, b1) - Right[0] = kotlin.math.min(a1, b2) + Left[0] = max2(a2, b1) + Right[0] = min2(a1, b2) } else { - Left[0] = kotlin.math.max(a2, b2) - Right[0] = kotlin.math.min(a1, b1) + Left[0] = max2(a2, b2) + Right[0] = min2(a1, b1) } } return Left[0] < Right[0] diff --git a/korma-shape/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/ClipperExt.kt b/korma-shape/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/ClipperExt.kt index df7ce4a..dc2bc48 100644 --- a/korma-shape/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/ClipperExt.kt +++ b/korma-shape/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/ClipperExt.kt @@ -15,10 +15,10 @@ internal fun Path.toShape2d(): Shape2d { val bl = this[(n + 3) % 4] if ((tl.x == bl.x) && (tr.x == br.x) && (tl.y == tr.y) && (bl.y == br.y)) { - val xmin = kotlin.math.min(tl.x, tr.x) - val xmax = kotlin.math.max(tl.x, tr.x) - val ymin = kotlin.math.min(tl.y, bl.y) - val ymax = kotlin.math.max(tl.y, bl.y) + val xmin = min2(tl.x, tr.x) + val xmax = max2(tl.x, tr.x) + val ymin = min2(tl.y, bl.y) + val ymax = max2(tl.y, bl.y) //println("($xmin,$ymin)-($xmax-$ymax) : $tl,$tr,$br,$bl") return Shape2d.Rectangle(xmin, ymin, xmax - xmin, ymax - ymin) } diff --git a/korma-shape/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/internal.kt b/korma-shape/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/internal.kt new file mode 100644 index 0000000..29ced53 --- /dev/null +++ b/korma-shape/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/internal.kt @@ -0,0 +1,10 @@ +package com.soywiz.korma.geom.shape.ops.internal + +@PublishedApi internal fun min2(a: Int, b: Int) = if (a < b) a else b +@PublishedApi internal fun max2(a: Int, b: Int) = if (a > b) a else b + +@PublishedApi internal fun min2(a: Float, b: Float) = if (a < b) a else b +@PublishedApi internal fun max2(a: Float, b: Float) = if (a > b) a else b + +@PublishedApi internal fun min2(a: Double, b: Double) = if (a < b) a else b +@PublishedApi internal fun max2(a: Double, b: Double) = if (a > b) a else b 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 562e02a..6419ea0 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt @@ -106,8 +106,8 @@ data class Rectangle( infix fun intersection(that: Rectangle) = intersection(that, Rectangle()) fun intersection(that: Rectangle, target: Rectangle = Rectangle()) = if (this intersects that) target.setBounds( - kotlin.math.max(this.left, that.left), kotlin.math.max(this.top, that.top), - kotlin.math.min(this.right, that.right), kotlin.math.min(this.bottom, that.bottom) + max2(this.left, that.left), max2(this.top, that.top), + min2(this.right, that.right), min2(this.bottom, that.bottom) ) else null fun displaced(dx: Double, dy: Double) = Rectangle(this.x + dx, this.y + dy, width, height) @@ -327,10 +327,10 @@ fun Iterable.bounds(target: Rectangle = Rectangle()): Rectangle { bottom = r.bottom first = false } else { - left = kotlin.math.min(left, r.left) - right = kotlin.math.max(right, r.right) - top = kotlin.math.min(top, r.top) - bottom = kotlin.math.max(bottom, r.bottom) + left = min2(left, r.left) + right = max2(right, r.right) + top = min2(top, r.top) + bottom = max2(bottom, r.bottom) } } return target.setBounds(left, top, right, bottom) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/ScaleMode.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/ScaleMode.kt index b8f7cbd..4fe6077 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/ScaleMode.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/ScaleMode.kt @@ -1,5 +1,7 @@ package com.soywiz.korma.geom +import com.soywiz.korma.internal.* +import com.soywiz.korma.internal.max2 import kotlin.native.concurrent.ThreadLocal class ScaleMode( @@ -27,14 +29,14 @@ class ScaleMode( val COVER = ScaleMode { c, iw, ih, cw, ch -> val s0 = cw / iw val s1 = ch / ih - val s = kotlin.math.max(s0, s1) + val s = max2(s0, s1) if (c == 0) iw * s else ih * s } val SHOW_ALL = ScaleMode { c, iw, ih, cw, ch -> val s0 = cw / iw val s1 = ch / ih - val s = kotlin.math.min(s0, s1) + val s = min2(s0, s1) if (c == 0) iw * s else ih * s } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Size.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Size.kt index 9c1f56f..06e3701 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Size.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Size.kt @@ -9,8 +9,8 @@ interface ISize { val area: Double get() = width * height val perimeter: Double get() = width * 2 + height * 2 - val min: Double get() = kotlin.math.min(width, height) - val max: Double get() = kotlin.math.max(width, height) + val min: Double get() = min2(width, height) + val max: Double get() = max2(width, height) companion object { operator fun invoke(width: Double, height: Double): ISize = Size(Point(width, height)) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/binpack/BinPacker.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/binpack/BinPacker.kt index 82ec854..25525b8 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/binpack/BinPacker.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/binpack/BinPacker.kt @@ -9,8 +9,8 @@ class BinPacker(val width: Double, val height: Double, val algo: Algo = MaxRects class Result(val maxWidth: Double, val maxHeight: Double, val items: List>) { private val rectanglesNotNull = items.map { it.second }.filterNotNull() - val width: Double = rectanglesNotNull.map { it.right }.max() ?: 0.0 - val height: Double = rectanglesNotNull.map { it.bottom }.max() ?: 0.0 + val width: Double = rectanglesNotNull.map { it.right }.maxOrNull() ?: 0.0 + val height: Double = rectanglesNotNull.map { it.bottom }.maxOrNull() ?: 0.0 val rects: List get() = items.map { it.second } val rectsStr: String get() = rects.toString() } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/Shape2d.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/Shape2d.kt index 0387145..4fb803c 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/Shape2d.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/Shape2d.kt @@ -178,7 +178,7 @@ inline fun approximateCurve( crossinline compute: (ratio: Double, get: (x: Double, y: Double) -> Unit) -> Unit, crossinline emit: (x: Double, y: Double) -> Unit ) { - val rcurveSteps = max(curveSteps, 20) + val rcurveSteps = max2(curveSteps, 20) val dt = 1.0 / rcurveSteps var lastX = 0.0 var lastY = 0.0 @@ -218,10 +218,10 @@ fun IPointArrayList.toRectangleOrNull(): Shape2d.Rectangle? { val ys = setOf(getY(0), getY(1), getY(2), getY(3)) if (xs.size != 2 || ys.size != 2) return null //get coordinates - val left = xs.min() ?: return null - val right = xs.max() ?: return null - val top = ys.max() ?: return null - val bottom = ys.min() ?: return null + val left = xs.minOrNull() ?: return null + val right = xs.maxOrNull() ?: return null + val top = ys.maxOrNull() ?: return null + val bottom = ys.minOrNull() ?: return null return Shape2d.Rectangle(Rectangle.fromBounds(top, left, right, bottom)) } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/Edge.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/Edge.kt index 233f08a..9521be0 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/Edge.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/Edge.kt @@ -98,17 +98,17 @@ class Edge { } fun setToHalf(a: Edge, b: Edge): Edge = this.apply { - val minY = min(a.minY, b.minY) - val maxY = min(a.maxY, b.maxY) + val minY = min2(a.minY, b.minY) + val maxY = min2(a.maxY, b.maxY) val minX = (a.intersectX(minY) + b.intersectX(minY)) / 2 val maxX = (a.intersectX(maxY) + b.intersectX(maxY)) / 2 setTo(minX, minY, maxX, maxY, +1) } - val minX get() = min(ax, bx) - val maxX get() = max(ax, bx) - val minY get() = min(ay, by) - val maxY get() = max(ay, by) + val minX get() = min2(ax, bx) + val maxX get() = max2(ax, bx) + val minY get() = min2(ay, by) + val maxY get() = max2(ay, by) @Suppress("ConvertTwoComparisonsToRangeCheck") //fun containsY(y: Int): Boolean = if (ay == by) y == ay else if (wind >= 0) y >= ay && y < by else y > ay && y <= by @@ -206,10 +206,10 @@ internal class LineSegment(ax: Double, ay: Double, bx: Double, by: Double) { } internal data class Line(val ax: Double, val ay: Double, val bx: Double, val by: Double) { - val minX get() = min(ax, bx) - val maxX get() = max(ax, bx) - val minY get() = min(ay, by) - val maxY get() = max(ay, by) + val minX get() = min2(ax, bx) + val maxX get() = max2(ax, bx) + val minY get() = min2(ay, by) + val maxY get() = max2(ay, by) val isCoplanarX get() = ay == by val isCoplanarY get() = ax == bx diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/VectorBuilder.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/VectorBuilder.kt index 60554c9..103abce 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/VectorBuilder.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/VectorBuilder.kt @@ -3,6 +3,8 @@ package com.soywiz.korma.geom.vector import com.soywiz.korma.annotations.KorDslMarker import com.soywiz.korma.geom.* import com.soywiz.korma.geom.bezier.* +import com.soywiz.korma.internal.* +import com.soywiz.korma.internal.min2 import kotlin.math.* @KorDslMarker @@ -96,7 +98,7 @@ fun VectorBuilder.arc(x: Double, y: Double, r: Double, start: Angle, end: Angle) val startAngle = start.radians % PI_TWO val endAngle = end.radians % PI_TWO - var remainingAngle = kotlin.math.min(PI_TWO, abs(endAngle - startAngle)) + var remainingAngle = min2(PI_TWO, abs(endAngle - startAngle)) if (remainingAngle == 0.0 && start != end) remainingAngle = PI_TWO val sgn = if (startAngle < endAngle) +1 else -1 var a1 = startAngle @@ -106,7 +108,7 @@ fun VectorBuilder.arc(x: Double, y: Double, r: Double, start: Angle, end: Angle) val p4 = Point() var index = 0 while (remainingAngle > EPSILON) { - val a2 = a1 + sgn * kotlin.math.min(remainingAngle, PI_OVER_TWO) + val a2 = a1 + sgn * min2(remainingAngle, PI_OVER_TWO) val k = 0.5522847498 val a = (a2 - a1) / 2.0 diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/internal/Internal.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/internal/Internal.kt index 7633bfe..352d759 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/internal/Internal.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/internal/Internal.kt @@ -16,3 +16,12 @@ internal infix fun Double.umod(other: Double): Double { @PublishedApi internal fun floorCeil(v: Double): Double = if (v < 0.0) ceil(v) else floor(v) + +@PublishedApi internal fun min2(a: Int, b: Int) = if (a < b) a else b +@PublishedApi internal fun max2(a: Int, b: Int) = if (a > b) a else b + +@PublishedApi internal fun min2(a: Float, b: Float) = if (a < b) a else b +@PublishedApi internal fun max2(a: Float, b: Float) = if (a > b) a else b + +@PublishedApi internal fun min2(a: Double, b: Double) = if (a < b) a else b +@PublishedApi internal fun max2(a: Double, b: Double) = if (a > b) a else b diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/math/ArrayExt.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/math/ArrayExt.kt index 30267d8..538841d 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/math/ArrayExt.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/math/ArrayExt.kt @@ -1,15 +1,18 @@ package com.soywiz.korma.math +import com.soywiz.korma.internal.* +import com.soywiz.korma.internal.max2 + fun DoubleArray.minOrElse(nil: Double): Double { if (isEmpty()) return nil var out = Double.POSITIVE_INFINITY - for (i in 0..lastIndex) out = kotlin.math.min(out, this[i]) + for (i in 0..lastIndex) out = min2(out, this[i]) return out } fun DoubleArray.maxOrElse(nil: Double): Double { if (isEmpty()) return nil var out = Double.NEGATIVE_INFINITY - for (i in 0..lastIndex) out = kotlin.math.max(out, this[i]) + for (i in 0..lastIndex) out = max2(out, this[i]) return out } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/random/RandomExt.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/random/RandomExt.kt index e14bb68..d118d01 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/random/RandomExt.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/random/RandomExt.kt @@ -50,7 +50,7 @@ data class RandomWeights(val weightsMap: Map) { companion object { private fun normalizeWeights(weights: List): List { - val min = weights.min() ?: 0.0 + val min = weights.minOrNull() ?: 0.0 return weights.map { (it + min) + 1 } } } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/segment/IntSegmentSet.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/segment/IntSegmentSet.kt index 69c1e7a..19899be 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/segment/IntSegmentSet.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/segment/IntSegmentSet.kt @@ -2,6 +2,8 @@ package com.soywiz.korma.segment import com.soywiz.kds.* import com.soywiz.korma.annotations.* +import com.soywiz.korma.internal.* +import com.soywiz.korma.internal.max2 /** * Non-overlapping SegmentSet @@ -90,8 +92,8 @@ class IntSegmentSet { fastForEachInterestingRange(min, max) { n, x1, x2 -> if (intersects(x1, x2, min, max)) { if (removeStart == -1) removeStart = n - this.min[removeStart] = kotlin.math.min(this.min.getAt(removeStart), kotlin.math.min(x1, min)) - this.max[removeStart] = kotlin.math.max(this.max.getAt(removeStart), kotlin.math.max(x2, max)) + this.min[removeStart] = min2(this.min.getAt(removeStart), min2(x1, min)) + this.max[removeStart] = max2(this.max.getAt(removeStart), max2(x2, max)) removeCount++ } } @@ -140,7 +142,7 @@ class IntSegmentSet { var count = 0 fastForEachInterestingRange(min, max) { n, x1, x2 -> if (intersects(x1, x2, min, max)) { - out(kotlin.math.max(x1, min), kotlin.math.min(x2, max)) + out(max2(x1, min), min2(x2, max)) count++ } } @@ -162,7 +164,7 @@ class IntSegmentSet { var count = 0 fastForEach { n, x1, x2 -> if (intersects(x1, x2, min, max)) { - out(kotlin.math.max(x1, min), kotlin.math.min(x2, max)) + out(max2(x1, min), min2(x2, max)) count++ } } @@ -207,7 +209,7 @@ class IntSegmentSet { // @TODO: In KDS latest versions @PublishedApi internal inline fun genericBinarySearchLeft(fromIndex: Int, toIndex: Int, check: (value: Int) -> Int): Int = - genericBinarySearch(fromIndex, toIndex, invalid = { from, to, low, high -> kotlin.math.min(low, high).coerceIn(from, to - 1) }, check = check) + genericBinarySearch(fromIndex, toIndex, invalid = { from, to, low, high -> min2(low, high).coerceIn(from, to - 1) }, check = check) @PublishedApi internal inline fun genericBinarySearchRight(fromIndex: Int, toIndex: Int, check: (value: Int) -> Int): Int = - genericBinarySearch(fromIndex, toIndex, invalid = { from, to, low, high -> kotlin.math.max(low, high).coerceIn(from, to - 1) }, check = check) + genericBinarySearch(fromIndex, toIndex, invalid = { from, to, low, high -> max2(low, high).coerceIn(from, to - 1) }, check = check)