22 #include <grass/gis.h>
23 #include <grass/Vect.h>
24 #include <grass/glocale.h>
39 void srch(
int id,
int *arg)
64 struct line_pnts *BPoints, *Points;
65 struct line_cats *Cats;
66 int i, j, k, ret, ltype, broken, last, nlines;
69 int apoints, npoints, nallpoints, nmarks;
72 double dx, dy, a1 = 0, a2 = 0;
73 int closed, last_point, cross;
83 G_debug(3,
"nlines = %d", nlines);
93 for (i = 1; i <= nlines; i++) {
110 last_point = Points->n_points - 1;
111 if (Points->x[0] == Points->x[last_point] &&
112 Points->y[0] == Points->y[last_point])
117 for (j = 0; j < Points->n_points; j++) {
121 if (j == last_point && closed)
135 G_debug(3,
"fpoint = %d", fpoint);
137 if (Points->n_points <= 2 ||
138 (!closed && (j == 0 || j == last_point))) {
143 if (j == 0 && closed) {
144 dx = Points->x[last_point] - Points->x[0];
145 dy = Points->y[last_point] - Points->y[0];
147 dx = Points->x[1] - Points->x[0];
148 dy = Points->y[1] - Points->y[0];
152 dx = Points->x[j - 1] - Points->x[j];
153 dy = Points->y[j - 1] - Points->y[j];
155 dx = Points->x[j + 1] - Points->x[j];
156 dy = Points->y[j + 1] - Points->y[j];
162 if (XPnts[fpoint].cross == 1)
167 XPnts[fpoint].
cross = 1;
171 G_debug(3,
"a1 = %f xa1 = %f a2 = %f xa2 = %f", a1,
172 XPnts[fpoint].a1, a2, XPnts[fpoint].a2);
173 if ((a1 == XPnts[fpoint].a1 && a2 == XPnts[fpoint].a2) || (a1 == XPnts[fpoint].a2 && a2 == XPnts[fpoint].a1)) {
177 XPnts[fpoint].
cross = 1;
185 if (npoints >= apoints) {
188 (
XPNT *) G_realloc(XPnts,
189 (apoints + 1) *
sizeof(
XPNT));
191 XPnts[npoints].
x = Points->x[j];
192 XPnts[npoints].
y = Points->y[j];
193 XPnts[npoints].
used = 0;
194 if (j == 0 || j == (Points->n_points - 1) ||
195 Points->n_points < 3) {
196 XPnts[npoints].
a1 = 0;
197 XPnts[npoints].
a2 = 0;
198 XPnts[npoints].
cross = 1;
202 XPnts[npoints].
a1 = a1;
203 XPnts[npoints].
a2 = a2;
204 XPnts[npoints].
cross = 0;
218 for (i = 1; i <= nlines; i++) {
233 n_orig_points = Points->n_points;
238 G_debug(3,
"n_points = %d", Points->n_points);
239 for (j = 1; j < Points->n_points; j++) {
251 if (Points->n_points <= 1 ||
252 (j == (Points->n_points - 1) && !broken))
258 G_debug(3,
"fpoint = %d", fpoint);
260 if (XPnts[fpoint].cross) {
261 XPnts[fpoint].
used = 1;
265 if ((j == (Points->n_points - 1) && broken) ||
266 XPnts[fpoint].
cross) {
268 for (k = last; k <= j; k++) {
275 if (BPoints->n_points > 1) {
278 "Line %d written j = %d n_points(orig,pruned) = %d n_points(new) = %d",
279 ret, j, Points->n_points, BPoints->n_points);
290 if (!broken && n_orig_points > Points->n_points) {
291 if (Points->n_points > 1) {
293 G_debug(3,
"Line %d pruned, npoints = %d", i,
298 G_debug(3,
"Line %d was deleted", i);
302 G_debug(3,
"Line %d was not changed", i);
309 for (i = 1; i < npoints; i++) {