update.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * \file lib/vector/diglib/update.c
  3. *
  4. * \brief Vector library - update topology (lower level functions)
  5. *
  6. * Lower level functions for reading/writing/manipulating vectors.
  7. *
  8. * (C) 2001 by the GRASS Development Team
  9. *
  10. * This program is free software under the GNU General Public License
  11. * (>=v2). Read the file COPYING that comes with GRASS for details.
  12. *
  13. * \author Radim Blazek
  14. */
  15. #include <stdlib.h>
  16. #include <grass/vector.h>
  17. /*!
  18. \brief Reset number of updated lines
  19. \param Plus pointer to Plus_head structure
  20. */
  21. void dig_line_reset_updated(struct Plus_head *Plus)
  22. {
  23. Plus->uplist.n_uplines = 0;
  24. }
  25. /*!
  26. \brief Add new line to updated
  27. \param Plus pointer to Plus_head structure
  28. \param line line id
  29. \param offset line offset (negative offset is ignored)
  30. */
  31. void dig_line_add_updated(struct Plus_head *Plus, int line)
  32. {
  33. int i;
  34. G_debug(3, "dig_line_add_updated(): line = %d", line);
  35. /* Check if already in list */
  36. for (i = 0; i < Plus->uplist.n_uplines; i++) {
  37. if (Plus->uplist.uplines[i] == line) {
  38. G_debug(3, "\tskipped");
  39. return;
  40. }
  41. }
  42. /* Alloc space if needed */
  43. if (Plus->uplist.n_uplines == Plus->uplist.alloc_uplines) {
  44. Plus->uplist.alloc_uplines += 1000;
  45. Plus->uplist.uplines =
  46. (int *)G_realloc(Plus->uplist.uplines,
  47. Plus->uplist.alloc_uplines * sizeof(int));
  48. Plus->uplist.uplines_offset =
  49. (off_t *)G_realloc(Plus->uplist.uplines_offset,
  50. Plus->uplist.alloc_uplines * sizeof(off_t));
  51. }
  52. Plus->uplist.uplines[Plus->uplist.n_uplines] = line;
  53. Plus->uplist.n_uplines++;
  54. }
  55. /*!
  56. \brief Reset number of updated nodes
  57. \param Plus pointer to Plus_head structure
  58. */
  59. void dig_node_reset_updated(struct Plus_head *Plus)
  60. {
  61. Plus->uplist.n_upnodes = 0;
  62. }
  63. /*!
  64. \brief Add node to updated
  65. \param Plus pointer to Plus_head structure
  66. \param node node id
  67. */
  68. void dig_node_add_updated(struct Plus_head *Plus, int node)
  69. {
  70. int i;
  71. G_debug(3, "dig_node_add_updated(): node = %d", node);
  72. /* Check if already in list */
  73. for (i = 0; i < Plus->uplist.n_upnodes; i++) {
  74. if (abs(Plus->uplist.upnodes[i]) == abs(node)) {
  75. G_debug(3, "\tskipped");
  76. return;
  77. }
  78. }
  79. /* Alloc space if needed */
  80. if (Plus->uplist.n_upnodes == Plus->uplist.alloc_upnodes) {
  81. Plus->uplist.alloc_upnodes += 1000;
  82. Plus->uplist.upnodes =
  83. (int *)G_realloc(Plus->uplist.upnodes,
  84. Plus->uplist.alloc_upnodes * sizeof(int));
  85. }
  86. Plus->uplist.upnodes[Plus->uplist.n_upnodes] = node;
  87. Plus->uplist.n_upnodes++;
  88. }