19 #include <grass/gis.h>
20 #include <grass/Vect.h>
21 #include <grass/glocale.h>
67 struct ilist *List_ref,
int type,
struct Map_info *Err)
69 struct line_pnts *APoints, *BPoints, *Points;
70 struct line_pnts **AXLines, **BXLines;
71 struct line_cats *ACats, *BCats, *Cats;
72 int j, k, l, ret, atype, btype, aline, bline, found, iline, nlines;
73 int naxlines, nbxlines, nx;
78 int touch1_n = 0, touch1_s = 0, touch1_e = 0, touch1_w = 0;
79 int touch2_n = 0, touch2_s = 0, touch2_e = 0, touch2_w = 0;
81 int node, anode1, anode2, bnode1, bnode2;
95 nlines = List_break->n_values;
100 G_debug(3,
"nlines = %d", nlines);
115 for (iline = 0; iline < nlines; iline++) {
118 aline = List_break->value[iline];
127 G_debug(3,
"aline = %d", aline);
139 touch1_n = touch1_s = touch1_e = touch1_w = 0;
140 for (j = 1; j < APoints->n_points; j++) {
141 if (APoints->y[j] == ABox.N)
143 if (APoints->y[j] == ABox.S)
145 if (APoints->x[j] == ABox.E)
147 if (APoints->x[j] == ABox.W)
150 G_debug(3,
"touch1: n = %d s = %d e = %d w = %d", touch1_n,
151 touch1_s, touch1_e, touch1_w);
152 touch2_n = touch2_s = touch2_e = touch2_w = 0;
153 for (j = 0; j < APoints->n_points - 1; j++) {
154 if (APoints->y[j] == ABox.N)
156 if (APoints->y[j] == ABox.S)
158 if (APoints->x[j] == ABox.E)
160 if (APoints->x[j] == ABox.W)
163 G_debug(3,
"touch2: n = %d s = %d e = %d w = %d", touch2_n,
164 touch2_s, touch2_e, touch2_w);
168 G_debug(3,
" %d lines selected by box", List->n_values);
170 for (j = 0; j < List->n_values; j++) {
171 bline = List->value[j];
175 G_debug(3,
" j = %d bline = %d", j, bline);
183 if (anode1 == bnode1 || anode1 == bnode2)
185 else if (anode2 == bnode1 || anode2 == bnode2)
192 if ((node == anode1 && nodey == ABox.N && !touch1_n &&
193 nodey == BBox.S) || (node == anode2 &&
194 nodey == ABox.N && !touch2_n &&
196 (node == anode1 && nodey == ABox.S && !touch1_s &&
197 nodey == BBox.N) || (node == anode2 &&
198 nodey == ABox.S && !touch2_s &&
200 (node == anode1 && nodex == ABox.E && !touch1_e &&
201 nodex == BBox.W) || (node == anode2 &&
202 nodex == ABox.E && !touch2_e &&
204 (node == anode1 && nodex == ABox.W && !touch1_w &&
205 nodex == BBox.E) || (node == anode2 &&
206 nodex == ABox.W && !touch2_w &&
209 "lines %d and %d touching by end nodes only -> no intersection",
221 &naxlines, &nbxlines, 0);
222 G_debug(3,
" naxlines = %d nbxlines = %d", naxlines, nbxlines);
227 if (aline == bline && naxlines == 0 && nbxlines == 0 &&
228 APoints->n_points >= 3) {
232 G_debug(3,
" Check collapsed loop");
233 if (APoints->n_points % 2) {
234 centre = APoints->n_points / 2;
235 if (APoints->x[centre - 1] == APoints->x[centre + 1] && APoints->y[centre - 1] == APoints->y[centre + 1] && APoints->z[centre - 1] == APoints->z[centre + 1]) {
237 (
struct line_pnts **)G_malloc(2 *
244 for (i = 0; i <= centre; i++)
246 APoints->y[i], APoints->z[i]);
248 for (i = centre; i < APoints->n_points; i++)
250 APoints->y[i], APoints->z[i]);
259 xx = (
double *)G_malloc((naxlines + nbxlines) *
261 yx = (
double *)G_malloc((naxlines + nbxlines) *
263 zx = (
double *)G_malloc((naxlines + nbxlines) *
269 for (k = 0; k < naxlines; k++) {
273 if ((atype & GV_POINTS) || AXLines[k]->n_points > 1) {
278 G_debug(3,
"Line %d written, npoints = %d", ret,
279 AXLines[k]->n_points);
288 xx[nx] = AXLines[k]->x[0];
289 yx[nx] = AXLines[k]->y[0];
290 zx[nx] = AXLines[k]->z[0];
296 nbreaks += naxlines - 1;
302 if (aline != bline) {
304 for (k = 0; k < nbxlines; k++) {
308 if ((btype & GV_POINTS) || BXLines[k]->n_points > 1) {
312 G_debug(5,
"Line %d written", ret);
322 for (l = 0; l < nx; l++) {
323 if (xx[l] == BXLines[k]->x[0] &&
324 yx[l] == BXLines[k]->y[0] &&
325 zx[l] == BXLines[k]->z[0]) {
331 xx[nx] = BXLines[k]->x[0];
332 yx[nx] = BXLines[k]->y[0];
333 zx[nx] = BXLines[k]->z[0];
340 nbreaks += nbxlines - 1;
343 for (k = 0; k < nbxlines; k++)
350 for (l = 0; l < nx; l++) {
365 nlines = List_break->n_values;
370 G_debug(3,
"nlines = %d", nlines);