home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / prog / graphics / segment_.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  2.0 KB  |  104 lines

  1. #include <LEDA/segment_set.h>
  2. #include <LEDA/window.h>
  3.  
  4. #include <math.h>
  5.  
  6.  
  7. declare(segment_set,real)
  8.  
  9.  
  10. main()
  11.   segment s,x;
  12.  
  13.   window W;
  14.  
  15.   W.init(-1000,1000,-1000);
  16.  
  17.   W.set_line_width(1);
  18.  
  19.   panel P("SEGMENT SET");
  20.   
  21.   P.text_item("Use the left mouse button to insert a set of segments, ");
  22.   P.text_item("all with the same orientation. Terminate the input by  ");
  23.   P.text_item("clicking the right button. During input, the segments  ");
  24.   P.text_item("are rotated to be parallel to the first read segment.  ");
  25.   P.text_item("Now you can input orthogonal query segments, for each  ");
  26.   P.text_item("of which the set of intersected segments is computed   ");
  27.   P.text_item("and displayed. To leave the program, click the right   ");
  28.   P.text_item("mouse button.                                          ");
  29.   P.text_item("                                                       ");
  30.  
  31.   P.button("continue");
  32.  
  33.   P.open();
  34.  
  35.  
  36.   W >> s;
  37.   W << s;
  38.  
  39.   real alpha = s.angle();
  40.  
  41.   segment_set(real) S(alpha);
  42.  
  43.   S.insert(s,s.xcoord1());
  44.  
  45.   while (W >> s)
  46.   { point p = s.start();
  47.     point q = p.translate(alpha,s.length());
  48.     s = segment(p,q);
  49.     W << s;
  50.     S.insert(s,s.xcoord1());
  51.  
  52. /*
  53.     W.set_line_style(dashed);
  54.     W<< s.rotate(point(0,0),-alpha);
  55.     W.set_line_style(solid);
  56. */
  57.    }
  58.  
  59.   W.set_mode(xor_mode);
  60.  
  61.   list(seg_item) L;
  62.   seg_item it;
  63.   point p;
  64.  
  65.   s = segment(W.xmin(),W.ymin(),W.xmax(),W.ymin());
  66.  
  67.   while (W >> p)
  68.   { real x,y;
  69.  
  70.     // erase previously found segments
  71.     W.set_line_width(4);
  72.     forall(it,L) W << S.key(it);
  73.     W.set_line_width(1);
  74.     forall(it,L) W << S.key(it);
  75.  
  76.  
  77.     W << s;
  78.  
  79.     W.read_mouse_seg(p.xcoord(),p.ycoord(),x,y);
  80.  
  81.     point q(x,y);
  82.  
  83.     q = p.translate(alpha+M_PI_2,p.distance(q));
  84.    
  85.     s = segment(p,q);
  86.  
  87.     W << s;
  88.  
  89.     L = S.intersection(s);
  90.  
  91.     forall(it,L) W << S.key(it);
  92.     W.set_line_width(4);
  93.     forall(it,L) W << S.key(it);
  94.  
  95.     forall(it,L) 
  96.       cout << "key = " << S.key(it) << "  info = " << S.inf(it) << "\n";
  97.     newline;
  98.  
  99.  
  100.   }
  101.  
  102. }
  103.