box.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <stdlib.h>
  18. #include <grass/vector.h>
  19. /*
  20. * dig_line_box ()
  21. * set box to points extent
  22. */
  23. int dig_line_box(const struct line_pnts *Points, struct bound_box * Box)
  24. {
  25. int i;
  26. if (Points->n_points <= 0) {
  27. Box->N = 0;
  28. Box->S = 0;
  29. Box->E = 0;
  30. Box->W = 0;
  31. Box->T = 0;
  32. Box->B = 0;
  33. return 0;
  34. }
  35. Box->E = Points->x[0];
  36. Box->W = Points->x[0];
  37. Box->N = Points->y[0];
  38. Box->S = Points->y[0];
  39. Box->T = Points->z[0];
  40. Box->B = Points->z[0];
  41. for (i = 1; i < Points->n_points; i++) {
  42. if (Points->x[i] > Box->E)
  43. Box->E = Points->x[i];
  44. else if (Points->x[i] < Box->W)
  45. Box->W = Points->x[i];
  46. if (Points->y[i] > Box->N)
  47. Box->N = Points->y[i];
  48. else if (Points->y[i] < Box->S)
  49. Box->S = Points->y[i];
  50. if (Points->z[i] > Box->T)
  51. Box->T = Points->z[i];
  52. else if (Points->z[i] < Box->B)
  53. Box->B = Points->z[i];
  54. }
  55. return 1;
  56. }
  57. /*
  58. * dig_box_copy ()
  59. * Copy B to A.
  60. */
  61. int dig_box_copy(struct bound_box * A, struct bound_box * B)
  62. {
  63. A->N = B->N;
  64. A->S = B->S;
  65. A->E = B->E;
  66. A->W = B->W;
  67. A->T = B->T;
  68. A->B = B->B;
  69. return 1;
  70. }
  71. /*
  72. * dig_box_extend ()
  73. * Extend A by B.
  74. */
  75. int dig_box_extend(struct bound_box * A, struct bound_box * B)
  76. {
  77. if (B->N > A->N)
  78. A->N = B->N;
  79. if (B->S < A->S)
  80. A->S = B->S;
  81. if (B->E > A->E)
  82. A->E = B->E;
  83. if (B->W < A->W)
  84. A->W = B->W;
  85. if (B->T > A->T)
  86. A->T = B->T;
  87. if (B->B < A->B)
  88. A->B = B->B;
  89. return 1;
  90. }