21 static int find_extended_intersection(
double,
double,
double,
double,
double,
22 double,
double *,
double *);
23 static int check_extended_direction(
double,
double,
double,
int,
double,
69 int parallel,
double thresh)
72 int i, j, first_node, n_nodes;
74 struct ilist *List_exclude, *List_found;
94 for (i = 0; i < List->
n_values; i++) {
95 int line, extended, node[2];
97 line = List->
value[i];
105 node[0] = node[1] = -1;
107 if (node[0] < 0 || node[1] < 0)
113 for (j = first_node; j < n_nodes && !extended; j++) {
129 G_debug(3,
"Vedit_extend_lines(): lines=%d,%d", line,
131 if (
extend_lines(Map, !j, line, found, parallel, thresh,
134 "Vedit_extend_lines(): lines=%d,%d -> extended",
136 nlines_modified += 2;
142 }
while (List_found->
n_values > 0 && !extended);
149 return nlines_modified;
153 int parallel,
double thresh,
struct ilist *List
UNUSED)
161 int type_from, type_to;
163 struct line_pnts *Points_from, *Points_to, *Points_final;
172 type_from =
Vect_read_line(Map, Points_from, Cats_from, line_from);
181 int n_points, seg, is, line_to_extended;
182 double x, y, px, py, x1, y1;
183 double dist, spdist, lpdist, length;
184 double angle_t, angle_f;
189 n_points = Points_from->
n_points - 1;
192 x = Points_from->
x[0];
193 y = Points_from->
y[0];
196 x = Points_from->
x[n_points];
197 y = Points_from->
y[n_points];
200 NULL, &dist, &spdist, &lpdist);
202 if (!(seg > 0 && dist > 0.0 && (thresh < 0. || dist <= thresh)))
215 line_to_extended = 0;
218 if (!find_extended_intersection(
x, y, angle_f, px, py, angle_t, &x1,
233 if (!check_extended_direction(
x, y, angle_f, first, x1, y1))
249 if (seg > 1 && seg < Points_to->n_points - 1)
253 line_to_extended = 1;
255 x2 = Points_to->
x[0];
256 y2 = Points_to->
y[0];
259 line_to_extended = 2;
261 x2 = Points_to->
x[Points_to->
n_points - 1];
262 y2 = Points_to->
y[Points_to->
n_points - 1];
266 if (!check_extended_direction(x2, y2, angle_t, seg == 1, x1,
275 Points_from->
x[0] = x1;
276 Points_from->
y[0] = y1;
279 Points_from->
x[n_points] = x1;
280 Points_from->
y[n_points] = y1;
289 if (line_to_extended == 1) {
292 for (is = 0; is < Points_to->
n_points; is++)
294 Points_to->
y[is], Points_to->
z[is]);
298 else if (line_to_extended == 2) {
300 for (is = 0; is < Points_to->
n_points; is++)
302 Points_to->
y[is], Points_to->
z[is]);
312 for (is = 0; is < seg; is++)
314 Points_to->
y[is], Points_to->
z[is]);
320 Points_final, Cats_to);
327 for (is = seg; is < Points_to->
n_points; is++)
329 Points_to->
y[is], Points_to->
z[is]);
337 Points_final, Cats_to);
349 return line_new > 0 ? 1 : 0;
352 static int find_extended_intersection(
double x1,
double y1,
double angle1,
353 double x2,
double y2,
double angle2,
354 double *
x,
double *y)
356 double c1, s1, c2, s2, d, a;
358 if (fabs(sin(angle1 - angle2)) <=
TOL) {
362 angle = atan2(y2 - y1, x2 - x1);
363 if (fabs(sin(angle - angle1)) <=
TOL) {
379 d = -c1 * s2 + c2 * s1;
384 a = (-s2 * (x2 - x1) + c2 * (y2 - y1)) / d;
391 static int check_extended_direction(
double x,
double y,
double angle,
392 int start_node,
double extx,
double exty)
395 int xdir, ydir, xext, yext;
402 xdir = (fabs(tmp) <=
TOL ? 0 : (tmp > 0 ? 1 : -1));
404 ydir = (fabs(tmp) <=
TOL ? 0 : (tmp > 0 ? 1 : -1));
408 xext = (fabs(tmp) <=
TOL ? 0 : (tmp > 0 ? 1 : -1));
410 yext = (fabs(tmp) <=
TOL ? 0 : (tmp > 0 ? 1 : -1));
412 if (xext != 0 && yext != 0) {
414 if (xdir / xext <= 0 || ydir / yext <= 0)
418 else if (xext == 0 && yext == 0) {
421 else if (xext == 0) {
424 if (xdir != 0 || ydir / yext <= 0)
431 if (ydir != 0 || xdir / xext <= 0)
int G_debug(int, const char *,...) __attribute__((format(printf
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
off_t Vect_rewrite_line(struct Map_info *, off_t, int, const struct line_pnts *, const struct line_cats *)
Rewrites existing feature (topological level required)
int Vect_get_line_nodes(struct Map_info *, int, int *, int *)
Get line nodes.
int Vect_get_node_coor(struct Map_info *, int, double *, double *, double *)
Get node coordinates.
double Vect_line_length(const struct line_pnts *)
Calculate line length, 3D-length in case of 3D vector line.
int Vect_point_on_line(const struct line_pnts *, double, double *, double *, double *, double *, double *)
Find point on line in the specified distance.
int Vect_get_line_type(struct Map_info *, int)
Get line type.
int Vect_find_line_list(struct Map_info *, double, double, double, int, double, int, const struct ilist *, struct ilist *)
Find the nearest line(s).
void Vect_destroy_list(struct ilist *)
Frees all memory associated with a struct ilist, including the struct itself.
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
int Vect_list_append(struct ilist *, int)
Append new item to the end of list if not yet present.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int Vect_line_distance(const struct line_pnts *, double, double, double, int, double *, double *, double *, double *, double *, double *)
Calculate distance of point to line.
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
int Vect_line_alive(struct Map_info *, int)
Check if feature is alive or dead (topological level required)
int Vect_line_insert_point(struct line_pnts *, int, double, double, double)
Insert new point at index position and move all old points at that position and above up.
off_t Vect_write_line(struct Map_info *, int, const struct line_pnts *, const struct line_cats *)
Writes a new feature.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
void Vect_reset_line(struct line_pnts *)
Reset line.
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
int Vect_reset_list(struct ilist *)
Reset ilist structure.
int Vect_append_point(struct line_pnts *, double, double, double)
Appends one point to the end of a line.
#define WITHOUT_Z
2D/3D vector data
int extend_lines(struct Map_info *Map, int first, int line_from, int line_to, int parallel, double thresh, struct ilist *List UNUSED)
int Vedit_extend_lines(struct Map_info *Map, struct ilist *List, int nodes, int parallel, double thresh)
Extend lines in given threshold.
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
int n_values
Number of values in the list.
int * value
Array of values.
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
int n_points
Number of points.
double * z
Array of Z coordinates.