Improved handling of numerical stability issues

The current solution is still somewhat approximate. I will make another
pass on line rendering in GL once I have more time