If coordinates surpass the edge of the raster, loop around.
Adding distance function; refactoring functions to always use (y,x) points for consistency.