delete.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /****************************************************************/
  2. /* */
  3. /* delete.c in ~/src/Glos */
  4. /* */
  5. /* This function detaches a point data structure from */
  6. /* the linked list and frees memory allocated for it. */
  7. /* */
  8. /****************************************************************/
  9. #include <stdlib.h>
  10. #include <grass/gis.h>
  11. #include <grass/raster.h>
  12. #include <grass/segment.h>
  13. #include "point.h"
  14. #define PT_TO_DELETE_X PT_TO_DELETE->x
  15. #define PT_TO_DELETE_Y PT_TO_DELETE->y
  16. #define PT_NEXT_TO_DELETED PT_TO_DELETE->next
  17. #define PT_PREVIOUS_TO_DELETED PT_TO_DELETE->previous
  18. #define NEXT_PT_BACK_PTR PT_TO_DELETE->next->previous
  19. #define PREVIOUS_PT_NEXT_PTR PT_TO_DELETE->previous->next
  20. struct point *delete(struct point *PT_TO_DELETE, struct point *head,
  21. SEGMENT * seg_out_p, int row_viewpt, int col_viewpt)
  22. {
  23. FCELL data;
  24. FCELL *value;
  25. /* mark deleted points by light brownish color */
  26. data = 1;
  27. value = &data;
  28. segment_put(seg_out_p, value,
  29. row_viewpt - PT_TO_DELETE_Y, PT_TO_DELETE_X + col_viewpt);
  30. /* If first and last point. This fixes a bug in r.los. See pts_elim.c for details */
  31. if ((PT_TO_DELETE == head) && (PT_NEXT_TO_DELETED == NULL)) {
  32. NEXT_PT_BACK_PTR = NULL;
  33. head = PT_NEXT_TO_DELETED;
  34. G_free(PT_TO_DELETE);
  35. return (head);
  36. }
  37. if (PT_TO_DELETE == head) { /* first one ? */
  38. NEXT_PT_BACK_PTR = NULL;
  39. head = PT_NEXT_TO_DELETED;
  40. /*
  41. We cannot delete this point right now, as pts_elim.c might still
  42. reference it. Thus, we only mark it for deletion now by pointing
  43. the global DELAYED_DELETE to it and free it the next time we
  44. get here!
  45. */
  46. if ( DELAYED_DELETE != NULL ) {
  47. G_free ( DELAYED_DELETE );
  48. DELAYED_DELETE = NULL;
  49. } else {
  50. if ( PT_TO_DELETE != NULL ) {
  51. DELAYED_DELETE = PT_TO_DELETE;
  52. }
  53. }
  54. return (head);
  55. }
  56. /* If last point. This fixes a bug in r.los. See pts_elim.c for details */
  57. if (PT_NEXT_TO_DELETED == NULL) {
  58. PREVIOUS_PT_NEXT_PTR = PT_NEXT_TO_DELETED;
  59. G_free(PT_TO_DELETE);
  60. return (head);
  61. }
  62. /* otherwise */
  63. NEXT_PT_BACK_PTR = PT_PREVIOUS_TO_DELETED;
  64. PREVIOUS_PT_NEXT_PTR = PT_NEXT_TO_DELETED;
  65. /*
  66. We cannot delete this point right now, as pts_elim.c might still
  67. reference it. Thus, we only mark it for deletion now by pointing
  68. the global DELAYED_DELETE to it and free it the next time we
  69. get here!
  70. */
  71. if ( DELAYED_DELETE != NULL ) {
  72. G_free ( DELAYED_DELETE );
  73. DELAYED_DELETE = NULL;
  74. } else {
  75. if ( PT_TO_DELETE != NULL ) {
  76. DELAYED_DELETE = PT_TO_DELETE;
  77. }
  78. }
  79. return (head);
  80. }
  81. /************* END OF FUNCTION "DELETE" *************************/