sw_output.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <float.h>
  4. #include <grass/vector.h>
  5. #include "sw_defs.h"
  6. #include "write.h"
  7. int openpl(void)
  8. {
  9. return 0;
  10. }
  11. int line(int a, int b, int c, int d)
  12. {
  13. return 0;
  14. }
  15. int circle(int a, int b, int c)
  16. {
  17. return 0;
  18. }
  19. int range(int a, int b, int c, int d)
  20. {
  21. return 0;
  22. }
  23. double pxmin, pxmax, pymin, pymax, cradius;
  24. int out_bisector(struct Edge *e)
  25. {
  26. if (triangulate & plot & !debug) {
  27. line(e->reg[0]->coord.x, e->reg[0]->coord.y, e->reg[1]->coord.x,
  28. e->reg[1]->coord.y);
  29. }
  30. /*
  31. if(!triangulate & !plot &!debug) {
  32. fprintf (stdout,"l %.*g %.*g %.*g \n", DBL_DIG, e->a, DBL_DIG, e->b, DBL_DIG, e->c);
  33. }
  34. if(debug) {
  35. fprintf (stdout,"line(%d) %gx+%gy=%g, bisecting %d %d\n", e->edgenbr,
  36. e->a, e->b, e->c, e->reg[le]->sitenbr, e->reg[re]->sitenbr);
  37. }
  38. */
  39. return 0;
  40. }
  41. int out_ep(struct Edge *e)
  42. {
  43. static struct line_pnts *Points = NULL;
  44. static struct line_cats *Cats = NULL;
  45. if (!Points) {
  46. Points = Vect_new_line_struct();
  47. Cats = Vect_new_cats_struct();
  48. }
  49. if (!triangulate & plot)
  50. clip_line(e);
  51. if (!triangulate & !plot) {
  52. /*
  53. fprintf (stdout,"e %d", e->edgenbr);
  54. fprintf (stdout," %d ", e->ep[le] != (struct Site *)NULL ? e->ep[le]->sitenbr : -1);
  55. fprintf (stdout,"%d\n", e->ep[re] != (struct Site *)NULL ? e->ep[re]->sitenbr : -1);
  56. */
  57. write_ep(e);
  58. }
  59. return 0;
  60. }
  61. int out_vertex(struct Site *v)
  62. {
  63. /*
  64. if(!triangulate & !plot &!debug)
  65. fprintf (stdout,"v %.*g %.*g\n", DBL_DIG, v->coord.x, DBL_DIG, v->coord.y);
  66. if(debug)
  67. fprintf (stdout,"vertex(%d) at %f %f\n", v->sitenbr, v->coord.x, v->coord.y);
  68. */
  69. return 0;
  70. }
  71. int out_site(struct Site *s)
  72. {
  73. if (!triangulate & plot & !debug)
  74. circle(s->coord.x, s->coord.y, cradius);
  75. /*
  76. if(!triangulate & !plot & !debug)
  77. fprintf (stdout,"s %f %f\n", s->coord.x, s->coord.y);
  78. if(debug)
  79. fprintf (stdout,"site (%d) at %f %f\n", s->sitenbr, s->coord.x, s->coord.y);
  80. */
  81. return 0;
  82. }
  83. int out_triple(struct Site *s1, struct Site *s2, struct Site *s3)
  84. {
  85. if (triangulate & !plot & !debug) {
  86. /* fprintf (stdout,"%d %d %d\n", s1->sitenbr, s2->sitenbr, s3->sitenbr); */
  87. write_triple(s1, s2, s3);
  88. }
  89. /*
  90. if(debug)
  91. fprintf (stdout,"circle through left=%d right=%d bottom=%d\n",
  92. s1->sitenbr, s2->sitenbr, s3->sitenbr);
  93. */
  94. return 0;
  95. }
  96. int plotinit(void)
  97. {
  98. double dx, dy, d;
  99. dy = ymax - ymin;
  100. dx = xmax - xmin;
  101. d = (dx > dy ? dx : dy) * 1.1;
  102. pxmin = xmin - (d - dx) / 2.0;
  103. pxmax = xmax + (d - dx) / 2.0;
  104. pymin = ymin - (d - dy) / 2.0;
  105. pymax = ymax + (d - dy) / 2.0;
  106. cradius = (pxmax - pxmin) / 350.0;
  107. openpl();
  108. range(pxmin, pymin, pxmax, pymax);
  109. return 0;
  110. }
  111. int clip_line(struct Edge *e)
  112. {
  113. struct Site *s1, *s2;
  114. double x1, x2, y1, y2;
  115. if (e->a == 1.0 && e->b >= 0.0) {
  116. s1 = e->ep[1];
  117. s2 = e->ep[0];
  118. }
  119. else {
  120. s1 = e->ep[0];
  121. s2 = e->ep[1];
  122. }
  123. if (e->a == 1.0) {
  124. y1 = pymin;
  125. if (s1 != (struct Site *)NULL && s1->coord.y > pymin)
  126. y1 = s1->coord.y;
  127. if (y1 > pymax)
  128. return -1;
  129. x1 = e->c - e->b * y1;
  130. y2 = pymax;
  131. if (s2 != (struct Site *)NULL && s2->coord.y < pymax)
  132. y2 = s2->coord.y;
  133. if (y2 < pymin)
  134. return (0);
  135. x2 = e->c - e->b * y2;
  136. if (((x1 > pxmax) & (x2 > pxmax)) | ((x1 < pxmin) & (x2 < pxmin)))
  137. return -1;
  138. if (x1 > pxmax) {
  139. x1 = pxmax;
  140. y1 = (e->c - x1) / e->b;
  141. }
  142. if (x1 < pxmin) {
  143. x1 = pxmin;
  144. y1 = (e->c - x1) / e->b;
  145. }
  146. if (x2 > pxmax) {
  147. x2 = pxmax;
  148. y2 = (e->c - x2) / e->b;
  149. }
  150. if (x2 < pxmin) {
  151. x2 = pxmin;
  152. y2 = (e->c - x2) / e->b;
  153. }
  154. }
  155. else {
  156. x1 = pxmin;
  157. if (s1 != (struct Site *)NULL && s1->coord.x > pxmin)
  158. x1 = s1->coord.x;
  159. if (x1 > pxmax)
  160. return (0);
  161. y1 = e->c - e->a * x1;
  162. x2 = pxmax;
  163. if (s2 != (struct Site *)NULL && s2->coord.x < pxmax)
  164. x2 = s2->coord.x;
  165. if (x2 < pxmin)
  166. return (0);
  167. y2 = e->c - e->a * x2;
  168. if (((y1 > pymax) & (y2 > pymax)) | ((y1 < pymin) & (y2 < pymin)))
  169. return 0;
  170. if (y1 > pymax) {
  171. y1 = pymax;
  172. x1 = (e->c - y1) / e->a;
  173. }
  174. if (y1 < pymin) {
  175. y1 = pymin;
  176. x1 = (e->c - y1) / e->a;
  177. }
  178. if (y2 > pymax) {
  179. y2 = pymax;
  180. x2 = (e->c - y2) / e->a;
  181. }
  182. if (y2 < pymin) {
  183. y2 = pymin;
  184. x2 = (e->c - y2) / e->a;
  185. }
  186. }
  187. line(x1, y1, x2, y2);
  188. return 0;
  189. }