1
2 /****** path_finder.c ***********************************************
3
4 This recursive function traces the least cost path backwards
5 to cells from which the cumulative cost was determined
6
7 *********************************************************************/
8 #include <grass/segment.h>
9 #include "local_proto.h"
10
11
path_finder(int row,int col,int backrow,int backcol)12 void path_finder(int row, int col, int backrow, int backcol)
13 {
14 int data, new_backrow, new_backcol;
15 extern char *value;
16 extern int nrows, ncols;
17 extern SEGMENT in_row_seg, in_col_seg, out_seg;
18
19 if (row < 0 || row >= nrows || col < 0 || col >= ncols)
20 return; /* outside the window */
21
22 /* if the pt has already been traversed, return */
23 value = (char *)&data;
24 Segment_get(&out_seg, value, row, col);
25 if (data == 1)
26 return; /* already traversed */
27
28 /* otherwise, draw a line on output */
29 drawline(row, col, backrow, backcol);
30 /*DEBUG
31 printf("\nrow=%d, col=%d, backrow=%d, backcol=%d", row, col, backrow, backcol);
32 */
33 /* update path position */
34 if (row == backrow && col == backcol) {
35 printf("\n");
36 return;
37 } /* reach an origin */
38
39 value = (char *)&new_backrow;
40 Segment_get(&in_row_seg, value, backrow, backcol);
41 value = (char *)&new_backcol;
42 Segment_get(&in_col_seg, value, backrow, backcol);
43
44 path_finder(backrow, backcol, new_backrow, new_backcol);
45 return;
46 }
47