/* just returns if line is not completed yet */ int write_boundary(struct COOR *seed) { struct COOR *point, *line_begin, *line_end; int dir, line_type, n, n1; point = seed; if ((dir = at_end(point))) { /* already have one end of line */ line_begin = point; line_end = find_end(point, dir, &line_type, &n); if (line_type == OPEN) return (-1); /* unfinished line */ direction = dir; } else { /* in middle of a line */ line_end = find_end(point, FORWARD, &line_type, &n); if (line_type == OPEN) /* line not finished */ return (-1); if (line_type == END) { /* found one end at least *//* look for other one */ line_begin = find_end(point, BACKWARD, &line_type, &n1); if (line_type == OPEN) /* line not finished */ return (-1); if (line_type == LOOP) { /* this should NEVER be the case */ return (-1); } direction = at_end(line_begin); /* found both ends now; total length */ n += n1; /* is sum of distances to each end */ } else { /* line_type = LOOP by default */ /* already have correct length */ line_begin = line_end; /* end and beginning are the same */ direction = FORWARD; /* direction is arbitrary */ } } if (smooth_flag == SMOOTH) write_smooth_bnd(line_begin, line_end, n); else write_bnd(line_begin, line_end, n); return (0); }
/* just returns if line is not completed yet */ int write_boundary(struct COOR *seed) { struct COOR *point, *line_begin, *line_end, *last; int dir, line_type, n, n1, i; point = seed; if ((dir = at_end(point))) { /* already have one end of line */ line_begin = point; line_end = find_end(point, dir, &line_type, &n); if (line_type == OPEN) return (-1); /* unfinished line */ direction = dir; } else { /* in middle of a line */ line_end = find_end(point, FORWARD, &line_type, &n); if (line_type == OPEN) /* line not finished */ return (-1); if (line_type == END) { /* found one end at least *//* look for other one */ line_begin = find_end(point, BACKWARD, &line_type, &n1); if (line_type == OPEN) /* line not finished */ return (-1); if (line_type == LOOP) { /* this should NEVER be the case */ return (-1); } direction = at_end(line_begin); /* found both ends now; total length */ n += n1; /* is sum of distances to each end */ } else { /* line_type = LOOP by default */ /* already have correct length */ line_begin = line_end; /* end and beginning are the same */ direction = FORWARD; /* direction is arbitrary */ } } dir = direction; if (smooth_flag == SMOOTH) write_smooth_bnd(line_begin, line_end, n); else write_bnd(line_begin, line_end, n); /* now free all the pointers */ direction = dir; point = line_begin; last = NULPTR; n1 = 0; /* skip first and last point */ while ((point = move(point)) == line_begin); while (point && point != line_end) { last = point; n1++; point = move(point); if (point == last) { /* should not happen */ G_warning("loop during free ptrs, ptr %d of %d", n1, n); point = move(point); } if (last->fptr != NULPTR) if (last->fptr->fptr == last) last->fptr->fptr = NULPTR; /* it can be NULL after the previous line, even though before it wasn't */ if (last->fptr != NULPTR) if (last->fptr->bptr == last) last->fptr->bptr = NULPTR; if (last->bptr != NULPTR) if (last->bptr->fptr == last) last->bptr->fptr = NULPTR; if (last->bptr != NULPTR) if (last->bptr->bptr == last) last->bptr->bptr = NULPTR; free_ptr(last); } if (point != line_end) { /* should not happen */ G_warning("Line end not reached, possible memory leak"); } /* free first and last point */ free_ptr(line_begin); if (line_end != line_begin) free_ptr(line_end); return (0); }