quicker euclidian distance. calculating xy_distance now also takes into account toroidal grid distance