Fix the bug in calculate the line length