vo_write.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <float.h>
  4. #include <grass/gis.h>
  5. #include <grass/vector.h>
  6. #include <grass/display.h>
  7. #include "sw_defs.h"
  8. #include "defs.h"
  9. #include "write.h"
  10. int write_ep(struct Edge *e)
  11. {
  12. static struct line_pnts *Points = NULL;
  13. static struct line_cats *Cats = NULL;
  14. if (!Points) {
  15. Points = Vect_new_line_struct();
  16. Cats = Vect_new_cats_struct();
  17. }
  18. if (!triangulate) {
  19. double x1, y1, x2, y2;
  20. if (e->ep[le] != NULL && e->ep[re] != NULL) { /* both end defined */
  21. x1 = e->ep[le]->coord.x;
  22. y1 = e->ep[le]->coord.y;
  23. x2 = e->ep[re]->coord.x;
  24. y2 = e->ep[re]->coord.y;
  25. if (!Vect_point_in_box(x1, y1, 0.0, &Box) ||
  26. !Vect_point_in_box(x2, y2, 0.0, &Box)) {
  27. Vect_box_clip(&x1, &y1, &x2, &y2, &Box);
  28. }
  29. /* Don't write zero length */
  30. if (x1 == x2 && y1 == y2)
  31. return 0;
  32. Vect_reset_line(Points);
  33. Vect_append_point(Points, x1, y1, 0.0);
  34. Vect_append_point(Points, x2, y2, 0.0);
  35. Vect_write_line(&Out, Type, Points, Cats);
  36. }
  37. else {
  38. int knownPointAtLeft;
  39. if (e->ep[le] != NULL) {
  40. x1 = e->ep[le]->coord.x;
  41. y1 = e->ep[le]->coord.y;
  42. knownPointAtLeft = 1;
  43. }
  44. else {
  45. x1 = e->ep[re]->coord.x;
  46. y1 = e->ep[re]->coord.y;
  47. knownPointAtLeft = 0;
  48. }
  49. if (extend_line(Box.S, Box.N, Box.W, Box.E,
  50. e->a, e->b, e->c, x1, y1, &x2, &y2,
  51. knownPointAtLeft)
  52. ) {
  53. /* Don't write zero length */
  54. if (x1 == x2 && y1 == y2)
  55. return 0;
  56. Vect_reset_line(Points);
  57. Vect_append_point(Points, x1, y1, 0.0);
  58. Vect_append_point(Points, x2, y2, 0.0);
  59. Vect_write_line(&Out, Type, Points, Cats);
  60. }
  61. }
  62. }
  63. return 0;
  64. }