File: Graph_Clse.c

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (166 lines) | stat: -rw-r--r-- 4,121 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * Close down the graphics processing.  This gets called only at driver
 * termination time.
 */


#include "htmlmap.h"
#include "gis.h"
#include "driverlib.h"

/* sreen dimensions defined in Graph_Set.c */
extern int screen_top;
extern int screen_left;
extern int screen_right;
extern int screen_bottom;


/* point in polygon test by Randolph Franklin */
/* http://www.ecse.rpi.edu/Homepages/wrf/     */
/* adapted for integer coordinates            */

static int pnpoly (int npol, int *xp, int *yp, int x, int y)
{
  int i, j, c = 0;
  for (i = 0, j = npol-1; i < npol; j = i++) {
    if ((((yp[i] <= y) && (y < yp[j])) ||
         ((yp[j] <= y) && (y < yp[i]))) &&
        (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
      c = !c;
  }
  return c;
}



int 
Graph_Close (void)
{
     struct MapPoly *poly, *test_poly;

     int i;
     int inside;

    /* 
     * exmaine the list of polygons, if a polygon wholly exists inside of
     * another polygon, then remove it.
     *
     */

    for (poly = head; poly != NULL; poly = poly->next_poly) {

        for (test_poly = head; test_poly != NULL; 
					test_poly = test_poly->next_poly) {
            if (poly == test_poly) {
                continue;	/* don't check ourselves */
            }
             
            inside = 1;
            for (i = 0; i < poly->num_pts && inside; i++) {
                inside = pnpoly(test_poly->num_pts, 
                                  test_poly->x_pts, test_poly->y_pts, 
                                  poly->x_pts[i],   poly->y_pts[i]);
            }
            if (inside) {
                poly->num_pts = 0;	/* mark polygon as having no points */
                break;
            }
        }

    }


    /*
     * write any beginning prologue appropriate for the map type
     */
    
    switch (html_type) {

      case APACHE:
        fprintf(output,"#base _base_\n#default _default_\n");
        break;

      case RAW:
        break;

      case CLIENT:
        fprintf(output,"<MAP NAME=\"map\">\n");
        break;
    }

    /*
     * write the polygons in a specific format
     */

    for (poly = head; poly != NULL; poly = poly->next_poly) {
        if (poly->num_pts >= 3) {

            switch (html_type) {

              case APACHE:
                fprintf(output,"poly %s", poly->url);
                for (i = 0; i < poly->num_pts; i++) {
                    fprintf(output," %d,%d", poly->x_pts[i], poly->y_pts[i]);
                }
                fprintf(output," %d,%d", poly->x_pts[0], poly->y_pts[0]);
                fprintf(output,"\n");
                break;

              case RAW:
                fprintf(output,"%s", poly->url);
                for (i = 0; i < poly->num_pts; i++) {
                    fprintf(output," %d %d", poly->x_pts[i], poly->y_pts[i]);
                }
                fprintf(output," %d %d", poly->x_pts[0], poly->y_pts[0]);
                fprintf(output,"\n");
                break;

              case CLIENT:
                fprintf(output,
                "<AREA SHAPE=\"POLY\"\n HREF=\"%s\"\n  ALT=\"%s\"\n  COORDS=\"",
			poly->url, poly->url);
                for (i = 0; i < poly->num_pts; i++) {
                    if (i > 0) fprintf(output,", ");
                    /* 
		     * don't add newlines, which confuses the weak-minded
		     * i.e., ms internet exploder :-(
 		     * was: if (i % 8 == 0 && i != 0) fprintf(output,"\n  ");
		     */ 
                    fprintf(output,"%d,%d", poly->x_pts[i], poly->y_pts[i]);
                }
                fprintf(output,", %d,%d", poly->x_pts[0], poly->y_pts[0]);
                fprintf(output,"\">\n");
                break;

            }

        } 

    }

    /* final stuff, if needed */

    switch (html_type) {

      case APACHE:
        break;

      case RAW:
        break;

      case CLIENT:
	fprintf(output,"<AREA SHAPE=\"RECT\" NOHREF COORDS=\"%d,%d %d,%d\">\n",
		screen_left, screen_top, screen_right, screen_bottom);
	fprintf(output,"</MAP>\n");
        break;

    }

    /*
     * close file 
     */

    fclose(output);

	return 0;
}