Ok, why did you ignore the advice that you didn't include the bound y<=x? You didn't, so you angular limits are wrong. For another thing, arctan(tan(t)) is not necessarily t. tan(5*pi/4)=1. arctan(1)=pi/4. You'll have to split along quadrants as well.