Calculating the distance of edges