Coordinates to index convertion