segment.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /****************************************************************
  2. * *
  3. * segment.c in ~/src/Glos *
  4. * *
  5. * This function picks up all the points in one segment *
  6. * and performs los analysis on them. *
  7. * *
  8. ****************************************************************/
  9. #include <grass/segment.h>
  10. #include "point.h"
  11. #define NEXT_PT PRESENT_PT->next
  12. #define NEXT_PT_BACK_PTR PRESENT_PT->next->previous
  13. #define HEAD_BACK_PTR head->previous
  14. struct point *segment(int segment_no, int xmax, int ymax,
  15. double slope_1, double slope_2, int flip,
  16. int sign_on_y, int sign_on_x, int viewpt_elev,
  17. SEGMENT * seg_in_p, SEGMENT * seg_out_p,
  18. SEGMENT * seg_patt_p, int row_viewpt, int col_viewpt,
  19. int patt_flag, int docurv, double ellps_a)
  20. {
  21. int lower_limit_y, upper_limit_y, less, x, y,
  22. x_actual, y_actual, x_flip, y_flip;
  23. struct point *head = (struct point *)NULL, *PRESENT_PT;
  24. int quadrant;
  25. /* decide which one of the four quadrants */
  26. quadrant = 1 + (segment_no - 1) / 4;
  27. if (slope_1 != 0) {
  28. less = ymax / slope_1 + 0.99;
  29. xmax = (xmax <= less) ? xmax : less;
  30. }
  31. /* outer loop over x coors for picking up points */
  32. for (x = xmax; x > 0; x--) {
  33. /* calculate limits for range of y for a single x */
  34. lower_limit_y = x * slope_1 + 0.9;
  35. upper_limit_y = x * slope_2;
  36. upper_limit_y = (upper_limit_y <= ymax) ? upper_limit_y : ymax;
  37. /* loop over y range to pick up correct points */
  38. for (y = upper_limit_y; y >= lower_limit_y; y--) {
  39. /* calculate actual x, y that lie in current segment */
  40. if (flip == 0) {
  41. x_flip = x;
  42. y_flip = y;
  43. }
  44. else {
  45. y_flip = x;
  46. x_flip = y;
  47. }
  48. x_actual = sign_on_x * x_flip;
  49. y_actual = sign_on_y * y_flip;
  50. /* add chosen point to the point list */
  51. head = make_list(head, y_actual, x_actual, seg_in_p,
  52. viewpt_elev, quadrant, row_viewpt, col_viewpt,
  53. docurv, ellps_a);
  54. }
  55. } /* end of outer loop */
  56. if (head != NULL) {
  57. /* assign back pointers in linked list */
  58. HEAD_BACK_PTR = NULL;
  59. PRESENT_PT = head;
  60. while (NEXT_PT != NULL) {
  61. NEXT_PT_BACK_PTR = PRESENT_PT;
  62. PRESENT_PT = NEXT_PT;
  63. }
  64. head = hidden_point_elimination(head, viewpt_elev,
  65. seg_in_p, seg_out_p, seg_patt_p,
  66. quadrant, sign_on_y, sign_on_x,
  67. row_viewpt, col_viewpt, patt_flag,
  68. docurv, ellps_a);
  69. }
  70. return (head);
  71. }