GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
vector/vedit/distance.c
Go to the documentation of this file.
1/*!
2 \file lib/vector/vedit/distance.c
3
4 \brief Vedit library - distance calculation
5
6 SPDX-FileCopyrightText: 2007-2008 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author Martin Landa <landa.martin gmail.com>
10 */
11
12#include <grass/vedit.h>
13
14/*!
15 \brief Calculate distances between two lines
16
17 \todo LL projection
18
19 \param Points1 first line geometry
20 \param Points2 second line geometry
21 \param with_z WITH_Z for 3D data
22 \param[out] mindistidx index of minimal distance
23
24 \return minimal distance between two lines (their nodes)
25 */
27 struct line_pnts *Points2, int with_z,
28 int *mindistidx)
29{
30 unsigned int i;
31 double distances[4];
32
33 /*
34 distances[0] = first-first
35 distances[1] = first-last
36 distances[2] = last-first
37 distances[3] = last-last
38 */
39
41 Points1->z[0], Points2->x[0],
42 Points2->y[0], Points2->z[0], with_z);
43
45 Points1->x[0], Points1->y[0], Points1->z[0],
46 Points2->x[Points2->n_points - 1], Points2->y[Points2->n_points - 1],
47 Points2->z[Points2->n_points - 1], with_z);
48
50 Points1->x[Points1->n_points - 1], Points1->y[Points1->n_points - 1],
51 Points1->z[Points1->n_points - 1], Points2->x[0], Points2->y[0],
52 Points2->z[0], with_z);
53
55 Points1->x[Points1->n_points - 1], Points1->y[Points1->n_points - 1],
56 Points1->z[Points1->n_points - 1], Points2->x[Points2->n_points - 1],
57 Points2->y[Points2->n_points - 1], Points2->z[Points2->n_points - 1],
58 with_z);
59
60 /* find the minimal distance between first or last point of both lines */
61 *mindistidx = 0;
62 for (i = 0; i < sizeof(distances) / sizeof(double); i++) {
63 if (distances[i] >= 0.0 && distances[i] < distances[*mindistidx])
64 *mindistidx = i;
65 }
66
67 G_debug(3, "Vedit_get_min_distance(): dists=%f,%f,%f,%f", distances[0],
68 distances[1], distances[2], distances[3]);
69
70 return distances[*mindistidx];
71}
int G_debug(int, const char *,...) __attribute__((format(printf
double Vect_points_distance(double, double, double, double, double, double, int)
Calculate distance of 2 points.
Definition line.c:864
Feature geometry info - coordinates.
double Vedit_get_min_distance(struct line_pnts *Points1, struct line_pnts *Points2, int with_z, int *mindistidx)
Calculate distances between two lines.