36 lines
1.2 KiB
Kotlin
36 lines
1.2 KiB
Kotlin
package com.qft.optical
|
|
|
|
import org.junit.Assert.assertTrue
|
|
import org.junit.Test
|
|
|
|
class LockRectTest {
|
|
@Test fun finderPointsProduceBoundedSquareRoi() {
|
|
val lock = LockRect.fromPoints(
|
|
listOf(300f to 180f, 660f to 180f, 300f to 540f),
|
|
960,
|
|
720,
|
|
) ?: error("lock missing")
|
|
assertTrue(lock.width == lock.height)
|
|
assertTrue(lock.left >= 0 && lock.top >= 0)
|
|
assertTrue(lock.right <= 960 && lock.bottom <= 720)
|
|
assertTrue(lock.areaFraction(960, 720) < 0.36f)
|
|
}
|
|
|
|
@Test fun missesCanExpandRoiWithoutLeavingFrame() {
|
|
val base = LockRect(250, 100, 420, 420)
|
|
val expanded = base.expand(960, 540, 1.35f)
|
|
assertTrue(expanded.width >= base.width)
|
|
assertTrue(expanded.left >= 0 && expanded.top >= 0)
|
|
assertTrue(expanded.right <= 960 && expanded.bottom <= 540)
|
|
}
|
|
|
|
@Test fun smoothingReducesLockJitter() {
|
|
val a = LockRect(100, 100, 300, 300)
|
|
val b = LockRect(140, 130, 340, 340)
|
|
val smoothed = a.smoothToward(b, 0.25f)
|
|
assertTrue(smoothed.left in 101..139)
|
|
assertTrue(smoothed.top in 101..129)
|
|
assertTrue(smoothed.width in 301..339)
|
|
}
|
|
}
|