home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 2 / LSD and 17bit Compendium Deluxe - Volume II.iso / a / prog / cprog / voronoi.lha / output.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-19  |  3.2 KB  |  152 lines

  1. #
  2. #include "defs.h"
  3. #include <stdio.h>
  4. /* for those who don't have Cherry's plot */
  5. /* #include <plot.h> */
  6. openpl(){}
  7. line(){}
  8. circle(){}
  9. range(){}
  10.  
  11. float pxmin, pxmax, pymin, pymax, cradius;
  12.  
  13. out_bisector(e)
  14. struct Edge *e;
  15. {
  16. if(triangulate & plot &!debug)
  17.     line(e->reg[0]->coord.x, e->reg[0]->coord.y, 
  18.          e->reg[1]->coord.x, e->reg[1]->coord.y);
  19. if(!triangulate & !plot &!debug)
  20.     printf("l %f %f %f", e->a, e->b, e->c);
  21. if(debug)
  22.     printf("line(%d) %gx+%gy=%g, bisecting %d %d\n", e->edgenbr,
  23.         e->a, e->b, e->c, e->reg[le]->sitenbr, e->reg[re]->sitenbr);
  24. }
  25.  
  26.  
  27. out_ep(e)
  28. struct Edge *e;
  29. {
  30. if(!triangulate & plot) 
  31.     clip_line(e);
  32. if(!triangulate & !plot)
  33. {    printf("e %d", e->edgenbr);
  34.     printf(" %d ", e->ep[le] != (struct Site *)NULL ? e->ep[le]->sitenbr : -1);
  35.     printf("%d\n", e->ep[re] != (struct Site *)NULL ? e->ep[re]->sitenbr : -1);
  36. };
  37. }
  38.  
  39. out_vertex(v)
  40. struct Site *v;
  41. {
  42. if(!triangulate & !plot &!debug)
  43.     printf ("v %f %f\n", v->coord.x, v->coord.y);
  44. if(debug)
  45.     printf("vertex(%d) at %f %f\n", v->sitenbr, v->coord.x, v->coord.y);
  46. }
  47.  
  48.  
  49. out_site(s)
  50. struct Site *s;
  51. {
  52. if(!triangulate & plot & !debug)
  53.     circle (s->coord.x, s->coord.y, cradius);
  54. if(!triangulate & !plot & !debug)
  55.     printf("s %f %f\n", s->coord.x, s->coord.y);
  56. if(debug)
  57.     printf("site (%d) at %f %f\n", s->sitenbr, s->coord.x, s->coord.y);
  58. }
  59.  
  60.  
  61. out_triple(s1, s2, s3)
  62. struct Site *s1, *s2, *s3;
  63. {
  64. if(triangulate & !plot &!debug)
  65.     printf("%d %d %d\n", s1->sitenbr, s2->sitenbr, s3->sitenbr);
  66. if(debug)
  67.     printf("circle through left=%d right=%d bottom=%d\n", 
  68.         s1->sitenbr, s2->sitenbr, s3->sitenbr);
  69. }
  70.  
  71.  
  72.  
  73. plotinit()
  74. {
  75. float dx,dy,d;
  76.  
  77. dy = ymax - ymin;
  78. dx = xmax - xmin;
  79. d = ( dx > dy ? dx : dy) * 1.1;
  80. pxmin = xmin - (d-dx)/2.0;
  81. pxmax = xmax + (d-dx)/2.0;
  82. pymin = ymin - (d-dy)/2.0;
  83. pymax = ymax + (d-dy)/2.0;
  84. cradius = (pxmax - pxmin)/350.0;
  85. openpl();
  86. range(pxmin, pymin, pxmax, pymax);
  87. }
  88.  
  89.  
  90. int clip_line(e)
  91. struct Edge *e;
  92. {
  93. struct Site *s1, *s2;
  94. float x1,x2,y1,y2;
  95.  
  96.     if(e -> a == 1.0 && e ->b >= 0.0)
  97.     {    s1 = e -> ep[1];
  98.         s2 = e -> ep[0];
  99.     }
  100.     else 
  101.     {    s1 = e -> ep[0];
  102.         s2 = e -> ep[1];
  103.     };
  104.  
  105.     if(e -> a == 1.0)
  106.     {
  107.         y1 = pymin;
  108.         if (s1!=(struct Site *)NULL && s1->coord.y > pymin)
  109.              y1 = s1->coord.y;
  110.         if(y1>pymax) return;
  111.         x1 = e -> c - e -> b * y1;
  112.         y2 = pymax;
  113.         if (s2!=(struct Site *)NULL && s2->coord.y < pymax) 
  114.             y2 = s2->coord.y;
  115.         if(y2<pymin) return(0);
  116.         x2 = e -> c - e -> b * y2;
  117.         if ((x1> pxmax & x2>pxmax) | (x1<pxmin&x2<pxmin)) return;
  118.         if(x1> pxmax)
  119.         {    x1 = pxmax; y1 = (e -> c - x1)/e -> b;};
  120.         if(x1<pxmin)
  121.         {    x1 = pxmin; y1 = (e -> c - x1)/e -> b;};
  122.         if(x2>pxmax)
  123.         {    x2 = pxmax; y2 = (e -> c - x2)/e -> b;};
  124.         if(x2<pxmin)
  125.         {    x2 = pxmin; y2 = (e -> c - x2)/e -> b;};
  126.     }
  127.     else
  128.     {
  129.         x1 = pxmin;
  130.         if (s1!=(struct Site *)NULL && s1->coord.x > pxmin) 
  131.             x1 = s1->coord.x;
  132.         if(x1>pxmax) return(0);
  133.         y1 = e -> c - e -> a * x1;
  134.         x2 = pxmax;
  135.         if (s2!=(struct Site *)NULL && s2->coord.x < pxmax) 
  136.             x2 = s2->coord.x;
  137.         if(x2<pxmin) return(0);
  138.         y2 = e -> c - e -> a * x2;
  139.         if ((y1> pymax & y2>pymax) | (y1<pymin&y2<pymin)) return(0);
  140.         if(y1> pymax)
  141.         {    y1 = pymax; x1 = (e -> c - y1)/e -> a;};
  142.         if(y1<pymin)
  143.         {    y1 = pymin; x1 = (e -> c - y1)/e -> a;};
  144.         if(y2>pymax)
  145.         {    y2 = pymax; x2 = (e -> c - y2)/e -> a;};
  146.         if(y2<pymin)
  147.         {    y2 = pymin; x2 = (e -> c - y2)/e -> a;};
  148.     };
  149.     
  150.     line(x1,y1,x2,y2);
  151. }
  152.