21 static int debug_level = -1;
55 int prev_line, next_line;
58 static int array_size;
64 if (debug_level == -1) {
68 debug_level = atoi(dstr);
73 G_debug(3,
"dig_build_area_with_line(): first_line = %d, side = %d",
78 Line = plus->
Line[first_line];
85 G_debug(3,
"First line degenerated");
89 if (array_size == 0) {
97 first_line = -first_line;
99 array[0] = first_line;
100 prev_line = -first_line;
107 G_debug(3,
"next_line = %d", next_line);
109 if (next_line == 0) {
110 G_debug(3,
"Cannot build area, no next line for line %d",
118 "Cannot build area, a neighbour of the line %d has the same angle at the node",
124 if (first_line == next_line) {
129 if (debug_level > 2) {
130 for (i = 0; i < n_lines; i++) {
131 G_debug(3,
" area line (%d) = %d", i, array[i]);
141 if (prev_line == next_line) {
147 for (i = 0; i < n_lines; i++)
148 if (abs(next_line) == abs(array[i])) {
154 if (n_lines >= array_size) {
162 array[n_lines++] = next_line;
163 prev_line = -next_line;
188 register int area, line;
203 G_debug(3,
" new area = %d", area);
211 for (i = 0; i < n_lines; i++) {
213 Area->
lines[i] = line;
214 Line = plus->
Line[abs(line)];
217 if (topo->
left != 0) {
218 G_warning(
_(
"Line %d already has area/isle %d to left"), line,
223 G_debug(3,
" Line %d left set to %d.", line, area);
227 if (topo->
right != 0) {
228 G_warning(
_(
"Line %d already has area/isle %d to right"),
233 G_debug(3,
" Line %d right set to %d.", line, area);
240 plus->
Area[area] = Area;
263 G_debug(3,
"dig_area_add_isle(): area = %d isle = %d", area, isle);
265 if (debug_level == -1) {
269 debug_level = atoi(dstr);
274 Area = plus->
Area[area];
278 if (debug_level > 0) {
279 for (i = 0; i < Area->
n_isles; i++) {
280 if (Area->
isles[i] == isle) {
282 G_warning(
_(
"Isle already registered in area"));
312 G_debug(3,
"dig_area_del_isle(): area = %d isle = %d", area, isle);
314 Area = plus->
Area[area];
324 G_fatal_error(
_(
"Attempt to delete not registered isle %d from area %d"),
367 G_debug(3,
"dig_del_area() area = %d", area);
379 for (i = 0; i < Area->
n_lines; i++) {
380 line = Area->
lines[i];
381 Line = plus->
Line[abs(line)];
384 G_debug(3,
" Set line %d right side to 0", line);
388 G_debug(3,
" Set line %d left side to 0", line);
408 Line = plus->
Line[line];
410 G_warning(
_(
"Dead centroid %d registered for area (bug in the vector library)"),
430 for (i = 0; i < Area->
n_isles; i++) {
433 G_fatal_error(
_(
"Attempt to delete area %d info from dead isle %d"),
434 area, Area->
isles[i]);
467 int type,
float *angle)
475 if (debug_level == -1) {
479 debug_level = atoi(dstr);
484 G_debug(3,
"dig__angle_next_line: line = %d, side = %d, type = %d",
485 current_line, side, type);
487 Line = plus->
Line[abs(current_line)];
496 if (current_line > 0) {
517 G_debug(3,
" node = %d", node);
519 Node = plus->
Node[node];
522 if (debug_level > 2) {
525 for (i = 0; i < Node->
n_lines; i++) {
526 G_debug(3,
" i = %d line = %d angle = %f", i, Node->
lines[i],
533 while (next >= 0 && Node->
lines[next] != current_line) {
539 G_fatal_error(
"dig_angle_next_line(): line %d not found at its own node %d",
546 G_debug(3,
" current position = %d", next);
560 G_debug(3,
" next = %d line = %d angle = %f", next,
563 if (Node->
angles[next] == -9.) {
564 G_debug(3,
" point/degenerated -> skip");
565 if (Node->
lines[next] == current_line)
571 line = Node->
lines[next];
572 Line = plus->
Line[abs(line)];
574 if (Line->
type & type) {
577 *angle = Node->
angles[next];
582 if (line == current_line)
585 G_debug(3,
" No next line for line %d at node %d",
586 current_line, (
int)node);
610 float angle1, angle2;
614 G_debug(3,
"dig_node_angle_check: line = %d, type = %d", line, type);
616 Line = plus->
Line[abs(line)];
646 if (angle1 == angle2) {
648 " The line to the right has the same angle: node = %d, line = %d",
656 if (angle1 == angle2) {
658 " The line to the left has the same angle: node = %d, line = %d",
686 register int isle, line;
710 for (i = 0; i < n_lines; i++) {
712 G_debug(3,
" i = %d line = %d", i, line);
713 Isle->
lines[i] = line;
714 Line = plus->
Line[abs(line)];
717 if (topo->
left != 0) {
718 G_warning(
_(
"Line %d already has area/isle %d to left"), line,
725 if (topo->
right != 0) {
726 G_warning(
_(
"Line %d already has area/isle %d to right"), line,
737 plus->
Isle[isle] = Isle;
764 G_debug(3,
"dig_del_isle() isle = %d", isle);
765 Isle = plus->
Isle[isle];
770 for (i = 0; i < Isle->
n_lines; i++) {
771 line = Isle->
lines[i];
772 Line = plus->
Line[abs(line)];
782 if (Isle->
area > 0) {
784 G_fatal_error(
_(
"Attempt to delete isle %d info from dead area %d"),
plus_t n_areas
Current number of areas.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
plus_t area
Area number, negative for duplicate centroid.
#define GV_LEFT
Boundary side indicator left/right.
int dig_del_isle(struct Plus_head *plus, int isle)
Delete island from Plus_head structure.
int dig_spidx_del_isle(struct Plus_head *, int)
Delete isle from spatial index.
struct P_isle * dig_alloc_isle()
Allocate new isle structure.
struct P_line ** Line
Array of vector geometries.
struct P_area * dig_alloc_area()
Allocate new area structure.
plus_t right
Area number to the right, negative for isle.
struct P_area ** Area
Array of areas.
struct P_node ** Node
Array of nodes.
int dig_del_area(struct Plus_head *plus, int area)
Delete area from Plus_head structure.
plus_t n_lines
Number of attached lines (size of lines, angle)
plus_t left
Area number to the left, negative for isle.
int dig_out_of_memory(void)
For now just print message and return error code.
struct P_isle ** Isle
Array of isles.
plus_t * lines
List of connected lines.
plus_t * isles
1st generation interior islands
plus_t n_isles
Current number of isles.
plus_t centroid
Number of first centroid within area.
plus_t n_lines
Number of boundary lines.
plus_t alloc_areas
Number of allocated areas.
int dig_spidx_add_area(struct Plus_head *, int, const struct bound_box *)
Add new area to spatial index.
int dig_area_add_isle(struct Plus_head *plus, int area, int isle)
Add isle to area if does not exist yet.
int dig_build_area_with_line(struct Plus_head *plus, plus_t first_line, int side, plus_t **lines)
Build topo for area from lines.
plus_t * lines
List of boundary lines.
float dig_node_line_angle(struct Plus_head *, int, int)
Return line angle.
Basic topology-related info.
int dig_alloc_areas(struct Plus_head *, int)
Reallocate array of pointers to areas.
void * dig__falloc(int, int)
void * topo
Topology info.
void * dig__frealloc(void *, int, int, int)
float * angles
List of angles of connected lines.
int dig_add_isle(struct Plus_head *plus, int n_lines, plus_t *lines, struct bound_box *box)
Allocate space for new island and create boundary info from array.
void dig_free_area(struct P_area *)
Free area structure.
plus_t * lines
List of boundary lines.
int dig_angle_next_line(struct Plus_head *plus, plus_t current_line, int side, int type, float *angle)
Find line number of next angle to follow a line.
Topological feature - node.
int dig_spidx_add_isle(struct Plus_head *, int, const struct bound_box *)
Add new island to spatial index.
plus_t n_isles
Number of islands inside.
plus_t alloc_isles
Allocated space for isles.
int dig_area_alloc_isle(struct P_area *, int)
Allocate space in P_area for add new isles.
int dig_area_alloc_line(struct P_area *, int)
allocate space in P_area for add new lines
void G_warning(const char *,...) __attribute__((format(printf
int dig_node_angle_check(struct Plus_head *plus, plus_t line, int type)
Check if angles of adjacent lines differ.
int dig_spidx_del_area(struct Plus_head *, int)
Delete area from spatial index.
void dig_free_isle(struct P_isle *)
Free isle structure.
const char * G_getenv_nofatal(const char *)
Get environment variable.
int dig_alloc_isles(struct Plus_head *, int)
Reallocate array of pointers to isles.
int dig_isle_alloc_line(struct P_isle *, int)
Allocate space in P_isle for add new lines.
plus_t n_lines
Number of boundary lines.
plus_t area
Area it exists w/in, if any.
int dig_add_area(struct Plus_head *plus, int n_lines, plus_t *lines, struct bound_box *box)
Allocate space for new area and create boundary info from array.
int G_debug(int, const char *,...) __attribute__((format(printf
plus_t alloc_isles
Number of allocated isles.
int dig_area_del_isle(struct Plus_head *plus, int area, int isle)
Delete isle from area.