[AD] [ alleg-Bugs-1858078 ] Bug in arc function

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Bugs item #1858078, was opened at 2007-12-25 17:00
Message generated for change (Settings changed) made by mmimica
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105665&aid=1858078&group_id=5665

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core Library
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Private: No
Submitted By: 8L45T3R (o8l45t3ro)
Assigned to: Nobody/Anonymous (nobody)
Summary: Bug in arc function

Initial Comment:
I found bug in arc function:

    arc(screen, 100, 100, itofix(-1), itofix(32), 30, makecol(128, 128, 128));
    arc(screen, 100, 100, itofix(-1), itofix(32), 20, makecol(128, 128, 128));

Although the only difference is in radius, second call draws whole circle instead just arc from -1 to 32.

Error is actually in function "do_arc" (helper function for the arc function).

When "do_arc" calls "get_point_on_arc(r, ang1, &sx, &sy);", due to small radius and angle near the zero,
variable sy became 0 (instead of small negative value) which later leads to wrong quadrant.

Solution for this precission problem is to calculate quadrant in "get_point_on_arc" function with double 
precision values.

So, new function will look like this:

static INLINE void get_point_on_arc_q(int r, fixed_8L a, int *out_x, int *out_y, int *out_q)
{
    double s, c;
    double double_a = a * (AL_PI * 2 / (1 << 24));
    c =  r * cos(double_a);
    s = -r * sin(double_a);
    *out_x = (int)((c < 0) ? (c - 0.5) : (c + 0.5));
    *out_y = (int)((s < 0) ? (s - 0.5) : (s + 0.5));
    
    if (c >= 0) {
        if (s <= 0)
            *out_q = 0;
        else
            *out_q = 3;
    }
    else {
        if (s <= 0)
            *out_q = 1;
        else
            *out_q = 2;
    }
}

And of course, in "do_arc" function should be removed quadrant calculation.


I also rewrotte (and test) the whole "do_arc" function, so you can use my implementation instead of old one.


----------------------------------------------------------------------

Comment By: Milan Mimica (mmimica)
Date: 2007-12-26 11:19

Message:
Logged In: YES 
user_id=1171214
Originator: NO

Hi!
Thanks for the fix. I'm am going to apply it to the 4.3.10plus branch on
SVN. I just need to know under what name to credit you. 8L45T3R?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105665&aid=1858078&group_id=5665




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/