lilypond-1.3.20
[lilypond.git] / test / bow.cc
blob418538880e97674b8058e65e6b6063d4c2623f8d
1 // vim:sw=2 makeprg=g++\ -g\ bow.cc\ -o\ bow
2 #include <iostream.h>
3 #define PT
4 // #define STAFFHEIGHT 16.0
5 #define STAFFHEIGHT 20.0
7 #define UP 1
8 #define DOWN (-1)
10 // mmm
11 #define STANDALONE
13 #include <math.h>
15 typedef void *Paper_def;
17 bool experimental_features_global_b = true;
18 //bool experimental_features_global_b = false;
20 #include "bezier.hh"
22 #if 0
23 #include "offset.cc"
24 #include "interval.cc"
25 #endif
27 #include "misc.cc"
28 #include "bezier.cc"
30 struct Point
32 Real x, y;
35 void
36 out (Bezier_bow& b)
38 cout << "save dx,dy,x,y;\n";
39 for (int i = 0; i < 4; i++)
40 cout << "z" << i + 1 << " = (" << b.control_[i].x ()
41 << ", " << b.control_[i].y () << ");\n";
42 for (int i = 1; i < 3; i++)
43 cout << "z" << i + 4 << " = (" << b.return_[i].x ()
44 << ", " << b.return_[i].y () << ");\n";
45 #if 0
46 cout << "pickup pencircle scaled 0.5pt#;\n";
47 cout << "draw z2--z3; draw (50,0)-- 0.5[z2,z3];\n";
48 #endif
49 cout << "pickup pencircle scaled 4pt#;\n";
50 for (int i = 0; i < 4; i++)
51 cout << "drawdot z" << i + 1 << ";\n";
52 cout << "path boogje;\n";
53 #if 0
54 cout << "pickup pencircle scaled 0.4pt#;\n";
55 cout << "boogje=z1..controls z2 and z3..z4..controls z5 and z6..cycle;\n";
56 cout << "filldraw boogje;\n";
57 #else
58 cout << "pickup pencircle scaled 1.6pt#;\n";
59 cout << "boogje=z1..controls z2 and z3..z4;\n";
60 cout << "draw boogje;\n";
61 cout << "pickup pencircle scaled 0.4pt#;\n";
62 cout << "boogje:=z4..controls z5 and z6..z1;\n";
63 cout << "draw boogje;\n";
64 #endif
65 cout << "showit; shipit;clearit;" << endl;
68 void
69 bow (Point* points, int n, int d)
71 Array<Offset> notes;
72 for (int i = 0; i < n; i++)
73 notes.push (Offset (points[i].x, points[i].y));
74 #if 1
75 cout << "pickup pencircle scaled 8pt#;\n";
76 #else
77 cout << "pickup pencircle scaled 2pt#;\n";
78 #endif
79 for (int i = 0; i < n; i++)
80 cout << "drawdot (" << notes[i].x () << ", " << notes[i].y () << ");\n";
81 Bezier_bow b (0);
82 b.set (notes, d);
83 b.calc ();
84 out (b);
85 return;
88 int
89 main ()
91 //cout.unsetf(ios::scientific);
92 cout.setf(ios::fixed);
93 #if 1
94 bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,0, 100,1 }, 6, 1);
95 bow ((Point[6]){ 0,0, 20,0, 40,30, 60,30, 80,0, 100,1 }, 6, 1);
96 bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,10, 100,1 }, 6, 1);
97 bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,40, 100,1 }, 6, 1);
98 bow ((Point[6]){ 0,0, 20,0, 40,0, 60,40, 80,0, 100,1 }, 6, 1);
99 bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, 1);
100 bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, -1);
101 bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,100 }, 6, -1);
102 bow ((Point[9]){ 0,0, 20,0, 40,-80, 60,0, 80,0, 100,0, 120,0, 140,0, 160,-1 }, 9, -1);
103 bow ((Point[9]){ 0,0, 40,0, 80,180, 120,0, 160,0, 200,0, 240,0, 280,0, 320,1 }, 9, 1);
104 bow ((Point[9]){
105 {0, 0},
106 {19.10645980317711, 1},
107 {29.402919606354207, 28},
108 {55.389379409531308, 1},
109 {73.530839212708514, 1},
110 {91.672299015885727, 1},
111 {111.35901367452229, 1},
112 {131.04572833315891, 1},
113 {145.76744299179552, 0}
115 9, 1);
116 bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,0, 100,40 }, 6, 1);
117 bow ((Point[2]){ 0,0, 20,0 }, 2, 1);
118 bow ((Point[2]){ 0,0, 20,-10 }, 2, 1);
119 bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,0, 100,100 }, 6, 1);
121 bow ((Point[6]){ 0,0, 20,-10, 40,20, 60,-20, 80,20, 100,0 }, 6, 1);
122 bow ((Point[6]){ 0,0, 20,-10, 40,20, 60,-20, 80,20, 100,0 }, 6, -1);
123 bow ((Point[6]){ 0,0, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, 1);
124 bow ((Point[6]){ 0,0, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, -1);
125 bow ((Point[6]){ 0,0, 20,20, 40,0, 60,40, 80,20, 100,100 }, 6, -1);
127 bow ((Point[6]){ 0,-10, 20,-20, 40,0, 60,-40, 80,-20, 100,-50 }, 6, 1);
129 bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, -1);
130 #endif
132 #if 1
133 //clipping
135 bow ((Point[6]){ 0,0, 20,60, 40,0, 60,0, 80,0, 100,1 }, 6, 1);
137 bow ((Point[6]){ 0,1, 20,0, 40,0, 60,0, 80,60, 100,0 }, 6, 1);
138 bow ((Point[6]){ 0,0, 20,20, 40,40, 60,60, 80,140, 100,100 }, 6, 1);
139 bow ((Point[6]){ 0,0, 20,20, 40,40, 60,60, 80,20, 100,100 }, 6, -1);
140 bow ((Point[6]){ 0,0, 20,-20, 40,-40, 60,-60, 80,-20, 100,-100 }, 6, 1);
141 bow ((Point[6]){ 0,0, 20,-20, 40,-40, 60,-60, 80,-140, 100,-100 }, 6, -1);
142 bow ((Point[7]){ 0,0, 20,40, 100,0, 150,0, 200,0, 280,40, 300,0 }, 7, 1);
143 bow ((Point[7]){ 0,0, 20,-40, 100,0, 150,0, 200,0, 280,-40, 300,0 }, 7, -1);
144 bow ((Point[7]){ 0,20, 20,40, 100,0, 150,0, 200,0, 280,40, 300,20 }, 7, 1);
145 bow ((Point[3]){ 0,0, 10,10, 20,-20 }, 3, 1);
147 bow ((Point[4]){ 0,0, 33,100, 75,0, 100,100 }, 4, -1);
148 bow ((Point[4]){ 0,0, 33,-100, 75,0, 100,-100 }, 4, 1);
149 #endif
151 #if 1
152 // infeasible
154 bow ((Point[6]){ 0,0, 20,20, 40,40, 60,60, 80,140, 100,100 }, 6, 1);
155 bow ((Point[6]){ 0,0, 20,-40, 40,0, 60,20, 80,20, 100,40 }, 6, -1);
156 bow ((Point[6]){ 0,0, 20,-20, 40,-20, 60,-20, 80,-80, 100,-40 }, 6, -1);
157 bow ((Point[6]){ 0,0, 20,-20, 40,-40, 60,-60, 80,-140, 100,-100 }, 6, -1);
158 bow ((Point[6]){ 0,0, 20,20, 40,40, 60,60, 80,140, 100,100 }, 6, 1);
159 #endif
161 cout << "\\end" << endl;
163 return 0;