Refactoring: move "norm" to Geometry.kt and add test
This commit is contained in:
@@ -25,7 +25,6 @@ import org.opencv.core.Size
|
|||||||
import org.opencv.imgproc.Imgproc
|
import org.opencv.imgproc.Imgproc
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.sqrt
|
|
||||||
|
|
||||||
fun detectDocumentQuad(mask: Bitmap, minQuadAreaRatio: Double = 0.02): Quad? {
|
fun detectDocumentQuad(mask: Bitmap, minQuadAreaRatio: Double = 0.02): Quad? {
|
||||||
val mat = Mat()
|
val mat = Mat()
|
||||||
@@ -143,8 +142,3 @@ fun Point.toCv(): org.opencv.core.Point {
|
|||||||
return org.opencv.core.Point(x.toDouble(), y.toDouble())
|
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)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -15,10 +15,21 @@
|
|||||||
package org.mydomain.myscan
|
package org.mydomain.myscan
|
||||||
|
|
||||||
import kotlin.math.atan2
|
import kotlin.math.atan2
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
data class Point(val x: Int, val y: Int)
|
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(
|
data class Quad(
|
||||||
val topLeft: Point,
|
val topLeft: Point,
|
||||||
|
|||||||
27
app/src/test/java/org/mydomain/myscan/GeometryTest.kt
Normal file
27
app/src/test/java/org/mydomain/myscan/GeometryTest.kt
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 Pierre-Yves Nicolas
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the Free
|
||||||
|
* Software Foundation, either version 3 of the License, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.mydomain.myscan
|
||||||
|
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class GeometryTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun line() {
|
||||||
|
assertThat(Line(Point(0, 0), Point(10, 0)).norm()).isEqualTo(10.0)
|
||||||
|
assertThat(Line(Point(1, 2), Point(4, 6)).norm()).isEqualTo(5.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user