distance.c
Go to the documentation of this file.00001
00017 #include <grass/vedit.h>
00018
00030 double Vedit_get_min_distance(struct line_pnts *Points1,
00031 struct line_pnts *Points2, int with_z,
00032 int *mindistidx)
00033 {
00034 unsigned int i;
00035 double distances[4];
00036
00037
00038
00039
00040
00041
00042
00043
00044 distances[0] =
00045 Vect_points_distance(Points1->x[0], Points1->y[0], Points1->z[0],
00046 Points2->x[0], Points2->y[0], Points2->z[0],
00047 with_z);
00048
00049 distances[1] =
00050 Vect_points_distance(Points1->x[0], Points1->y[0], Points1->z[0],
00051 Points2->x[Points2->n_points - 1],
00052 Points2->y[Points2->n_points - 1],
00053 Points2->z[Points2->n_points - 1], with_z);
00054
00055 distances[2] = Vect_points_distance(Points1->x[Points1->n_points - 1],
00056 Points1->y[Points1->n_points - 1],
00057 Points1->z[Points1->n_points - 1],
00058 Points2->x[0], Points2->y[0],
00059 Points2->z[0], with_z);
00060
00061 distances[3] = Vect_points_distance(Points1->x[Points1->n_points - 1],
00062 Points1->y[Points1->n_points - 1],
00063 Points1->z[Points1->n_points - 1],
00064 Points2->x[Points2->n_points - 1],
00065 Points2->y[Points2->n_points - 1],
00066 Points2->z[Points2->n_points - 1],
00067 with_z);
00068
00069
00070 *mindistidx = 0;
00071 for (i = 0; i < sizeof(distances) / sizeof(double); i++) {
00072 if (distances[i] >= 0.0 && distances[i] < distances[*mindistidx])
00073 *mindistidx = i;
00074 }
00075
00076 G_debug(3, "Vedit_get_min_distance(): dists=%f,%f,%f,%f",
00077 distances[0], distances[1], distances[2], distances[3]);
00078
00079 return distances[*mindistidx];
00080 }