update.c 2.4 KB

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