Added a boundary-aware getter to grid.js (not yet used).
Cleaner way to handle border cases, if it's not too slow.