15 #include <grass/vedit.h>
17 static int connect_lines(
struct Map_info *,
int,
int,
int,
18 double,
struct ilist *);
32 struct line_pnts *coord,
double thresh,
33 struct ilist *List_updated)
36 int type, line, seg, newline;
38 double px, py, spdist, lpdist, dist;
41 struct line_pnts *Points, *Points2;
42 struct line_cats *Cats;
43 struct ilist *List_in_box;
52 for (i = 0; i < List->n_values; i++) {
53 line = List->value[i];
67 for (j = 0; j < coord->n_points; j++) {
70 coord->z[j], WITHOUT_Z, &px, &py,
NULL,
71 &dist, &spdist, &lpdist);
77 G_debug(3,
"Vedit_split_lines(): line=%d, x=%f, y=%f, px=%f, py=%f, seg=%d, "
78 "dist=%f, spdist=%f, lpdist=%f", line, coord->x[j],
79 coord->y[j], px, py, seg, dist, spdist, lpdist);
84 G_debug(3,
"Vedit_split_lines(): line=%d", line);
87 for (l = 0; l < seg; l++) {
107 for (l = seg; l < Points->n_points; l++) {
128 return nlines_modified;
154 int nlines_modified, connected;
155 int i, j, node[2], n_nodes;
159 struct ilist *List_exclude, *List_found;
169 for (i = 0; i < List->n_values; i++) {
170 line = List->value[i];
175 node[0] = node[1] = -1;
177 if (node[0] < 0 || node[1] < 0)
183 for (j = 0; j < n_nodes && !connected; j++) {
191 List_exclude, List_found);
195 G_debug(3,
"Vedit_connect_lines(): lines=%d,%d", line, found);
196 if (connect_lines(Map, !j, line, found, thresh, List)) {
197 G_debug(3,
"Vedit_connect_lines(): lines=%d,%d -> connected",
199 nlines_modified += 2;
205 }
while(List_found->n_values > 0 && !connected);
212 return nlines_modified;
215 int connect_lines(
struct Map_info *Map,
int first,
int line_from,
int line_to,
216 double thresh,
struct ilist *List)
219 int type_from, type_to;
220 int n_points, seg, is;
221 double x, y, px, py, x1, y1;
222 double dist, spdist, lpdist, length, dist_p;
223 double angle_t, angle_f, angle;
225 struct line_pnts *Points_from, *Points_to, *Points_final;
226 struct line_cats *Cats_from, *Cats_to;
234 type_from =
Vect_read_line(Map, Points_from, Cats_from, line_from);
238 if (!(type_from &
GV_LINES) || !(type_to & GV_LINES))
243 x = Points_from->x[0];
244 y = Points_from->y[0];
247 n_points = Points_from->n_points - 1;
248 x = Points_from->x[n_points];
249 y = Points_from->y[n_points];
252 &px, &py,
NULL, &dist, &spdist, &lpdist);
254 if (seg > 0 && dist > 0.0 && (thresh < 0. || dist <= thresh)) {
266 angle = angle_t - angle_f;
267 dist_p = fabs(dist / sin(angle));
276 x1 = x + dist_p * cos(angle_f);
277 y1 = y + dist_p * sin(angle_f);
285 Points_from->x[0] = x1;
286 Points_from->y[0] = y1;
289 Points_from->x[n_points] = x1;
290 Points_from->y[n_points] = y1;
294 Points_from, Cats_from);
299 for (is = 0; is < seg; is++) {
306 Points_final, Cats_to);
312 for (is = seg; is < Points_to->n_points; is++) {
320 Points_final, Cats_to);
334 return line_new > 0 ? 1 : 0;