plus_area.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. /**
  2. * \file plus_area.c
  3. *
  4. * \brief Vector library - update topo for areas (lower level functions)
  5. *
  6. * Lower level functions for reading/writing/manipulating vectors.
  7. *
  8. * This program is free software under the GNU General Public License
  9. * (>=v2). Read the file COPYING that comes with GRASS for details.
  10. *
  11. * \author CERL (probably Dave Gerdes), Radim Blazek
  12. *
  13. * \date 2001-2006
  14. */
  15. #include <stdlib.h>
  16. #include <grass/Vect.h>
  17. #include <grass/glocale.h>
  18. /*!
  19. * \brief Build topo for area from lines
  20. *
  21. * Area is built in clockwise order.
  22. * Take a given line and start off to the RIGHT/LEFT and try to complete
  23. * an area.
  24. *
  25. * Possible Scenarios:
  26. * - I. path runs into first line. : AREA!
  27. * - II. path runs into a dead end (no other area lines at node) : no area
  28. * - III. path runs into a previous line that is not 1st line or to 1st line but not to start node : no area
  29. *
  30. * After we find an area then we call point_in_area() to see if the
  31. * specified point is w/in the area
  32. *
  33. * Old returns -1: error 0: no area (1: point in area)
  34. * -2: island !!
  35. *
  36. * \param[in] plus pointer to Plus_head structure
  37. * \param[in] first_line line id of first line
  38. * \param[in] side side of line to build area on (GV_LEFT | GV_RIGHT)
  39. * \param[in] lines pointer to array of lines
  40. *
  41. * \return -1 on error
  42. * \return 0 no area
  43. * \return number of lines
  44. */
  45. int
  46. dig_build_area_with_line(struct Plus_head *plus, plus_t first_line, int side,
  47. plus_t ** lines)
  48. {
  49. register int i;
  50. int prev_line, next_line;
  51. static plus_t *array;
  52. char *p;
  53. static int array_size; /* 0 on startup */
  54. int n_lines;
  55. P_LINE *Line;
  56. int node;
  57. G_debug(3, "dig_build_area_with_line(): first_line = %d, side = %d",
  58. first_line, side);
  59. /* First check if line is not degenerated (degenerated lines have angle -9)
  60. * Following degenerated lines are skip by dig_angle_next_line() */
  61. Line = plus->Line[first_line];
  62. node = Line->N1; /* to check one is enough, because if degenerated N1 == N2 */
  63. if (dig_node_line_angle(plus, node, first_line) == -9.) {
  64. G_debug(3, "First line degenerated");
  65. return (0);
  66. }
  67. if (array_size == 0) { /* first time */
  68. array_size = 1000;
  69. array = (plus_t *) dig__falloc(array_size, sizeof(plus_t));
  70. if (array == NULL)
  71. return (dig_out_of_memory());
  72. }
  73. if (side == GV_LEFT) {
  74. first_line = -first_line; /* start at node1, reverse direction */
  75. }
  76. array[0] = first_line;
  77. prev_line = -first_line; /* start at node2 for direct and node1 for
  78. reverse direction */
  79. /* angle of first line */
  80. n_lines = 1;
  81. while (1) {
  82. next_line =
  83. dig_angle_next_line(plus, prev_line, GV_RIGHT, GV_BOUNDARY);
  84. G_debug(3, "next_line = %d", next_line);
  85. if (next_line == 0)
  86. return (-1); /* Not found */
  87. /* Check if adjacent lines do not have the same angle */
  88. if (!dig_node_angle_check(plus, next_line, GV_BOUNDARY)) {
  89. G_debug(3,
  90. "Cannot build area, a neighbour of the line %d has the same angle at the node",
  91. next_line);
  92. return 0;
  93. }
  94. /* I. Area closed. This also handles the problem w/ 1 single area line */
  95. if (first_line == next_line) {
  96. /* GOT ONE! fill area struct and return */
  97. G_debug(3, "Got one! :");
  98. for (i = 0; i < n_lines; i++) {
  99. G_debug(3, " area line (%d) = %d", i, array[i]);
  100. }
  101. *lines = array;
  102. return (n_lines);
  103. }
  104. /* II. Note this is a dead end */
  105. /* ( if prev_line != -first_line so it goes after the previous test) ? */
  106. if (prev_line == next_line) {
  107. G_debug(3, "Dead_end:");
  108. return (0); /* dead end */
  109. }
  110. /* III. Unclosed ?, I would say started from free end */
  111. for (i = 0; i < n_lines; i++)
  112. if (abs(next_line) == abs(array[i])) {
  113. G_debug(3, "Unclosed area:");
  114. return (0); /* ran into a different area */
  115. }
  116. /* otherwise keep going */
  117. if (n_lines >= array_size) {
  118. p = dig__frealloc(array, array_size + 100, sizeof(plus_t),
  119. array_size);
  120. if (p == NULL)
  121. return (dig_out_of_memory());
  122. array = (plus_t *) p;
  123. array_size += 100;
  124. }
  125. array[n_lines++] = next_line;
  126. prev_line = -next_line;
  127. }
  128. return 0;
  129. }
  130. /*!
  131. * \brief Allocate space for new area and create boundary info from array.
  132. *
  133. * Then for each line in area, update line (right,left) info.
  134. *
  135. * Neither islands nor centroids area filled.
  136. *
  137. * \param[in] plus pointer to Plus_head structure
  138. * \param[in] n_lines number of lines
  139. * \param[in] lines array of lines, negative for reverse direction
  140. *
  141. * \return number of new area
  142. * \return -1 on error
  143. */
  144. int dig_add_area(struct Plus_head *plus, int n_lines, plus_t * lines)
  145. {
  146. register int i;
  147. register int area, line;
  148. P_AREA *Area;
  149. P_LINE *Line;
  150. BOUND_BOX box, abox;
  151. G_debug(3, "dig_add_area():");
  152. /* First look if we have space in array of pointers to areas
  153. * and reallocate if necessary */
  154. if (plus->n_areas >= plus->alloc_areas) { /* array is full */
  155. if (dig_alloc_areas(plus, 1000) == -1)
  156. return -1;
  157. }
  158. /* allocate area structure */
  159. area = plus->n_areas + 1;
  160. G_debug(3, " new area = %d", area);
  161. Area = dig_alloc_area();
  162. if (Area == NULL)
  163. return -1;
  164. if (dig_area_alloc_line(Area, n_lines) == -1)
  165. return -1;
  166. for (i = 0; i < n_lines; i++) {
  167. line = lines[i];
  168. Area->lines[i] = line;
  169. Line = plus->Line[abs(line)];
  170. if (plus->do_uplist)
  171. dig_line_add_updated(plus, abs(line));
  172. if (line < 0) { /* revers direction -> area on left */
  173. if (Line->left != 0) {
  174. G_warning(_("Line %d already has area/isle %d to left"), line,
  175. Line->left);
  176. return -1;
  177. }
  178. G_debug(3, " Line %d left set to %d.", line, area);
  179. Line->left = area;
  180. }
  181. else {
  182. if (Line->right != 0) {
  183. G_warning(_("Line %d already has area/isle %d to right"),
  184. line, Line->right);
  185. return -1;
  186. }
  187. G_debug(3, " Line %d right set to %d.", line, area);
  188. Line->right = area;
  189. }
  190. dig_line_get_box(plus, abs(line), &box);
  191. if (i == 0)
  192. dig_box_copy(&abox, &box);
  193. else
  194. dig_box_extend(&abox, &box);
  195. }
  196. Area->n_lines = n_lines;
  197. Area->centroid = 0;
  198. plus->Area[area] = Area;
  199. dig_area_set_box(plus, area, &abox);
  200. dig_spidx_add_area(plus, area, &abox);
  201. plus->n_areas++;
  202. return (area);
  203. }
  204. /*!
  205. * \brief Add isle to area if does not exist yet.
  206. *
  207. * \param[in] plus pointer to Plus_head structure
  208. * \param[in] area area id
  209. * \param[in] isle isle id
  210. *
  211. * \return 0
  212. */
  213. int dig_area_add_isle(struct Plus_head *plus, int area, int isle)
  214. {
  215. int i;
  216. P_AREA *Area;
  217. G_debug(3, "dig_area_add_isle(): area = %d isle = %d", area, isle);
  218. Area = plus->Area[area];
  219. if (Area == NULL)
  220. G_fatal_error("Attempt to add isle to dead area");
  221. for (i = 0; i < Area->n_isles; i++) {
  222. if (Area->isles[i] == isle) { /* Already exist */
  223. G_debug(3, "isle already registered in area");
  224. return 0;
  225. }
  226. }
  227. if (Area->alloc_isles <= Area->n_isles) /* array is full */
  228. dig_area_alloc_isle(Area, 1);
  229. Area->isles[Area->n_isles] = isle;
  230. Area->n_isles++;
  231. G_debug(3, " -> n_isles = %d", Area->n_isles);
  232. return 0;
  233. }
  234. /*!
  235. * \brief Delete isle from area.
  236. *
  237. * \param[in] plus pointer to Plus_head structure
  238. * \param[in] area area id
  239. * \param[in] isle isle id
  240. *
  241. * \return 0
  242. */
  243. int dig_area_del_isle(struct Plus_head *plus, int area, int isle)
  244. {
  245. int i, mv;
  246. P_AREA *Area;
  247. G_debug(3, "dig_area_del_isle(): area = %d isle = %d", area, isle);
  248. Area = plus->Area[area];
  249. if (Area == NULL)
  250. G_fatal_error(_("Attempt to delete isle from dead area"));
  251. mv = 0;
  252. for (i = 0; i < Area->n_isles; i++) {
  253. if (mv) {
  254. Area->isles[i - 1] = Area->isles[i];
  255. }
  256. else {
  257. if (Area->isles[i] == isle)
  258. mv = 1;
  259. }
  260. }
  261. if (mv) {
  262. Area->n_isles--;
  263. }
  264. else {
  265. G_fatal_error(_("Attempt to delete not registered isle %d from area %d"),
  266. isle, area);
  267. }
  268. return 0;
  269. }
  270. /*!
  271. * \brief Delete area from Plus_head structure
  272. *
  273. * This function deletes area from the topo structure and resets references
  274. * to this area in lines, isles (within) to 0.
  275. * Possible new area is not created by this function, so that
  276. * old boundaries participating in this area are left without area information
  277. * even if form new area.
  278. * Not enabled now: If area is inside other area, area info for islands within
  279. * deleted area is reset to that area outside.
  280. * (currently area info of isles is set to 0)
  281. *
  282. * \param[in] plus pointer to Plus_head structure
  283. * \param[in] area area id
  284. *
  285. * \return 0 on error
  286. * \return 1 on success
  287. */
  288. int dig_del_area(struct Plus_head *plus, int area)
  289. {
  290. int i, line;
  291. /* int isle, area_out; */
  292. P_AREA *Area;
  293. P_LINE *Line;
  294. P_ISLE *Isle;
  295. G_debug(3, "dig_del_area() area = %d", area);
  296. Area = plus->Area[area];
  297. if (Area == NULL) {
  298. G_warning(_("Attempt to delete dead area"));
  299. return 0;
  300. }
  301. dig_spidx_del_area(plus, area);
  302. /* Set area for all lines to 0 */
  303. /* isle = 0; */
  304. for (i = 0; i < Area->n_lines; i++) {
  305. line = Area->lines[i]; /* >0 = clockwise -> right, <0 = counterclockwise ->left */
  306. Line = plus->Line[abs(line)];
  307. if (plus->do_uplist)
  308. dig_line_add_updated(plus, abs(line));
  309. if (line > 0) {
  310. G_debug(3, " Set line %d right side to 0", line);
  311. Line->right = 0;
  312. }
  313. else {
  314. G_debug(3, " Set line %d left side to 0", line);
  315. Line->left = 0;
  316. }
  317. /* Find the isle this area is part of (used late below) */
  318. /*
  319. if ( line > 0 ) {
  320. if ( Line->left < 0 ) isle = Line->left;
  321. } else {
  322. if ( Line->right < 0 ) isle = Line->right;
  323. }
  324. */
  325. }
  326. /* Unset area information of centroid */
  327. /* TODO: duplicate centroids have also area information ->
  328. * 1) do not save such info
  329. * 2) find all by box and reset info */
  330. line = Area->centroid;
  331. if (line > 0) {
  332. Line = plus->Line[line];
  333. if (!Line) {
  334. G_warning(_("Dead centroid %d registered for area (bug in the vector library)"),
  335. line);
  336. }
  337. else {
  338. Line->left = 0;
  339. if (plus->do_uplist)
  340. dig_line_add_updated(plus, line);
  341. }
  342. }
  343. /* Find the area this area is within */
  344. /*
  345. area_out = 0;
  346. if ( isle > 0 ) {
  347. Isle = plus->Isle[abs(isle)];
  348. area_out = Isle->area;
  349. }
  350. */
  351. /* Reset information about area outside for isles within this area */
  352. G_debug(3, " n_isles = %d", Area->n_isles);
  353. for (i = 0; i < Area->n_isles; i++) {
  354. Isle = plus->Isle[Area->isles[i]];
  355. if (Isle == NULL) {
  356. G_fatal_error(_("Attempt to delete area %d info from dead isle %d"),
  357. area, Area->isles[i]);
  358. }
  359. else {
  360. /* Isle->area = area_out; */
  361. Isle->area = 0;
  362. }
  363. }
  364. /* TODO: free structures */
  365. plus->Area[area] = NULL;
  366. return 1;
  367. }
  368. /*!
  369. * \brief Set area bounding box
  370. *
  371. * \param[in] plus pointer to Plus_head structure
  372. * \param[in] area area id
  373. * \param[in] Box bounding box
  374. *
  375. * \return 1
  376. */
  377. int dig_area_set_box(struct Plus_head *plus, plus_t area, BOUND_BOX * Box)
  378. {
  379. P_AREA *Area;
  380. Area = plus->Area[area];
  381. Area->N = Box->N;
  382. Area->S = Box->S;
  383. Area->E = Box->E;
  384. Area->W = Box->W;
  385. Area->T = Box->T;
  386. Area->B = Box->B;
  387. return (1);
  388. }
  389. /*!
  390. * \brief Find number line of next angle to follow an line
  391. *
  392. * Assume that lines are sorted in increasing angle order and angles
  393. * of points and degenerated lines are set to 9 (ignored).
  394. *
  395. * \param[in] plus pointer to Plus_head structure
  396. * \param[in] current_line current line id, negative if request for node 2
  397. * \param[in] side side GV_RIGHT or GV_LEFT
  398. * \param[in] type line type (GV_LINE, GV_BOUNDARY or both)
  399. *
  400. * \return line number of next angle to follow an line (negative if connected by node2)
  401. * (number of current line may be return if dangle - this is used in build)
  402. * \return 0 on error or not found
  403. */
  404. int
  405. dig_angle_next_line(struct Plus_head *plus, plus_t current_line, int side,
  406. int type)
  407. {
  408. int i, next;
  409. int current;
  410. int line;
  411. plus_t node;
  412. P_NODE *Node;
  413. P_LINE *Line;
  414. G_debug(3, "dig__angle_next_line: line = %d, side = %d, type = %d",
  415. current_line, side, type);
  416. Line = plus->Line[abs(current_line)];
  417. if (current_line > 0)
  418. node = Line->N1;
  419. else
  420. node = Line->N2;
  421. G_debug(3, " node = %d", node);
  422. Node = plus->Node[node];
  423. G_debug(3, " n_lines = %d", Node->n_lines);
  424. for (i = 0; i < Node->n_lines; i++) {
  425. G_debug(3, " i = %d line = %d angle = %f", i, Node->lines[i],
  426. Node->angles[i]);
  427. }
  428. /* first find index for that line */
  429. next = -1;
  430. for (current = 0; current < Node->n_lines; current++) {
  431. if (Node->lines[current] == current_line)
  432. next = current;
  433. }
  434. if (next == -1)
  435. return 0; /* not found */
  436. G_debug(3, " current position = %d", next);
  437. while (1) {
  438. if (side == GV_RIGHT) { /* go up (greater angle) */
  439. if (next == Node->n_lines - 1)
  440. next = 0;
  441. else
  442. next++;
  443. }
  444. else { /* go down (smaller angle) */
  445. if (next == 0)
  446. next = Node->n_lines - 1;
  447. else
  448. next--;
  449. }
  450. G_debug(3, " next = %d line = %d angle = %f", next,
  451. Node->lines[next], Node->angles[next]);
  452. if (Node->angles[next] == -9.) { /* skip points and degenerated */
  453. G_debug(3, " point/degenerated -> skip");
  454. if (Node->lines[next] == current_line)
  455. break; /* Yes, that may happen if input line is degenerated and isolated and this breaks loop */
  456. else
  457. continue;
  458. }
  459. line = abs(Node->lines[next]);
  460. Line = plus->Line[line];
  461. if (Line->type & type) { /* line found */
  462. G_debug(3, " this one");
  463. return (Node->lines[next]);
  464. }
  465. /* input line reached, this must be last, because current_line may be correct return value (dangle) */
  466. if (Node->lines[next] == current_line)
  467. break;
  468. }
  469. G_debug(3, " Line NOT found at node %d", (int)node);
  470. return 0;
  471. }
  472. /*!
  473. * \brief Checks if angles of adjacent lines differ.
  474. *
  475. * Negative line number for end point. Assume that lines are sorted
  476. * in increasing angle order and angles of points and degenerated
  477. * lines are set to 9 (ignored).
  478. *
  479. * \param[in] plus pointer to Plus_head structure
  480. * \param[in] line current line id, negative if request for node 2
  481. * \param[in] type line type (GV_LINE, GV_BOUNDARY or both)
  482. *
  483. * \return 1 angles differ
  484. * \return 0 angle of a line up or down is identical
  485. */
  486. int dig_node_angle_check(struct Plus_head *plus, plus_t line, int type)
  487. {
  488. int next, prev;
  489. float angle1, angle2;
  490. plus_t node;
  491. P_LINE *Line;
  492. G_debug(3, "dig_node_angle_check: line = %d, type = %d", line, type);
  493. Line = plus->Line[abs(line)];
  494. if (line > 0)
  495. node = Line->N1;
  496. else
  497. node = Line->N2;
  498. angle1 = dig_node_line_angle(plus, node, line);
  499. /* Next */
  500. next = dig_angle_next_line(plus, line, GV_RIGHT, type);
  501. angle2 = dig_node_line_angle(plus, node, next);
  502. if (angle1 == angle2) {
  503. G_debug(3,
  504. " The line to the right has the same angle: node = %d, line = %d",
  505. node, next);
  506. return 0;
  507. }
  508. /* Previous */
  509. prev = dig_angle_next_line(plus, line, GV_LEFT, type);
  510. angle2 = dig_node_line_angle(plus, node, prev);
  511. if (angle1 == angle2) {
  512. G_debug(3,
  513. " The line to the left has the same angle: node = %d, line = %d",
  514. node, next);
  515. return 0;
  516. }
  517. return 1; /* OK */
  518. }
  519. /*!
  520. * \brief Allocate space for new island and create boundary info from array.
  521. *
  522. * The order of input lines is expected to be counter clockwise.
  523. * Then for each line in isle, update line (right,left) info.
  524. *
  525. * Area number the island is within is not filled.
  526. *
  527. * \param[in] plus pointer to Plus_head structure
  528. * \param[in] n_lines number of lines
  529. * \param[in] lines array of lines, negative for reverse direction
  530. *
  531. * \return number of new isle
  532. * \return -1 on error
  533. */
  534. int dig_add_isle(struct Plus_head *plus, int n_lines, plus_t * lines)
  535. {
  536. register int i;
  537. register int isle, line;
  538. P_ISLE *Isle;
  539. P_LINE *Line;
  540. BOUND_BOX box, abox;
  541. G_debug(3, "dig_add_isle():");
  542. /* First look if we have space in array of pointers to isles
  543. * and reallocate if necessary */
  544. if (plus->n_isles >= plus->alloc_isles) { /* array is full */
  545. if (dig_alloc_isles(plus, 1000) == -1)
  546. return -1;
  547. }
  548. /* allocate isle structure */
  549. isle = plus->n_isles + 1;
  550. Isle = dig_alloc_isle();
  551. if (Isle == NULL)
  552. return -1;
  553. if ((dig_isle_alloc_line(Isle, n_lines)) == -1)
  554. return -1;
  555. Isle->area = 0;
  556. Isle->N = 0;
  557. Isle->S = 0;
  558. Isle->E = 0;
  559. Isle->W = 0;
  560. for (i = 0; i < n_lines; i++) {
  561. line = lines[i];
  562. G_debug(3, " i = %d line = %d", i, line);
  563. Isle->lines[i] = line;
  564. Line = plus->Line[abs(line)];
  565. if (plus->do_uplist)
  566. dig_line_add_updated(plus, abs(line));
  567. if (line < 0) { /* revers direction -> isle on left */
  568. if (Line->left != 0) {
  569. G_warning(_("Line %d already has area/isle %d to left"), line,
  570. Line->left);
  571. return -1;
  572. }
  573. Line->left = -isle;
  574. }
  575. else {
  576. if (Line->right != 0) {
  577. G_warning(_("Line %d already has area/isle %d to left"), line,
  578. Line->right);
  579. return -1;
  580. }
  581. Line->right = -isle;
  582. }
  583. dig_line_get_box(plus, abs(line), &box);
  584. if (i == 0)
  585. dig_box_copy(&abox, &box);
  586. else
  587. dig_box_extend(&abox, &box);
  588. }
  589. Isle->n_lines = n_lines;
  590. plus->Isle[isle] = Isle;
  591. dig_isle_set_box(plus, isle, &abox);
  592. dig_spidx_add_isle(plus, isle, &abox);
  593. plus->n_isles++;
  594. return (isle);
  595. }
  596. /*!
  597. * \brief Set isle bounding box
  598. *
  599. * \param[in] plus pointer to Plus_head structure
  600. * \param[in] isle isle id
  601. * \param[in] Box bounding box
  602. *
  603. * \return 1
  604. */
  605. int dig_isle_set_box(struct Plus_head *plus, plus_t isle, BOUND_BOX * Box)
  606. {
  607. P_ISLE *Isle;
  608. Isle = plus->Isle[isle];
  609. Isle->N = Box->N;
  610. Isle->S = Box->S;
  611. Isle->E = Box->E;
  612. Isle->W = Box->W;
  613. Isle->T = Box->T;
  614. Isle->B = Box->B;
  615. return (1);
  616. }
  617. /*!
  618. * \brief Delete island from Plus_head structure
  619. *
  620. * Reset references to it in lines and area outside.
  621. *
  622. * \param[in] plus pointer to Plus_head structure
  623. * \param[in] isle isle id
  624. *
  625. * \return 1
  626. */
  627. int dig_del_isle(struct Plus_head *plus, int isle)
  628. {
  629. int i, line;
  630. P_LINE *Line;
  631. P_ISLE *Isle;
  632. G_debug(3, "dig_del_isle() isle = %d", isle);
  633. Isle = plus->Isle[isle];
  634. dig_spidx_del_isle(plus, isle);
  635. /* Set area for all lines to 0 */
  636. for (i = 0; i < Isle->n_lines; i++) {
  637. line = Isle->lines[i]; /* >0 = clockwise -> right, <0 = counterclockwise ->left */
  638. Line = plus->Line[abs(line)];
  639. if (plus->do_uplist)
  640. dig_line_add_updated(plus, abs(line));
  641. if (line > 0)
  642. Line->right = 0;
  643. else
  644. Line->left = 0;
  645. }
  646. /* Delete reference from area it is within */
  647. G_debug(3, " area outside isle = %d", Isle->area);
  648. if (Isle->area > 0) {
  649. if (plus->Area[Isle->area] == NULL) {
  650. G_fatal_error(_("Attempt to delete isle %d info from dead area %d"),
  651. isle, Isle->area);
  652. }
  653. else {
  654. dig_area_del_isle(plus, Isle->area, isle);
  655. }
  656. }
  657. /* TODO: free structures */
  658. plus->Isle[isle] = NULL;
  659. return 1;
  660. }