[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] BUG: Detecting rotation at multiples of 90
hi,
indeed, this seems to be the case. Thanks!
Committed revision 1396.
cheers,
Here's a C test case I used to test it....
--- testbla.c ---
int test_bla(float angle) {
//if (!(((int) angle) % 90)) {
if ( !( fmodf(angle, 90.0f) ) ) {
return 1;
} else {
return 0;
}
}
int main()
{
float angle;
printf("0==%d\n", test_bla(89.9f));
printf("1==%d\n", test_bla(90.0f));
printf("0==%d\n", test_bla(90.0001f));
printf("0==%d\n", test_bla(90.1f));
printf("0==%d\n", test_bla(90.9f));
printf("0==%d\n", test_bla(92.0f));
printf("1==%d\n", test_bla(180.0f));
printf("1==%d\n", test_bla(270.0f));
printf("1==%d\n", test_bla(360.0f));
return 0;
}
gcc testbla.c -lm && ./a.out
0==0
1==1
0==0
0==0
0==0
0==0
1==1
1==1
1==1
On Tue, Jun 10, 2008 at 6:11 PM, Marcus von Appen <mva@xxxxxxxxxxxx> wrote:
> On, Tue Jun 10, 2008, Charlie Nolan wrote:
>
>> transform.c, 574..586
>> if (!(((int) angle) % 90))
>> {
>> # (snip) Exact rotation for angles that are multiples of 90.
>> }
>>
>> There's a subtle bug here, in that casting to int will eliminate the
>> full-precision rotation on every range (90*x, 90*x + 1). My C-fu is a
>> bit weak, but I think that can be fixed by changing the if statement
>> to:
>> if ( !( angle % 90.0f ) )
>
> fmodf() or fmod() would be better as % is (to my knowledge) not clearly
> defined for floating point types in the C standard. Besides that, I
> would agree :-).
>
> Regards
> Marcus
>