distance calculation over torus