Added function to find shortest path in a torus.