Fix deltx() for x < r->lx && r->lx < r->hx; likewise delty()

Bug couldn't bite, because callers pass only coordinates within the
interval.
This commit is contained in:
Markus Armbruster 2008-08-16 14:57:13 -04:00
parent 6830c80341
commit 42a8b315e5

View file

@ -189,26 +189,28 @@ radmap2(int owner,
pr("\n"); pr("\n");
} }
/*
* Return distance from left edge of R to X.
* Value is between 0 (inclusive) and WORLD_X (exclusive).
* X must be normalized.
*/
int int
deltx(struct range *r, coord x) deltx(struct range *r, coord x)
{ {
if (r->lx < r->hx)
return x - r->lx;
if (x >= r->lx) if (x >= r->lx)
return x - r->lx; return x - r->lx;
return x + WORLD_X - r->lx; return x + WORLD_X - r->lx;
} }
/*
* Return distance from top edge of R to Y.
* Value is between 0 (inclusive) and WORLD_Y (exclusive).
* Y must be normalized.
*/
int int
delty(struct range *r, coord y) delty(struct range *r, coord y)
{ {
if (r->ly < r->hy)
return y - r->ly;
if (y >= r->ly) if (y >= r->ly)
return y - r->ly; return y - r->ly;
return y + WORLD_Y - r->ly; return y + WORLD_Y - r->ly;
} }