Bug#392774: wormux: blocks the whole X session when GNU touches the
first object
Steinar H. Gunderson
sgunderson at bigfoot.com
Sun Nov 12 20:10:22 CET 2006
On Sun, Nov 12, 2006 at 03:11:44AM +0200, Tuukka Hastrup wrote:
> - while(angle < -M_PI) angle += M_PI;
> - while(angle > M_PI) angle -= M_PI;
> + angle = fmod(angle, M_PI);
This patch is simply wrong.
What you want to do is to reduce the argument to [-pi, pi> (or <-pi, pi] if
you want, it doesn't matter which side is inclusive), so you can represent
the entire unit circle. In particular, you want pi+a (where a is a small
positive number) to be reduced to (-pi)+a; your version reduces it to a.
The issue gets meddled a bit by the fact that fmod(x, y) reduces x to be in
the range <-y, y> (not [0, y> as one might expect), in a perhaps not entirely
intuitive way (in general, fmod(-x, y) = -fmod(x, y) for positive x and y).
So what you want is something more along the lines of
angle = fmod(angle, 2.0*M_PI); // [0, 2pi> or <-2pi, 0], depending on
// sign of ANGLE
if (angle < 0.0)
angle += 2.0*M_PI; // [0, 2pi>
if (angle >= M_PI)
angle -= 2.0*M_PI; // [-pi, pi>
Untested, though, and you might want to change the "< 0.0" to "< -M_PI" to
avoid stuff like -pi/2 to be moved up to the positive side and then back
again.
/* Steinar */
--
Homepage: http://www.sesse.net/
More information about the Pkg-games-devel
mailing list