21 #include <grass/gis.h>
22 #include <grass/Vect.h>
23 #include <grass/glocale.h>
60 G_fatal_error(
"Vect_new_line_struct(): %s", _(
"Out of memory"));
69 p = (
struct line_pnts *)malloc(
sizeof(
struct line_pnts));
73 p->alloc_points = p->n_points = 0;
76 p->x = p->y = p->z =
NULL;
91 if (p->alloc_points) {
121 for (i = 0; i < n; i++) {
128 Points->n_points = n;
148 Points->n_points = 0;
173 n = Points->n_points;
178 return ++(Points->n_points);
197 if (index < 0 || index > Points->n_points - 1)
199 _(
"Index out of range in"));
205 for (n = Points->n_points; n > index; n--) {
206 Points->x[n] = Points->x[n - 1];
207 Points->y[n] = Points->y[n - 1];
208 Points->z[n] = Points->z[n - 1];
211 Points->x[index] = x;
212 Points->y[index] = y;
213 Points->z[index] = z;
214 return ++(Points->n_points);
229 if (index < 0 || index > Points->n_points - 1)
231 _(
"Index out of range in"));
233 if (Points->n_points == 0)
237 for (n = index; n < Points->n_points - 1; n++) {
238 Points->x[n] = Points->x[n + 1];
239 Points->y[n] = Points->y[n + 1];
240 Points->z[n] = Points->z[n + 1];
243 return --(Points->n_points);
257 if (Points->n_points > 0) {
259 for (i = 1; i < Points->n_points; i++) {
260 if (Points->x[i] != Points->x[j - 1] ||
261 Points->y[i] != Points->y[j - 1]
262 || Points->z[i] != Points->z[j - 1]) {
263 Points->x[j] = Points->x[i];
264 Points->y[j] = Points->y[i];
265 Points->z[j] = Points->z[i];
269 Points->n_points = j;
272 return (Points->n_points);
289 if (ret < Points->n_points)
290 Points->n_points = ret;
292 return (Points->n_points);
315 on = Points->n_points;
316 an = APoints->n_points;
323 if (direction == GV_FORWARD) {
324 for (i = 0; i < an; i++) {
325 Points->x[on + i] = APoints->x[i];
326 Points->y[on + i] = APoints->y[i];
327 Points->z[on + i] = APoints->z[i];
331 for (i = 0; i < an; i++) {
332 Points->x[on + i] = APoints->x[an - i - 1];
333 Points->y[on + i] = APoints->y[an - i - 1];
334 Points->z[on + i] = APoints->z[an - i - 1];
338 Points->n_points = n;
362 for (i = 0; i < *n; i++) {
367 *n = Points->n_points;
370 return (Points->n_points);
392 double *x,
double *y,
double *z,
double *angle,
396 double dist = 0, length;
397 double xp = 0, yp = 0, zp = 0, dx = 0, dy = 0, dz = 0, dxy =
400 G_debug(3,
"Vect_point_on_line(): distance = %f", distance);
401 if ((distance < 0) || (Points->n_points < 2))
406 G_debug(3,
" length = %f", length);
407 if (distance < 0 || distance > length) {
408 G_debug(3,
" -> outside line");
412 np = Points->n_points;
418 dx = Points->x[1] - Points->x[0];
419 dy = Points->y[1] - Points->y[0];
420 dz = Points->z[1] - Points->z[0];
424 else if (distance == length) {
426 xp = Points->x[np - 1];
427 yp = Points->y[np - 1];
428 zp = Points->z[np - 1];
429 dx = Points->x[np - 1] - Points->x[np - 2];
430 dy = Points->y[np - 1] - Points->y[np - 2];
431 dz = Points->z[np - 1] - Points->z[np - 2];
436 for (j = 0; j < Points->n_points - 1; j++) {
439 dx = Points->x[j + 1] - Points->x[j];
440 dy = Points->y[j + 1] - Points->y[j];
441 dz = Points->z[j + 1] - Points->z[j];
443 dxyz = hypot(dxy, dz);
446 if (dist >= distance) {
447 rest = distance - dist + dxyz;
450 xp = Points->x[j] + k * dx;
451 yp = Points->y[j] + k * dy;
452 zp = Points->z[j] + k * dz;
468 *angle = atan2(dy, dx);
472 *slope = atan2(dz, dxy);
496 struct line_pnts *OutPoints)
500 double x1, y1, z1, x2, y2, z2;
502 G_debug(3,
"Vect_line_segment(): start = %f, end = %f, n_points = %d",
503 start, end, InPoints->n_points);
524 G_debug(3,
" -> seg1 = %d seg2 = %d", seg1, seg2);
526 if (seg1 == 0 || seg2 == 0) {
527 G_warning(_(
"Segment outside line, no segment created"));
533 for (i = seg1; i < seg2; i++) {
555 double dx, dy, dz, len = 0;
557 if (Points->n_points < 2)
560 for (j = 0; j < Points->n_points - 1; j++) {
561 dx = Points->x[j + 1] - Points->x[j];
562 dy = Points->y[j + 1] - Points->y[j];
563 dz = Points->z[j + 1] - Points->z[j];
564 len += hypot(hypot(dx, dy), dz);
583 double dx, dy, dz, dxy, len = 0;
587 if (Points->n_points < 2)
590 for (j = 0; j < Points->n_points - 1; j++) {
594 Points->x[j + 1], Points->y[j + 1]);
596 dx = Points->x[j + 1] - Points->x[j];
597 dy = Points->y[j + 1] - Points->y[j];
601 dz = Points->z[j + 1] - Points->z[j];
602 len += hypot(dxy, dz);
629 double ux,
double uy,
double uz,
631 double *px,
double *py,
double *pz,
632 double *dist,
double *spdist,
double *lpdist)
635 register double distance;
636 register double new_dist;
637 double tpx, tpy, tpz, tdist, tspdist, tlpdist = 0;
639 register int n_points;
642 n_points = points->n_points;
647 points->y[0], points->z[0],
648 points->x[0], points->y[0],
654 tdist = sqrt(distance);
664 points->y[0], points->z[0],
665 points->x[1], points->y[1],
670 for (i = 1; i < n_points - 1; i++) {
672 points->x[i], points->y[i],
676 points->z[i + 1], with_z,
679 if (new_dist < distance) {
687 points->x[segment - 1],
688 points->y[segment - 1],
689 points->z[segment - 1],
692 points->z[segment], with_z,
693 &tpx, &tpy, &tpz, &tspdist,
699 for (i = 0; i < segment - 1; i++) {
700 dx = points->x[i + 1] - points->x[i];
701 dy = points->y[i + 1] - points->y[i];
703 dz = points->z[i + 1] - points->z[i];
707 tlpdist += hypot(hypot(dx, dy), dz);
711 tdist = sqrt(distance);
743 double x2,
double y2,
double z2,
754 return hypot(hypot(dx, dy), dz);
756 return hypot(dx, dy);
786 np = (int)Points->n_points / 2;
788 for (i = 0; i < np; i++) {
789 j = Points->n_points - i - 1;
793 Points->x[i] = Points->x[j];
794 Points->y[i] = Points->y[j];
795 Points->z[i] = Points->z[j];
815 static struct line_cats *cats =
NULL;
823 G_debug(3,
"Vect_get_line_cat: display line %d, ltype %d, cat %d", line,