Skip to content

Commit

Permalink
Fixed ArrayTile equality bug
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Bouffard <jbouffard@azavea.com>

Updated the CHANGELOG

Signed-off-by: Jacob Bouffard <jbouffard@azavea.com>

Added Nan check to equality

Signed-off-by: Jacob Bouffard <jbouffard@azavea.com>
  • Loading branch information
Jacob Bouffard committed Jun 14, 2019
1 parent 603a253 commit 09472e5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Fixes & Updates
- Fix map{X|Y}ToGrid function behavior that could give a bit incorrect results (`#2953 <https://github.com/locationtech/geotrellis/pull/2953>`_).
- Fix COG layer update bug related to COGLayerMetadata zoomRanges ordering (`#2922 <https://github.com/locationtech/geotrellis/pull/2922>`_).
- Use original ZoomRanges on COG layer update (`#2956 <https://github.com/locationtech/geotrellis/pull/2956>`_).
- ArrayTile equality will now check the cols, rows, and cellType of the two tiles (`#2991 <https://github.com/locationtech/geotrellis/pull/2991>`_).

2.3.0
-----
Expand Down
28 changes: 20 additions & 8 deletions raster/src/main/scala/geotrellis/raster/ArrayTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,27 @@ trait ArrayTile extends Tile with Serializable {
* @return A boolean
*/
override def equals(other: Any): Boolean = other match {
case r: ArrayTile => {
if (r == null) return false
val len = size
if (len != r.size) return false
case tile: ArrayTile => {
if (tile == null) return false
if (tile.cols != cols || tile.rows != rows) return false
if (tile.cellType != cellType) return false

var i = 0
while (i < len) {
if (apply(i) != r(i)) return false
i += 1
}

if (cellType.isFloatingPoint)
while (i < size) {
val value = applyDouble(i)
val otherValue = tile.applyDouble(i)

if (value.isNaN && otherValue.isNaN) return true
if (value != otherValue) return false
i += 1
}
else
while (i < size) {
if (apply(i) != tile(i)) return false
i += 1
}
true
}
case _ => false
Expand Down
22 changes: 22 additions & 0 deletions raster/src/test/scala/geotrellis/raster/ArrayTileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,26 @@ class ArrayTileSpec extends FunSpec
}
}
}

describe("ArrayTile equality") {
val at = IntArrayTile(Array.ofDim[Int](4 * 4).fill(0), 4, 4)

it("should not equal an ArrayTile of different shape") {
val other = IntArrayTile(Array.ofDim[Int](2 * 8).fill(0), 2, 8)

assert(at != other)
}

it("should not equal an ArrayTile of different cellType") {
val other = ShortArrayTile(Array.ofDim[Short](4 * 4).fill(0), 4, 4)

assert(at != other)
}

it("should equal other ArrayTile") {
val other = IntArrayTile(Array.ofDim[Int](4 * 4).fill(0), 4, 4)

assert(at == other)
}
}
}

0 comments on commit 09472e5

Please sign in to comment.