Simplify code for live analysis
This commit is contained in:
@@ -47,16 +47,18 @@ data class Quad(
|
||||
Line(bottomLeft, topLeft))
|
||||
}
|
||||
|
||||
fun rotate90(iterations: Int, imageWidth: Int, imageHeight: Int): Quad {
|
||||
fun rotate90(iterations: Int, imageSize: ImageSize): Quad {
|
||||
val rotatedPoints = listOf(
|
||||
rotate90(topLeft, imageWidth, imageHeight, iterations),
|
||||
rotate90(topRight, imageWidth, imageHeight, iterations),
|
||||
rotate90(bottomRight, imageWidth, imageHeight, iterations),
|
||||
rotate90(bottomLeft, imageWidth, imageHeight, iterations)
|
||||
rotate90(topLeft, imageSize, iterations),
|
||||
rotate90(topRight, imageSize, iterations),
|
||||
rotate90(bottomRight, imageSize, iterations),
|
||||
rotate90(bottomLeft, imageSize, iterations)
|
||||
)
|
||||
return createQuad(rotatedPoints)
|
||||
}
|
||||
private fun rotate90(p: Point, width: Int, height: Int, iterations: Int): Point {
|
||||
private fun rotate90(p: Point, imageSize: ImageSize, iterations: Int): Point {
|
||||
val width = imageSize.width
|
||||
val height = imageSize.height
|
||||
return when (iterations % 4) {
|
||||
1 -> Point(height - p.y, p.x) // 90°
|
||||
2 -> Point(width - p.x, height - p.y) // 180°
|
||||
|
||||
@@ -40,21 +40,21 @@ class GeometryTest {
|
||||
fun rotateQuad() {
|
||||
val quad = createQuad(listOf(
|
||||
Point(1,2), Point(10, 3), Point(11,12), Point(3, 9)))
|
||||
assertThat(quad.rotate90(1, 100, 50)).isEqualTo(
|
||||
assertThat(quad.rotate90(1, ImageSize(100, 50))).isEqualTo(
|
||||
createQuad(listOf(
|
||||
Point(48,1), Point(47, 10), Point(38,11), Point(41, 3)
|
||||
)))
|
||||
assertThat(quad.rotate90(2, 100, 50)).isEqualTo(
|
||||
assertThat(quad.rotate90(2, ImageSize(100, 50))).isEqualTo(
|
||||
createQuad(listOf(
|
||||
Point(99,48), Point(90, 47), Point(89,38), Point(97, 41)
|
||||
)))
|
||||
assertThat(quad.rotate90(3, 100, 50)).isEqualTo(
|
||||
assertThat(quad.rotate90(3, ImageSize(100, 50))).isEqualTo(
|
||||
createQuad(listOf(
|
||||
Point(2,99), Point(3, 90), Point(12,89), Point(9, 97)
|
||||
)))
|
||||
assertThat(quad.rotate90(4, 100, 50)).isEqualTo(quad)
|
||||
assertThat(quad.rotate90(5, 100, 50)).isEqualTo(
|
||||
quad.rotate90(1, 100, 50)
|
||||
assertThat(quad.rotate90(4, ImageSize(100, 50))).isEqualTo(quad)
|
||||
assertThat(quad.rotate90(5, ImageSize(100, 50)))
|
||||
.isEqualTo(quad.rotate90(1, ImageSize(100, 50))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user