From: Markus Armbruster Date: Fri, 8 Apr 2011 18:38:03 +0000 (+0200) Subject: Move xysize_range(), xydist_range() to xy.c and xy.h X-Git-Tag: v4.3.27~63 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=40b6032a5d14fe40ff83237399debedf8adc7352 Move xysize_range(), xydist_range() to xy.c and xy.h Moved from snxtsct.c and prototypes.h next to the other struct range functions. --- diff --git a/include/prototypes.h b/include/prototypes.h index 1dc4a1601..98140ec3f 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -648,8 +648,6 @@ extern void snxtitem_cargo(struct nstr_item *, int, int, int); /* snxtsct.c */ extern int snxtsct(struct nstr_sect *, char *); extern void snxtsct_area(struct nstr_sect *, struct range *); -extern void xydist_range(coord, coord, int, struct range *); -extern void xysize_range(struct range *); extern void snxtsct_all(struct nstr_sect *); extern void snxtsct_rewind(struct nstr_sect *); extern void snxtsct_dist(struct nstr_sect *, coord, coord, int); diff --git a/include/xy.h b/include/xy.h index e8fcffb65..838ccc8f0 100644 --- a/include/xy.h +++ b/include/xy.h @@ -60,6 +60,8 @@ extern void xyrelrange(struct natstr *np, struct range *src, struct range *dst); extern void xyabsrange(struct natstr *np, struct range *src, struct range *dst); +extern void xydist_range(coord, coord, int, struct range *); +extern void xysize_range(struct range *); extern coord strtox(char *str, char **end); extern coord strtoy(char *str, char **end); extern coord xabs(struct natstr *np, coord relx); diff --git a/src/lib/common/xy.c b/src/lib/common/xy.c index d4d3d2717..fc01b38e9 100644 --- a/src/lib/common/xy.c +++ b/src/lib/common/xy.c @@ -107,6 +107,47 @@ xyabsrange(struct natstr *np, struct range *src, struct range *dst) dst->height = src->height; } +void +xysize_range(struct range *rp) +{ + if (rp->lx > rp->hx) + rp->width = WORLD_X + rp->hx + 1 - rp->lx; + else + rp->width = rp->hx + 1 - rp->lx; + if (CANT_HAPPEN(rp->width > WORLD_X)) + rp->width = WORLD_X; + if (rp->ly > rp->hy) + rp->height = WORLD_Y + rp->hy + 1 - rp->ly; + else + rp->height = rp->hy + 1 - rp->ly; + if (CANT_HAPPEN(rp->height > WORLD_Y)) + rp->height = WORLD_Y; +} + +void +xydist_range(coord x, coord y, int dist, struct range *rp) +{ + if (4 * dist + 1 < WORLD_X) { + rp->lx = xnorm(x - 2 * dist); + rp->hx = xnorm(x + 2 * dist); + rp->width = 4 * dist + 1; + } else { + rp->lx = xnorm(x - WORLD_X / 2); + rp->hx = xnorm(rp->lx + WORLD_X - 1); + rp->width = WORLD_X; + } + + if (2 * dist + 1 < WORLD_Y) { + rp->ly = ynorm(y - dist); + rp->hy = ynorm(y + dist); + rp->height = 2 * dist + 1; + } else { + rp->ly = ynorm(y - WORLD_Y / 2); + rp->hy = ynorm(rp->ly + WORLD_Y - 1); + rp->height = WORLD_Y; + } +} + /* * Convert initial part of STR to normalized x-coordinate. * Return -1 on error. This works, as normalized coordinates are diff --git a/src/lib/subs/snxtsct.c b/src/lib/subs/snxtsct.c index 67504ef73..9bb76dec1 100644 --- a/src/lib/subs/snxtsct.c +++ b/src/lib/subs/snxtsct.c @@ -150,44 +150,3 @@ snxtsct_dist(struct nstr_sect *np, coord cx, coord cy, int dist) np->dx = -1; np->dy = 0; } - -void -xysize_range(struct range *rp) -{ - if (rp->lx > rp->hx) - rp->width = WORLD_X + rp->hx + 1 - rp->lx; - else - rp->width = rp->hx + 1 - rp->lx; - if (CANT_HAPPEN(rp->width > WORLD_X)) - rp->width = WORLD_X; - if (rp->ly > rp->hy) - rp->height = WORLD_Y + rp->hy + 1 - rp->ly; - else - rp->height = rp->hy + 1 - rp->ly; - if (CANT_HAPPEN(rp->height > WORLD_Y)) - rp->height = WORLD_Y; -} - -void -xydist_range(coord x, coord y, int dist, struct range *rp) -{ - if (4 * dist + 1 < WORLD_X) { - rp->lx = xnorm(x - 2 * dist); - rp->hx = xnorm(x + 2 * dist); - rp->width = 4 * dist + 1; - } else { - rp->lx = xnorm(x - WORLD_X / 2); - rp->hx = xnorm(rp->lx + WORLD_X - 1); - rp->width = WORLD_X; - } - - if (2 * dist + 1 < WORLD_Y) { - rp->ly = ynorm(y - dist); - rp->hy = ynorm(y + dist); - rp->height = 2 * dist + 1; - } else { - rp->ly = ynorm(y - WORLD_Y / 2); - rp->hy = ynorm(rp->ly + WORLD_Y - 1); - rp->height = WORLD_Y; - } -}