Calculate line lengths