1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include "distance.h"
int process_right (int from_row, int to_row, int start_col, int first_zone)
{
register int i,col,cur_zone;
register MAPTYPE *to_ptr, *from_ptr;
register int ncols;
register int xcol;
register int incr;
register int farthest;
/* find cells to the right
* stop at right edge, or when ncols is bigger than the last zone,
* or when we see a 1 in the map
*/
xcol = col = start_col;
from_ptr = map + MAPINDEX(from_row, col);
to_ptr = map + MAPINDEX(to_row, col);
farthest = distances[ndist-1].ncols;
/* planimetric grids will look for ncols^2
* and can use fact that (n+1)^2 = n^2 + 2n + 1
*/
if (window.proj != PROJECTION_LL)
incr = 1;
else
incr = 0;
ncols = 0;
while(1)
{
if (col >= window.cols-1)
{ /* global wrap-around */
if (!wrap_ncols) return window.cols;
col = -1;
ncols += wrap_ncols-1;
from_ptr = map + MAPINDEX(from_row, -1);
to_ptr = map + MAPINDEX(to_row, -1);
}
col++;
xcol++;
if (*++from_ptr == 1) break;
if (incr)
{
ncols += incr;
incr += 2;
}
else
ncols++;
if(ncols > farthest) break;
/* convert 1,2,3,4 to -1,0,1,2 etc. 0 becomes ndist */
if(cur_zone = *++to_ptr)
cur_zone -= ZONE_INCR;
else
cur_zone = ndist;
/* find the first zone that is closer than the current value */
for (i = first_zone; i < cur_zone; i++)
{
if (distances[i].ncols >= ncols)
{
*to_ptr = (first_zone=i) + ZONE_INCR;
break;
}
}
}
while (xcol <= maxcol && *from_ptr++ != 1)
xcol++;
return xcol;
}
|