update.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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, off_t offset)
  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. Plus->uplist.uplines_offset[i] = offset;
  39. G_debug(3, "\tskipped");
  40. return;
  41. }
  42. }
  43. /* Alloc space if needed */
  44. if (Plus->uplist.n_uplines == Plus->uplist.alloc_uplines) {
  45. Plus->uplist.alloc_uplines += 1000;
  46. Plus->uplist.uplines =
  47. (int *)G_realloc(Plus->uplist.uplines,
  48. Plus->uplist.alloc_uplines * sizeof(int));
  49. Plus->uplist.uplines_offset =
  50. (off_t *)G_realloc(Plus->uplist.uplines_offset,
  51. Plus->uplist.alloc_uplines * sizeof(off_t));
  52. }
  53. Plus->uplist.uplines[Plus->uplist.n_uplines] = line;
  54. Plus->uplist.uplines_offset[Plus->uplist.n_uplines] = offset;
  55. Plus->uplist.n_uplines++;
  56. }
  57. /*!
  58. \brief Reset number of updated nodes
  59. \param Plus pointer to Plus_head structure
  60. */
  61. void dig_node_reset_updated(struct Plus_head *Plus)
  62. {
  63. Plus->uplist.n_upnodes = 0;
  64. }
  65. /*!
  66. \brief Add node to updated
  67. \param Plus pointer to Plus_head structure
  68. \param node node id
  69. */
  70. void dig_node_add_updated(struct Plus_head *Plus, int node)
  71. {
  72. int i;
  73. G_debug(3, "dig_node_add_updated(): node = %d", node);
  74. /* Check if already in list */
  75. for (i = 0; i < Plus->uplist.n_upnodes; i++) {
  76. if (abs(Plus->uplist.upnodes[i]) == abs(node)) {
  77. G_debug(3, "\tskipped");
  78. return;
  79. }
  80. }
  81. /* Alloc space if needed */
  82. if (Plus->uplist.n_upnodes == Plus->uplist.alloc_upnodes) {
  83. Plus->uplist.alloc_upnodes += 1000;
  84. Plus->uplist.upnodes =
  85. (int *)G_realloc(Plus->uplist.upnodes,
  86. Plus->uplist.alloc_upnodes * sizeof(int));
  87. }
  88. Plus->uplist.upnodes[Plus->uplist.n_upnodes] = node;
  89. Plus->uplist.n_upnodes++;
  90. }