Avoid undefined behavior when points are very close

@jbeezley please try this branch with your code and let me know if at-least the precision issue is fixed. The problem was related to precision issue as we thought and in GL is the the second term of atan is smaller than precision, then it leads to undefined behavior. 

I will be interested to see if this affects the performance or not.