Skip to content

Commit

Permalink
Merge pull request #2060 from jpolchlo/fix/map-key-transform
Browse files Browse the repository at this point in the history
Allow MapKeyTransform to deal with points north and west of extent
  • Loading branch information
lossyrob authored Mar 13, 2017
2 parents c163476 + 47f52b7 commit e6bb6fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class MapKeyTransform(val extent: Extent, val layoutCols: Int, val layoutRows: I
val trow =
((extent.ymax - y) / extent.height) * layoutRows

(tcol.toInt, trow.toInt)
(tcol.floor.toInt, trow.floor.toInt)
}

def apply[K: SpatialComponent](key: K): Extent = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,12 @@ class MapKeyTransformSpec extends FunSpec with Matchers {
assert(mp(Extent(0,0,0,0)) === GridBounds(0, 2, 0, 2))
assert(mp(Extent(0,0,2,0)) === GridBounds(0, 2, 1, 2))
}

it("should properly handle points north or west of the extent bounds") {
val mp = MapKeyTransform(Extent(0.0, 0.0, 1.0, 1.0), 2, 2)
assert(mp(Point(0.0, 1.0)) == SpatialKey(0, 0))
assert(mp(Point(-0.1, 1.0)) == SpatialKey(-1, 0))
assert(mp(Point(0.0, 1.1)) == SpatialKey(0, -1))
}
}
}

0 comments on commit e6bb6fc

Please sign in to comment.