Handle horizontal lines properly in Line.getSignedDistance()

Closes #546.
Some code clean-up.