Refactoring: move "norm" to Geometry.kt and add test

This commit is contained in:
Pierre-Yves Nicolas
2025-07-01 21:25:26 +02:00
parent 5e0cf451ea
commit 5a98f9f5e6
3 changed files with 39 additions and 7 deletions

View File

@@ -25,7 +25,6 @@ import org.opencv.core.Size
import org.opencv.imgproc.Imgproc
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.sqrt
fun detectDocumentQuad(mask: Bitmap, minQuadAreaRatio: Double = 0.02): Quad? {
val mat = Mat()
@@ -143,8 +142,3 @@ fun Point.toCv(): org.opencv.core.Point {
return org.opencv.core.Point(x.toDouble(), y.toDouble())
}
private fun norm(p1: Point, p2: Point): Double {
val dx = (p2.x - p1.x)
val dy = (p2.y - p1.y)
return sqrt(dx.toDouble() * dx + dy * dy)
}

View File

@@ -15,10 +15,21 @@
package org.mydomain.myscan
import kotlin.math.atan2
import kotlin.math.sqrt
data class Point(val x: Int, val y: Int)
data class Line(val from: Point, val to: Point)
data class Line(val from: Point, val to: Point) {
fun norm(): Double {
return norm(from, to)
}
}
fun norm(p1: Point, p2: Point): Double {
val dx = (p2.x - p1.x)
val dy = (p2.y - p1.y)
return sqrt(dx.toDouble() * dx + dy * dy)
}
data class Quad(
val topLeft: Point,