dix: use single return statement in DoGetDirection
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Daniel Stone <daniel@fooishbar.org> Reviewed-by: Jamey Sharp <jamey@minilop.net> Reviewed-by: Simon Thum <simon.thum@gmx.de>
This commit is contained in:
parent
5f8edbe47e
commit
62f4bef82d
|
@ -453,54 +453,61 @@ enum directions {
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
DoGetDirection(int dx, int dy){
|
DoGetDirection(int dx, int dy){
|
||||||
float r;
|
int dir = 0;
|
||||||
int i1, i2;
|
|
||||||
/* on insignificant mickeys, flag 135 degrees */
|
/* on insignificant mickeys, flag 135 degrees */
|
||||||
if(abs(dx) < 2 && abs(dy) < 2){
|
if(abs(dx) < 2 && abs(dy) < 2){
|
||||||
/* first check diagonal cases */
|
/* first check diagonal cases */
|
||||||
if(dx > 0 && dy > 0)
|
if(dx > 0 && dy > 0)
|
||||||
return E | SE | S;
|
dir = E | SE | S;
|
||||||
if(dx > 0 && dy < 0)
|
else if(dx > 0 && dy < 0)
|
||||||
return N | NE | E;
|
dir = N | NE | E;
|
||||||
if(dx < 0 && dy < 0)
|
else if(dx < 0 && dy < 0)
|
||||||
return W | NW | N;
|
dir = W | NW | N;
|
||||||
if(dx < 0 && dy > 0)
|
else if(dx < 0 && dy > 0)
|
||||||
return W | SW | S;
|
dir = W | SW | S;
|
||||||
/* check axis-aligned directions */
|
/* check axis-aligned directions */
|
||||||
if(dx > 0)
|
else if(dx > 0)
|
||||||
return NE | E | SE;
|
dir = NE | E | SE;
|
||||||
if(dx < 0)
|
else if(dx < 0)
|
||||||
return NW | W | SW;
|
dir = NW | W | SW;
|
||||||
if(dy > 0)
|
else if(dy > 0)
|
||||||
return SE | S | SW;
|
dir = SE | S | SW;
|
||||||
if(dy < 0)
|
else if(dy < 0)
|
||||||
return NE | N | NW;
|
dir = NE | N | NW;
|
||||||
return UNDEFINED; /* shouldn't happen */
|
else
|
||||||
}
|
dir = UNDEFINED; /* shouldn't happen */
|
||||||
/* else, compute angle and set appropriate flags */
|
} else { /* compute angle and set appropriate flags */
|
||||||
|
float r;
|
||||||
|
int i1, i2;
|
||||||
|
|
||||||
#ifdef _ISOC99_SOURCE
|
#ifdef _ISOC99_SOURCE
|
||||||
r = atan2f(dy, dx);
|
r = atan2f(dy, dx);
|
||||||
#else
|
#else
|
||||||
r = atan2(dy, dx);
|
r = atan2(dy, dx);
|
||||||
#endif
|
#endif
|
||||||
/* find direction.
|
/* find direction.
|
||||||
*
|
*
|
||||||
* Add 360° to avoid r become negative since C has no well-defined
|
* 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,
|
* modulo for such cases. Then divide by 45° to get the octant
|
||||||
* e.g. 0 <= r <= 1 is [0-45]°
|
* number, e.g.
|
||||||
* 1 <= r <= 2 is [45-90]°
|
* 0 <= r <= 1 is [0-45]°
|
||||||
* etc.
|
* 1 <= r <= 2 is [45-90]°
|
||||||
* But we add extra 90° to match up with our N, S, etc. defines up
|
* etc.
|
||||||
* there, rest stays the same.
|
* 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 each),
|
r = (r+(M_PI*2.5))/(M_PI/4);
|
||||||
* except on very well-aligned mickeys. */
|
/* this intends to flag 2 directions (45 degrees),
|
||||||
i1 = (int)(r+0.1) % 8;
|
* except on very well-aligned mickeys. */
|
||||||
i2 = (int)(r+0.9) % 8;
|
i1 = (int)(r+0.1) % 8;
|
||||||
if(i1 < 0 || i1 > 7 || i2 < 0 || i2 > 7)
|
i2 = (int)(r+0.9) % 8;
|
||||||
return UNDEFINED; /* shouldn't happen */
|
if(i1 < 0 || i1 > 7 || i2 < 0 || i2 > 7)
|
||||||
return 1 << i1 | 1 << i2;
|
dir = UNDEFINED; /* shouldn't happen */
|
||||||
|
else
|
||||||
|
dir = (1 << i1 | 1 << i2);
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DIRECTION_CACHE_RANGE 5
|
#define DIRECTION_CACHE_RANGE 5
|
||||||
|
|
Loading…
Reference in New Issue