diff --git a/differ/src/commonMain/kotlin/com/dropbox/differ/ImageComparator.kt b/differ/src/commonMain/kotlin/com/dropbox/differ/ImageComparator.kt index 8a0a750..06dbe2b 100644 --- a/differ/src/commonMain/kotlin/com/dropbox/differ/ImageComparator.kt +++ b/differ/src/commonMain/kotlin/com/dropbox/differ/ImageComparator.kt @@ -48,7 +48,7 @@ class SimpleImageComparator( (b..t).forEach { offsetY -> if (offsetX != x || offsetY != y) { // If we're out of bounds for either of the images, return false - if (x >= minOf(left.width, right.width) || y >= minOf(left.height, right.height)) return false + if (offsetX >= minOf(left.width, right.width) || offsetY >= minOf(left.height, right.height)) return false val c1 = left.getPixel(offsetX, offsetY) val localDeltaThreshold = color.distance(c1) diff --git a/differ/src/commonTest/kotlin/com/dropbox/differ/ShiftComparisonTest.kt b/differ/src/commonTest/kotlin/com/dropbox/differ/ShiftComparisonTest.kt index e1d480e..1ee6f7b 100644 --- a/differ/src/commonTest/kotlin/com/dropbox/differ/ShiftComparisonTest.kt +++ b/differ/src/commonTest/kotlin/com/dropbox/differ/ShiftComparisonTest.kt @@ -61,4 +61,14 @@ class ShiftComparisonTest { assertEquals(comparator.hShift, 0) assertEquals(comparator.vShift, 10) } + + @Test fun `returns DIFFERENT for different sized images`() { + val first = TestImage(width = 1080, height = 1080) + val second = TestImage(width = 1080, height = 540) + second.setPixel(second.width - 1, second.height - 1, Color(0f, 0f, 0f, 0f)) + + val comparator = SimpleImageComparator(hShift = 1, vShift = 1) + assertEquals(540 * 1080 + 1, comparator.compare(first, second).pixelDifferences) + assertEquals(540 * 1080, comparator.compare(second, first).pixelDifferences) + } }