yes my problem is that my pan sometimes get like this..

0.. 180.. -180.. 0 thats the range, so i have to convert..
if angle<0 add 360.. Ok now i have 0.. to 360 range degree..

Now, im in the 4th day that i work hard in many solution, but all them have some kind of fail point.

So im checking angle for all the 4^4 possibilities..
4 quadrants, and the 4 interactions between them.

i can post my code if it work.
But this is really a math big exercice.