Calculating the length of a line segment