Correct conditional to correctly treat segments which end on a boundary.