Calculation of line segment length