On Wed, Apr 20, 2011 at 11:26:54AM -0700, Jamey Sharp wrote: > This code mixes spaces and tabs, which you might consider making > consistent as long as you're changing almost every line of the function > anyway.
I'll fix it up, thanks > Also, it isn't obvious to me why you're so excited about using a single > return statement in several of these patches. :-) I think I got a bit overexcited :) But debugging code is a lot simpler when there's only one line to put a printf in or break point on, not several. Cheers, Peter > On Wed, Apr 20, 2011 at 04:28:17PM +1000, Peter Hutterer wrote: > > Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net> > > --- > > dix/ptrveloc.c | 87 > > ++++++++++++++++++++++++++++++------------------------- > > 1 files changed, 47 insertions(+), 40 deletions(-) > > > > diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c > > index c23d513..12c4067 100644 > > --- a/dix/ptrveloc.c > > +++ b/dix/ptrveloc.c > > @@ -453,54 +453,61 @@ enum directions { > > */ > > static int > > DoGetDirection(int dx, int dy){ > > - float r; > > - int i1, i2; > > + int dir = 0; > > + > > /* on insignificant mickeys, flag 135 degrees */ > > if(abs(dx) < 2 && abs(dy) < 2){ > > /* first check diagonal cases */ > > if(dx > 0 && dy > 0) > > - return E | SE | S; > > - if(dx > 0 && dy < 0) > > - return N | NE | E; > > - if(dx < 0 && dy < 0) > > - return W | NW | N; > > - if(dx < 0 && dy > 0) > > - return W | SW | S; > > + dir = E | SE | S; > > + else if(dx > 0 && dy < 0) > > + dir = N | NE | E; > > + else if(dx < 0 && dy < 0) > > + dir = W | NW | N; > > + else if(dx < 0 && dy > 0) > > + dir = W | SW | S; > > /* check axis-aligned directions */ > > - if(dx > 0) > > - return NE | E | SE; > > - if(dx < 0) > > - return NW | W | SW; > > - if(dy > 0) > > - return SE | S | SW; > > - if(dy < 0) > > - return NE | N | NW; > > - return UNDEFINED; /* shouldn't happen */ > > - } > > - /* else, compute angle and set appropriate flags */ > > + else if(dx > 0) > > + dir = NE | E | SE; > > + else if(dx < 0) > > + dir = NW | W | SW; > > + else if(dy > 0) > > + dir = SE | S | SW; > > + else if(dy < 0) > > + dir = NE | N | NW; > > + else > > + dir = UNDEFINED; /* shouldn't happen */ > > + } else { /* compute angle and set appropriate flags */ > > + float r; > > + int i1, i2; > > + > > #ifdef _ISOC99_SOURCE > > - r = atan2f(dy, dx); > > + r = atan2f(dy, dx); > > #else > > - r = atan2(dy, dx); > > + r = atan2(dy, dx); > > #endif > > - /* find direction. > > - * > > - * Add 360° to avoid r become negative since C has no well-defined > > - * modulo for such cases. Then divide by 45° to get the octant number, > > - * e.g. 0 <= r <= 1 is [0-45]° > > - * 1 <= r <= 2 is [45-90]° > > - * etc. > > - * But we add extra 90° to match up with our N, S, etc. defines up > > - * there, rest stays the same. > > - */ > > - r = (r+(M_PI*2.5))/(M_PI/4); > > - /* this intends to flag 2 directions (45 degrees), > > - * except on very well-aligned mickeys. */ > > - i1 = (int)(r+0.1) % 8; > > - i2 = (int)(r+0.9) % 8; > > - if(i1 < 0 || i1 > 7 || i2 < 0 || i2 > 7) > > - return UNDEFINED; /* shouldn't happen */ > > - return 1 << i1 | 1 << i2; > > + /* find direction. > > + * > > + * Add 360° to avoid r become negative since C has no well-defined > > + * modulo for such cases. Then divide by 45° to get the octant > > + * number, e.g. > > + * 0 <= r <= 1 is [0-45]° > > + * 1 <= r <= 2 is [45-90]° > > + * etc. > > + * But we add extra 90° to match up with our N, S, etc. defines up > > + * there, rest stays the same. > > + */ > > + r = (r+(M_PI*2.5))/(M_PI/4); > > + /* this intends to flag 2 directions (45 degrees), > > + * except on very well-aligned mickeys. */ > > + i1 = (int)(r+0.1) % 8; > > + i2 = (int)(r+0.9) % 8; > > + if(i1 < 0 || i1 > 7 || i2 < 0 || i2 > 7) > > + dir = UNDEFINED; /* shouldn't happen */ > > + else > > + dir = (1 << i1 | 1 << i2); > > + } > > + return dir; > > } > > > > #define DIRECTION_CACHE_RANGE 5 > > -- > > 1.7.4.4 > > > > _______________________________________________ > > xorg-devel@lists.x.org: X.Org development > > Archives: http://lists.x.org/archives/xorg-devel > > Info: http://lists.x.org/mailman/listinfo/xorg-devel _______________________________________________ xorg-devel@lists.x.org: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel