segment distance calculation fix