Given the function:
void Arc::SetAngles(double startAngle, double endAngle) {
while(endAngle > (startAngle + 359.0)) endAngle -= 1.0;
while(startAngle > 360.0) startAngle -= 360.0;
while(startAngle < -360.0) startAngle += 360.0;
while(endAngle > 360.0) endAngle -= 360.0;
while(endAngle < -360.0) endAngle += 360.0;
_startAngle = DegreeToRadian(startAngle);
_endAngle = DegreeToRadian(endAngle);
}
Is there an algebraic solution to those while loops? It just looks…ugly. (Not to mention…slow.)
In C or C++ you’d use
fmodto get rid of some of your loops. Instead of this:Do this:
Don’t use the normal modulus operator (
%) as that’s for integers and won’t do the right thing with floating point values.Your first loop:
Can be replaced with just this:
But I think you should rethink that part of your algorithm: there’s no point in comparing the angles before you normalize them to the [0,360) interval.