Grid: fixed overflow

because the rows and cols was int16_t, and location was encoded as the
row and col of the origin of the world coords, we would have overflow
issues for grids far from origin.

solved by:
- storing origin as coords of first cell
- using int for rows and cols

Also removed duplicated code, and added a test