24 #define LENGTH(DX, DY) ( sqrt( (DX*DX)+(DY*DY) ) ) 28 static void vect(
double x1,
double y1,
double x2,
double y2,
double *
x,
52 static int find_cross(
struct line_pnts *Points,
int s1,
int s2,
int s3,
53 int s4,
int *s5,
int *s6)
59 "find_cross(): npoints = %d, s1 = %d, s2 = %d, s3 = %d, s4 = %d",
65 for (i = s1; i <= s2; i++) {
66 for (j = s3; j <= s4; j++) {
72 x[j], y[j], x[j + 1], y[j + 1]);
73 if (ret == 1 && ((i - j) > 1 || (i - j) < -1)) {
76 G_debug(5,
" intersection: s5 = %d, s6 = %d", *s5, *s6);
82 G_debug(5,
" overlap: s5 = %d, s6 = %d", *s5, *s6);
95 static int point_in_buf(
struct line_pnts *Points,
double px,
double py,
103 for (i = 0; i < np - 1; i++) {
105 Points->
x[i], Points->
y[i], 0,
106 Points->
x[i + 1], Points->
y[i + 1],
130 static void clean_parallel(
struct line_pnts *Points,
131 struct line_pnts *origPoints,
double d,
int rm_end)
133 int i, j, np, npn, sa, sb;
135 int first = 0, current, last, lcount;
136 double *
x, *y, px, py, ix, iy;
139 G_debug(4,
"clean_parallel(): npoints = %d, d = %f, rm_end = %d",
154 while (first < np - 2) {
160 (Points, current, last - 1, current + 1, last, &sa,
169 G_debug(5,
" current = %d, last = %d, lcount = %d", current,
183 if ((sb - sa) == 1) {
190 y[sb], x[sb + 1], y[sb + 1], &ix, &iy);
192 for (i = sa + 1; i < sb + 1; i++) {
196 if (point_in_buf(origPoints, px, py, d)) {
212 for (i = j; i < Points->
n_points; i++) {
223 for (i = 0; i < Points->
n_points - 1; i++) {
224 px = (x[i] + x[i + 1]) / 2;
225 py = (y[i] + y[i + 1]) / 2;
226 if (point_in_buf(origPoints, x[i], y[i], d * 0.9999)
227 && point_in_buf(origPoints, px, py, d * 0.9999)) {
236 for (i = j; i < Points->
n_points; i++) {
245 for (i = Points->
n_points - 1; i >= 1; i--) {
246 px = (x[i] + x[i - 1]) / 2;
247 py = (y[i] + y[i - 1]) / 2;
248 if (point_in_buf(origPoints, x[i], y[i], d * 0.9999)
249 && point_in_buf(origPoints, px, py, d * 0.9999)) {
269 static void parallel_line(
struct line_pnts *Points,
double d,
double tol,
272 int i, j, np, na, side;
273 double *
x, *
y, nx, ny, tx, ty, vx, vy, ux, uy, wx, wy;
274 double atol, atol2, a, av, aw;
298 side = (int)(d / fabs(d));
299 atol = 2 * acos(1 - tol / fabs(d));
301 for (i = 0; i < np - 1; i++) {
302 vect(x[i], y[i], x[i + 1], y[i + 1], &tx, &ty);
315 vect(x[i + 1], y[i + 1], x[i + 2], y[i + 2], &ux, &uy);
320 a = (aw - av) * side;
325 if (a <= PI && a > atol) {
326 na = (int)(a / atol);
327 atol2 = a / (na + 1) * side;
328 for (j = 0; j < na; j++) {
330 nx = x[i + 1] + fabs(d) * cos(av);
331 ny = y[i + 1] + fabs(d) * sin(av);
355 double tolerance,
int rm_end,
struct line_pnts *OutPoints)
358 "Vect_line_parallel(): npoints = %d, distance = %f, tolerance = %f",
359 InPoints->
n_points, distance, tolerance);
361 parallel_line(InPoints, distance, tolerance, OutPoints);
363 clean_parallel(OutPoints, InPoints, distance, rm_end);
383 double tolerance,
struct line_pnts *OutPoints)
390 distance = fabs(distance);
392 dangle = 2 * acos(1 - tolerance / fabs(distance));
411 else if (npoints == 1) {
414 for (angle = 0; angle < 2 *
PI; angle += dangle) {
415 x = Points->
x[0] + distance * cos(angle);
416 y = Points->
y[0] + distance * sin(angle);
423 for (side = 0; side < 2; side++) {
424 double angle, sangle;
425 double lx1, ly1, lx2, ly2;
426 double x,
y, nx, ny, sx, sy, ex, ey;
441 lx1 = Points->
x[npoints - 2];
442 ly1 = Points->
y[npoints - 2];
443 lx2 = Points->
x[npoints - 1];
444 ly2 = Points->
y[npoints - 1];
454 vect(lx1, ly1, lx2, ly2, &nx, &ny);
457 sangle = atan2(-nx, ny);
458 sx = lx2 + ny * distance;
459 sy = ly2 - nx * distance;
462 ex = lx2 - ny * distance;
463 ey = ly2 + nx * distance;
468 for (angle = dangle; angle <
PI; angle += dangle) {
469 x = lx2 + distance * cos(sangle + angle);
470 y = ly2 + distance * sin(sangle + angle);
int Vect_append_points(struct line_pnts *, const struct line_pnts *, int)
Appends points to the end of a line.
#define GV_FORWARD
Line direction indicator forward/backward.
void Vect_line_buffer(const struct line_pnts *InPoints, double distance, double tolerance, struct line_pnts *OutPoints)
Create buffer around the line line.
int n_points
Number of points.
int Vect_copy_xyz_to_pnts(struct line_pnts *, const double *, const double *, const double *, int)
Copy points from array to line_pnts structure.
int Vect_line_prune(struct line_pnts *)
Remove duplicate points, i.e. zero length segments.
double * x
Array of X coordinates.
Feature geometry info - coordinates.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
double dig_distance2_point_to_line(double, double, double, double, double, double, double, double, double, int, double *, double *, double *, double *, int *)
int Vect_append_point(struct line_pnts *, double, double, double)
Appends one point to the end of a line.
int dig_find_intersection(double, double, double, double, double, double, double, double, double *, double *)
int dig_test_for_intersection(double, double, double, double, double, double, double, double)
double * y
Array of Y coordinates.
int Vect_find_poly_centroid(const struct line_pnts *, double *, double *)
Get centroid of polygon.
void Vect_line_parallel(struct line_pnts *InPoints, double distance, double tolerance, int rm_end, struct line_pnts *OutPoints)
Create parallel line.
int G_debug(int, const char *,...) __attribute__((format(printf
void Vect_reset_line(struct line_pnts *)
Reset line.