19 #include <grass/Vect.h>
20 #include <grass/glocale.h>
22 static double dist_squared(
double,
double,
double,
double);
43 struct line_pnts *points,
int type)
45 register int i, j, nlines;
50 G_debug(3,
"dig_node_add_line(): node = %d line = %d", nodeid, lineid);
52 node = plus->Node[nodeid];
53 nlines = node->n_lines;
69 G_debug(3,
" angle = %f", angle);
72 node->angles[nlines] = 999.;
74 for (i = 0; i <= nlines; i++) {
75 if (angle < node->angles[i]) {
77 for (j = nlines - 1; j >= i; j--) {
78 node->angles[j + 1] = node->angles[j];
79 node->lines[j + 1] = node->lines[j];
81 node->angles[i] = angle;
82 node->lines[i] = lineid;
90 "dig_node_add_line(): line %d added position %d n_lines: %d angle %f",
91 lineid, i, node->n_lines, angle);
93 return ((
int)node->n_lines);
113 G_debug(3,
"dig_add_node(): n_nodes = %d, alloc_nodes = %d",
114 plus->n_nodes, plus->alloc_nodes);
115 if (plus->n_nodes >= plus->alloc_nodes) {
121 nnum = plus->n_nodes + 1;
125 node = plus->Node[nnum];
134 G_debug(3,
"new node = %d, n_nodes = %d, alloc_nodes = %d", nnum,
135 plus->n_nodes, plus->alloc_nodes);
153 register int first_time;
154 register int have_match;
156 double least_dist, dist;
163 for (i = 1; i <= plus->n_nodes; i++) {
164 if (plus->Node[i] ==
NULL)
167 node = plus->Node[i];
168 if ((fabs(node->x - x) <= thresh) && (fabs(node->y - y) <= thresh)) {
169 dist = dist_squared(x, y, node->x, node->y);
176 if (dist < least_dist) {
207 G_debug(3,
"dig_node_line_angle: node = %d line = %d", nodeid, lineid);
209 node = plus->Node[nodeid];
210 nlines = node->n_lines;
212 for (i = 0; i < nlines; i++) {
213 if (node->lines[i] == lineid)
214 return (node->angles[i]);
217 G_fatal_error(_(
"Attempt to read line angle for the line which is not connected to the node: "
218 "node %d, line %d"), nodeid, lineid);
223 static double dist_squared(
double x1,
double y1,
double x2,
double y2)
229 return (dx * dx + dy * dy);
int dig_alloc_nodes(struct Plus_head *Plus, int add)
P_NODE * dig_alloc_node()
float dig_node_line_angle(struct Plus_head *plus, int nodeid, int lineid)
Return line angle.
int dig_node_add_line(struct Plus_head *plus, int nodeid, int lineid, struct line_pnts *points, int type)
Add line info to node.
int dig_node_alloc_line(P_NODE *node, int add)
int dig_add_node(struct Plus_head *plus, double x, double y, double z)
Add new node to plus structure.
int dig_spidx_add_node(struct Plus_head *Plus, int node, double x, double y, double z)
Add new node to spatial index.
int dig_which_node(struct Plus_head *plus, double x, double y, double thresh)
Return actual index into node arrays of the first set of matching coordinates.
int G_debug(int level, const char *msg,...)
Print debugging message.
float dig_calc_begin_angle(struct line_pnts *points, double thresh)
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
float dig_calc_end_angle(struct line_pnts *points, double thresh)