Sorting Coordinates in Polar Order for Graham Scan

Instead of Math.atan(y/x) try Math.atan2(y,x):

atan( 0/1 ) = 0
atan( 0/-1 ) = -0

atan2( 0, 1 ) = 0
atan2( 0, -1) = pi

Reference:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2

1 Like