box.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. ****************************************************************************
  3. *
  4. * MODULE: Vector library
  5. *
  6. * AUTHOR(S): Radim Blazek
  7. *
  8. * PURPOSE: Lower level functions for reading/writing/manipulating vectors.
  9. *
  10. * COPYRIGHT: (C) 2001 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. *****************************************************************************/
  17. #include <grass/config.h>
  18. #include <stdlib.h>
  19. #include <grass/Vect.h>
  20. /*
  21. * dig_line_box ()
  22. * set box to points extent
  23. */
  24. int dig_line_box(const struct line_pnts *Points, BOUND_BOX * Box)
  25. {
  26. int i;
  27. if (Points->n_points <= 0) {
  28. Box->N = 0;
  29. Box->S = 0;
  30. Box->E = 0;
  31. Box->W = 0;
  32. Box->T = 0;
  33. Box->B = 0;
  34. return 0;
  35. }
  36. Box->E = Points->x[0];
  37. Box->W = Points->x[0];
  38. Box->N = Points->y[0];
  39. Box->S = Points->y[0];
  40. Box->T = Points->z[0];
  41. Box->B = Points->z[0];
  42. for (i = 1; i < Points->n_points; i++) {
  43. if (Points->x[i] > Box->E)
  44. Box->E = Points->x[i];
  45. else if (Points->x[i] < Box->W)
  46. Box->W = Points->x[i];
  47. if (Points->y[i] > Box->N)
  48. Box->N = Points->y[i];
  49. else if (Points->y[i] < Box->S)
  50. Box->S = Points->y[i];
  51. if (Points->z[i] > Box->T)
  52. Box->T = Points->z[i];
  53. else if (Points->z[i] < Box->B)
  54. Box->B = Points->z[i];
  55. }
  56. return 1;
  57. }
  58. /*
  59. * dig_box_copy ()
  60. * Copy B to A.
  61. */
  62. int dig_box_copy(BOUND_BOX * A, BOUND_BOX * B)
  63. {
  64. A->N = B->N;
  65. A->S = B->S;
  66. A->E = B->E;
  67. A->W = B->W;
  68. A->T = B->T;
  69. A->B = B->B;
  70. return 1;
  71. }
  72. /*
  73. * dig_box_extend ()
  74. * Extend A by B.
  75. */
  76. int dig_box_extend(BOUND_BOX * A, BOUND_BOX * B)
  77. {
  78. if (B->N > A->N)
  79. A->N = B->N;
  80. if (B->S < A->S)
  81. A->S = B->S;
  82. if (B->E > A->E)
  83. A->E = B->E;
  84. if (B->W < A->W)
  85. A->W = B->W;
  86. if (B->T > A->T)
  87. A->T = B->T;
  88. if (B->B < A->B)
  89. A->B = B->B;
  90. return 1;
  91. }