Move SSD drag rect normalization to typed Kotlin
ober
9a8e3160b3db0e9c38075407280d9c9083f22a05
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -427,7 +427,7 @@ (typed-kotlin-file "com/sfb/ssdreview/OcrGeometry.kt" (typed-library (com sfb ssdreview) - (export centerInside rectArea) + (export centerInside rectArea normalizeRect) (type Float32) (type FloatArray) (type Int32) @@ -453,7 +453,25 @@ (height (- (float-array-ref rect (int32 3)) (float-array-ref rect (int32 1))))) (* (if (< width (float32 0.0)) (float32 0.0) width) - (if (< height (float32 0.0)) (float32 0.0) height))))))) + (if (< height (float32 0.0)) (float32 0.0) height))))) + (def (normalizeRect (rect : FloatArray)) : FloatArray + (float-array + (if (< (float-array-ref rect (int32 0)) + (float-array-ref rect (int32 2))) + (float-array-ref rect (int32 0)) + (float-array-ref rect (int32 2))) + (if (< (float-array-ref rect (int32 1)) + (float-array-ref rect (int32 3))) + (float-array-ref rect (int32 1)) + (float-array-ref rect (int32 3))) + (if (> (float-array-ref rect (int32 0)) + (float-array-ref rect (int32 2))) + (float-array-ref rect (int32 0)) + (float-array-ref rect (int32 2))) + (if (> (float-array-ref rect (int32 1)) + (float-array-ref rect (int32 3))) + (float-array-ref rect (int32 1)) + (float-array-ref rect (int32 3))))))) (typed-kotlin-file "com/sfb/ssdreview/UiTextHelpers.kt" (typed-library (com sfb ssdreview) @@ -3530,7 +3548,7 @@ " private fun finishSelection() {" " val start = dragStart ?: return" " val end = dragEnd ?: return" - " val rect = normalize(floatArrayOf(start[0], start[1], end[0], end[1]))" + " val rect = normalizeRect(floatArrayOf(start[0], start[1], end[0], end[1]))" " dragStart = null" " dragEnd = null" " invalidate()" @@ -3658,7 +3676,7 @@ " private fun drawDrag(canvas: Canvas) {" " val start = dragStart ?: return" " val end = dragEnd ?: return" - " val rect = normalize(floatArrayOf(start[0], start[1], end[0], end[1]))" + " val rect = normalizeRect(floatArrayOf(start[0], start[1], end[0], end[1]))" " paint.style = Paint.Style.FILL" " paint.color = Color.argb(38, 37, 99, 235)" " canvas.drawRect(rect[0], rect[1], rect[2], rect[3], paint)" @@ -3773,12 +3791,6 @@ " }?.id" " }" "" - " private fun normalize(rect: FloatArray): FloatArray = floatArrayOf(" - " min(rect[0], rect[2])," - " min(rect[1], rect[3])," - " max(rect[0], rect[2])," - " max(rect[1], rect[3])" - " )" "}" )) (kotlin-file-lines "com/sfb/ssdreview/TruthStore.kt"