- int distance, direction;
- distance = h[(i+1) % npoints] - h[i];
- direction = (distance >= 0 ? -1 : 1);
-
- if (distance > 180)
- distance = 180 - (distance - 180);
- else if (distance < -180)
- distance = -(180 - ((-distance) - 180));
- else
- direction = -direction;
+ int distance = h[(i+1) % npoints] - h[i];
+ int direction = (distance >= 0 ? -1 : 1);
+
+ if (distance <= 180 && distance >= -180)
+ direction = -direction;