getNearestRasterPosition = ({ x, y }, raster) => {

  const rasterHalf = raster / 2;

  // calculate distances to previous raster lines
  const distPrevX = mod(x, raster);
  const distPrevY = mod(y, raster);

  return {
    x: distPrevX < rasterHalf ? x - distPrevX : x - distPrevX + raster,
    y: distPrevY < rasterHalf ? y - distPrevY : y - distPrevY + raster
  };

}
Maps a coordinate to the nearest raster coordinate.

@param {number} x
@param {number} y
@param {number} raster
@return {{x: number, y: number}}