implement snapToGrid() method for polygons