+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;
+ }
+}
+