]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
* lily/hairpin.cc: use Line_interface
[lilypond.git] / lily / lookup.cc
1 /*
2   lookup.cc -- implement simple Lookup methods.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8   Jan Nieuwenhuizen <janneke@gnu.org>
9
10   TODO
11       Glissando
12 */
13 #include <math.h>
14 #include <ctype.h>
15
16 #include "warn.hh"
17 #include "dimensions.hh"
18 #include "bezier.hh"
19 #include "string-convert.hh"
20 #include "file-path.hh"
21 #include "main.hh"
22 #include "lily-guile.hh"
23 #include "molecule.hh"
24 #include "lookup.hh"
25 #include "font-metric.hh"
26 #include "interval.hh"
27
28 Molecule
29 Lookup::dot (Offset p, Real radius)
30 {
31   SCM at = (scm_list_n (ly_symbol2scm ("dot"),
32                         gh_double2scm (p[X_AXIS]),
33                         gh_double2scm (p[Y_AXIS]),
34                         gh_double2scm (radius),
35                         SCM_UNDEFINED));
36   Box box;
37   box.add_point (p - Offset (radius, radius));
38   box.add_point (p + Offset (radius, radius));
39   return Molecule (box, at);
40 }
41
42
43
44 /*
45  * Horizontal Slope:
46  *
47  *            /|   ^
48  *           / |   |
49  *          /  |   | height
50  *         /   |   |
51  *        /    |   v
52  *       |    /
53  *       |   /
54  * (0,0) x  /slope=dy/dx
55  *       | /
56  *       |/
57  *
58  *       <----->
59  *        width
60  */
61 Molecule 
62 Lookup::beam (Real slope, Real width, Real thick, Real blot) 
63 {
64   Real height = slope * width; 
65   Real min_y = (0 <? height) - thick/2;
66   Real max_y = (0 >? height) + thick/2;
67
68   Box b (Interval (0, width),
69          Interval (min_y, max_y));
70   
71   SCM at = scm_list_n (ly_symbol2scm ("beam"),
72                     gh_double2scm (width),
73                     gh_double2scm (slope),
74                     gh_double2scm (thick),
75                     gh_double2scm (blot),
76                     SCM_UNDEFINED);
77   return Molecule (b, at);
78 }
79
80 Molecule
81 Lookup::dashed_slur (Bezier b, Real thick, Real dash)
82 {
83   SCM l = SCM_EOL;
84
85   for (int i= 4; i -- ;)
86     {
87       l = gh_cons (ly_offset2scm (b.control_[i]), l);
88     }
89
90   SCM at = (scm_list_n (ly_symbol2scm ("dashed-slur"),
91                                gh_double2scm (thick), 
92                                gh_double2scm (dash),
93                                ly_quote_scm (l),
94                                SCM_UNDEFINED));
95
96   Box box (Interval (0,0),Interval (0,0));
97   return   Molecule (box, at);
98 }
99
100 Molecule
101 Lookup::line (Real th, Offset from, Offset to)
102 {
103   SCM at = scm_list_n (ly_symbol2scm ("draw-line"),
104                         gh_double2scm (th), 
105                         gh_double2scm (from[X_AXIS]),
106                         gh_double2scm (from[Y_AXIS]),
107                         gh_double2scm (to[X_AXIS]),
108                         gh_double2scm (to[Y_AXIS]),
109                         SCM_UNDEFINED);
110
111   Box box;
112   box.add_point (from);
113   box.add_point (to);
114
115   box[X_AXIS].widen (th/2);
116   box[Y_AXIS].widen (th/2);  
117
118   return Molecule (box, at);
119 }
120
121
122 Molecule
123 Lookup::horizontal_line (Interval w, Real th)
124 {
125   SCM at = scm_list_n (ly_symbol2scm ("horizontal-line"),
126                        gh_double2scm (w[LEFT]), 
127                        gh_double2scm (w[RIGHT]),
128                        gh_double2scm (th),
129                        SCM_UNDEFINED);
130
131
132   Box box ;
133   box[X_AXIS] = w;
134   box[Y_AXIS] = Interval (-th/2,th/2);
135
136   return Molecule (box, at);
137 }
138
139
140 Molecule
141 Lookup::blank (Box b) 
142 {
143   return Molecule (b, scm_makfrom0str (""));
144 }
145
146 Molecule
147 Lookup::filled_box (Box b) 
148 {
149   SCM  at  = (scm_list_n (ly_symbol2scm ("filledbox"),
150                      gh_double2scm (-b[X_AXIS][LEFT]),
151                      gh_double2scm (b[X_AXIS][RIGHT]),                 
152                      gh_double2scm (-b[Y_AXIS][DOWN]),
153                      gh_double2scm (b[Y_AXIS][UP]),                    
154                      SCM_UNDEFINED));
155
156   return Molecule (b,at);
157 }
158
159 /*
160  * round filled box:
161  *
162  *   __________________________________
163  *  /     \  ^           /     \      ^
164  * |         |blot              |     |
165  * |       | |dia       |       |     |
166  * |         |meter             |     |
167  * |\ _ _ /  v           \ _ _ /|     |
168  * |                            |     |
169  * |                            |     | Box
170  * |                    <------>|     | extent
171  * |                      blot  |     | (Y_AXIS)
172  * |                    diameter|     |
173  * |                            |     |
174  * |  _ _                  _ _  |     |
175  * |/     \              /     \|     |
176  * |                            |     |
177  * |       |            |       |     |
178  * |                            |     |
179  * x\_____/______________\_____/|_____v
180  * |(0,0)                       |
181  * |                            |
182  * |                            |
183  * |<-------------------------->|
184  *       Box extent(X_AXIS)
185  */
186 Molecule
187 Lookup::round_filled_box (Box b, Real blotdiameter)
188 {
189   if (b.x ().length () < blotdiameter)
190     {
191       programming_error (_f ("round filled box horizontal extent smaller than blot; decreasing blot"));
192       blotdiameter = b.x ().length ();
193     }
194   if (b.y ().length () < blotdiameter)
195     {
196       programming_error (_f ("round filled box vertical extent smaller than blot; decreasing blot"));
197       blotdiameter = b.y ().length ();
198     }
199
200   SCM at = (scm_list_n (ly_symbol2scm ("round-filled-box"),
201                         gh_double2scm (-b[X_AXIS][LEFT]),
202                         gh_double2scm (b[X_AXIS][RIGHT]),
203                         gh_double2scm (-b[Y_AXIS][DOWN]),
204                         gh_double2scm (b[Y_AXIS][UP]),
205                         gh_double2scm (blotdiameter),
206                         SCM_UNDEFINED));
207
208   return Molecule (b,at);
209 }
210
211           
212
213 /*
214  * Create Molecule that represents a filled polygon with round edges.
215  *
216  * LIMITATIONS:
217  *
218  * (a) Only outer (convex) edges are rounded.
219  *
220  * (b) This algorithm works as expected only for polygons whose edges
221  * do not intersect.  For example, the polygon ((0, 0), (q, 0), (0,
222  * q), (q, q)) has an intersection at point (q/2, q/2) and therefore
223  * will give a strange result.  Even non-adjacent edges that just
224  * touch each other will in general not work as expected for non-null
225  * blotdiameter.
226  *
227  * (c) Given a polygon ((x0, y0), (x1, y1), ... , (x(n-1), y(n-1))),
228  * if there is a natural number k such that blotdiameter is greater
229  * than the maximum of { | (x(k mod n), y(k mod n)) - (x((k+1) mod n),
230  * y((k+1) mod n)) |, | (x(k mod n), y(k mod n)) - (x((k+2) mod n),
231  * y((k+2) mod n)) |, | (x((k+1) mod n), y((k+1) mod n)) - (x((k+2)
232  * mod n), y((k+2) mod n)) | }, then the outline of the rounded
233  * polygon will exceed the outline of the core polygon.  In other
234  * words: Do not draw rounded polygons that have a leg smaller or
235  * thinner than blotdiameter (or set blotdiameter to a sufficiently
236  * small value -- maybe even 0.0)!
237  *
238  * NOTE: Limitations (b) and (c) arise from the fact that round edges
239  * are made by moulding sharp edges to round ones rather than adding
240  * to a core filled polygon.  For details of these two different
241  * approaches, see the thread upon the ledger lines patch that started
242  * on March 25, 2002 on the devel mailing list.  The below version of
243  * round_filled_polygon() sticks to the moulding model, which the
244  * majority of the list participants finally voted for.  This,
245  * however, results in the above limitations and a much increased
246  * complexity of the algorithm, since it has to compute a shrinked
247  * polygon -- which is not trivial define precisely and unambigously.
248  * With the other approach, one simply could move a circle of size
249  * blotdiameter along all edges of the polygon (which is what the
250  * postscript routine in the backend effectively does, but on the
251  * shrinked polygon). --jr
252  */
253 Molecule
254 Lookup::round_filled_polygon (Array<Offset> points, Real blotdiameter)
255 {
256   /* TODO: Maybe print a warning if one of the above limitations
257      applies to the given polygon.  However, this is quite complicated
258      to check. */
259
260   /* remove consecutive duplicate points */
261   const Real epsilon = 0.01;
262   for (int i = 0; i < points.size ();)
263     {
264       int next_i = (i + 1) % points.size ();
265       Real d = (points[i] - points[next_i]).length ();
266       if (d < epsilon)
267         points.del (next_i);
268       else
269         i++;
270     }
271
272   /* special cases: degenerated polygons */
273   if (points.size () == 0)
274     return Molecule ();
275   if (points.size () == 1)
276     return dot (points[0], 0.5 * blotdiameter);
277   if (points.size () == 2)
278     return line (blotdiameter, points[0], points[1]);
279
280   /* shrink polygon in size by 0.5 * blotdiameter */
281   Array<Offset> shrinked_points;
282   shrinked_points.set_size (points.size ());
283   bool ccw = 1; // true, if three adjacent points are counterclockwise ordered
284   for (int i = 0; i < points.size (); i++)
285     {
286       int i0 = i;
287       int i1 = (i + 1) % points.size ();
288       int i2 = (i + 2) % points.size ();
289       Offset p0 = points[i0];
290       Offset p1 = points[i1];
291       Offset p2 = points[i2];
292       Offset p10 = p0 - p1;
293       Offset p12 = p2 - p1;
294       if (p10.length () != 0.0)
295         { // recompute ccw
296           Real phi = p10.arg ();
297           // rotate (p2 - p0) by (-phi)
298           Offset q = complex_multiply (p2 - p0, complex_exp (Offset (1.0, -phi)));
299
300           if (q[Y_AXIS] > 0)
301             ccw = 1;
302           else if (q[Y_AXIS] < 0)
303             ccw = 0;
304           else {} // keep ccw unchanged
305         }
306       else {} // keep ccw unchanged
307       Offset p10n = (1.0 / p10.length ()) * p10; // normalize length to 1.0
308       Offset p12n = (1.0 / p12.length ()) * p12;
309       Offset p13n = 0.5 * (p10n + p12n);
310       Offset p14n = 0.5 * (p10n - p12n);
311       Offset p13;
312       Real d = p13n.length () * p14n.length (); // distance p3n to line(p1..p0)
313       if (d < epsilon)
314         // special case: p0, p1, p2 are on a single line => build
315         // vector orthogonal to (p2-p0) of length 0.5 blotdiameter
316         {
317           p13[X_AXIS] = p10[Y_AXIS];
318           p13[Y_AXIS] = -p10[X_AXIS];
319           p13 = (0.5 * blotdiameter / p13.length ()) * p13;
320         }
321       else
322         p13 = (0.5 * blotdiameter / d) * p13n;
323       shrinked_points[i1] = p1 + ((ccw) ? p13 : -p13);
324     }
325
326   /* build scm expression and bounding box */
327   SCM shrinked_points_scm = SCM_EOL;
328   Box box;
329   for (int i = 0; i < shrinked_points.size (); i++)
330     {
331       SCM x = gh_double2scm (shrinked_points[i][X_AXIS]);
332       SCM y = gh_double2scm (shrinked_points[i][Y_AXIS]);
333       shrinked_points_scm = gh_cons (x, gh_cons (y, shrinked_points_scm));
334       box.add_point (points[i]);
335     }
336   SCM polygon_scm = scm_list_n (ly_symbol2scm ("polygon"),
337                                 ly_quote_scm (shrinked_points_scm),
338                                 gh_double2scm (blotdiameter),
339                                 SCM_UNDEFINED);
340
341   Molecule polygon = Molecule (box, polygon_scm);
342   shrinked_points.clear ();
343   return polygon;
344 }
345
346
347 /*
348   TODO: deprecate?
349
350   should use rounded corners.
351  */
352 Molecule
353 Lookup::frame (Box b, Real thick, Real blot)
354 {
355   Molecule m;
356   Direction d = LEFT;
357   for (Axis a = X_AXIS; a < NO_AXES; a = Axis (a + 1))
358     {
359       Axis o = Axis ((a+1)%NO_AXES);
360       do
361         {
362           Box edges;
363           edges[a] = b[a][d] + 0.5 * thick * Interval (-1, 1);
364           edges[o][DOWN] = b[o][DOWN] - thick/2;
365           edges[o][UP] = b[o][UP] + thick/2;      
366           
367           m.add_molecule (round_filled_box (edges, blot));
368         }
369       while (flip (&d) != LEFT);
370     }
371   return m;
372 }
373
374 /*
375   Make a smooth curve along the points 
376  */
377 Molecule
378 Lookup::slur (Bezier curve, Real curvethick, Real linethick) 
379 {
380   Real alpha = (curve.control_[3] - curve.control_[0]).arg ();
381   Bezier back = curve;
382   Offset perp = curvethick * complex_exp (Offset (0, alpha + M_PI/2)) * 0.5;
383   back.reverse ();
384   back.control_[1] += perp;
385   back.control_[2] += perp;
386
387   curve.control_[1] -= perp;
388   curve.control_[2] -= perp;
389   
390   SCM scontrols[8];
391
392   for (int i=4; i--;)
393     scontrols[ i ] = ly_offset2scm (back.control_[i]);
394   for (int i=4 ; i--;)
395     scontrols[i+4] = ly_offset2scm (curve.control_[i]);
396
397   /*
398     Need the weird order b.o. the way PS want its arguments  
399    */
400   int indices[]= {5, 6, 7, 4, 1, 2, 3, 0};
401   SCM list = SCM_EOL;
402   for (int i= 8; i--;)
403     {
404       list = gh_cons (scontrols[indices[i]], list);
405     }
406   
407   
408   SCM at = (scm_list_n (ly_symbol2scm ("bezier-sandwich"),
409                      ly_quote_scm (list),
410                      gh_double2scm (linethick),
411                      SCM_UNDEFINED));
412   Box b(curve.extent (X_AXIS),
413         curve.extent (Y_AXIS));
414
415   b[X_AXIS].unite (back.extent (X_AXIS));
416   b[Y_AXIS].unite (back.extent (Y_AXIS));
417
418   return Molecule (b, at);
419 }
420
421 /*
422  * Bezier Sandwich:
423  *
424  *                               .|
425  *                        .       |
426  *              top .             |
427  *              . curve           |
428  *          .                     |
429  *       .                        |
430  *     .                          |
431  *    |                           |
432  *    |                          .|
433  *    |                     .
434  *    |         bottom .
435  *    |            . curve
436  *    |         .
437  *    |      .
438  *    |   .
439  *    | .
440  *    |.
441  *    |
442  *
443  */
444 Molecule
445 Lookup::bezier_sandwich (Bezier top_curve, Bezier bottom_curve)
446 {
447   /*
448     Need the weird order b.o. the way PS want its arguments  
449    */
450   SCM list = SCM_EOL;
451   list = gh_cons (ly_offset2scm (bottom_curve.control_[3]), list);
452   list = gh_cons (ly_offset2scm (bottom_curve.control_[0]), list);
453   list = gh_cons (ly_offset2scm (bottom_curve.control_[1]), list);
454   list = gh_cons (ly_offset2scm (bottom_curve.control_[2]), list);
455   list = gh_cons (ly_offset2scm (top_curve.control_[0]), list);
456   list = gh_cons (ly_offset2scm (top_curve.control_[3]), list);
457   list = gh_cons (ly_offset2scm (top_curve.control_[2]), list);
458   list = gh_cons (ly_offset2scm (top_curve.control_[1]), list);
459
460   SCM horizontal_bend = scm_list_n (ly_symbol2scm ("bezier-sandwich"),
461                                     ly_quote_scm (list),
462                                     gh_double2scm (0.0),
463                                     SCM_UNDEFINED);
464
465   Interval x_extent = top_curve.extent (X_AXIS);
466   x_extent.unite (bottom_curve.extent (X_AXIS));
467   Interval y_extent = top_curve.extent (Y_AXIS);
468   y_extent.unite (bottom_curve.extent (Y_AXIS));
469   Box b (x_extent, y_extent);
470
471   return Molecule (b, horizontal_bend);
472 }
473
474 /*
475   TODO: junk me.
476  */
477 Molecule
478 Lookup::accordion (SCM s, Real staff_space, Font_metric *fm) 
479 {
480   Molecule m;
481   String sym = ly_scm2string (ly_car (s));
482   String reg = ly_scm2string (ly_car (ly_cdr (s)));
483
484   if (sym == "Discant")
485     {
486       Molecule r = fm->find_by_name ("accordion-accDiscant");
487       m.add_molecule (r);
488       if (reg.left_string (1) == "F")
489         {
490           Molecule d = fm->find_by_name ("accordion-accDot");
491           d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
492           m.add_molecule (d);
493           reg = reg.right_string (reg.length ()-1);
494         }
495       int eflag = 0x00;
496       if (reg.left_string (3) == "EEE")
497         {
498           eflag = 0x07;
499           reg = reg.right_string (reg.length ()-3);
500         }
501       else if (reg.left_string (2) == "EE")
502         {
503           eflag = 0x05;
504           reg = reg.right_string (reg.length ()-2);
505         }
506       else if (reg.left_string (2) == "Eh")
507         {
508           eflag = 0x04;
509           reg = reg.right_string (reg.length ()-2);
510         }
511       else if (reg.left_string (1) == "E")
512         {
513           eflag = 0x02;
514           reg = reg.right_string (reg.length ()-1);
515         }
516       if (eflag & 0x02)
517         {
518           Molecule d = fm->find_by_name ("accordion-accDot");
519           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
520           m.add_molecule (d);
521         }
522       if (eflag & 0x04)
523         {
524           Molecule d = fm->find_by_name ("accordion-accDot");
525           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
526           d.translate_axis (0.8 * staff_space PT, X_AXIS);
527           m.add_molecule (d);
528         }
529       if (eflag & 0x01)
530         {
531           Molecule d = fm->find_by_name ("accordion-accDot");
532           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
533           d.translate_axis (-0.8 * staff_space PT, X_AXIS);
534           m.add_molecule (d);
535         }
536       if (reg.left_string (2) == "SS")
537         {
538           Molecule d = fm->find_by_name ("accordion-accDot");
539           d.translate_axis (0.5 * staff_space PT, Y_AXIS);
540           d.translate_axis (0.4 * staff_space PT, X_AXIS);
541           m.add_molecule (d);
542           d.translate_axis (-0.8 * staff_space PT, X_AXIS);
543           m.add_molecule (d);
544           reg = reg.right_string (reg.length ()-2);
545         }
546       if (reg.left_string (1) == "S")
547         {
548           Molecule d = fm->find_by_name ("accordion-accDot");
549           d.translate_axis (0.5 * staff_space PT, Y_AXIS);
550           m.add_molecule (d);
551           reg = reg.right_string (reg.length ()-1);
552         }
553     }
554   else if (sym == "Freebase")
555     {
556       Molecule r = fm->find_by_name ("accordion-accFreebase");
557       m.add_molecule (r);
558       if (reg.left_string (1) == "F")
559         {
560           Molecule d = fm->find_by_name ("accordion-accDot");
561           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
562           m.add_molecule (d);
563           reg = reg.right_string (reg.length ()-1);
564         }
565       if (reg == "E")
566         {
567           Molecule d = fm->find_by_name ("accordion-accDot");
568           d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
569           m.add_molecule (d);
570         }
571     }
572   else if (sym == "Bayanbase")
573     {
574       Molecule r = fm->find_by_name ("accordion-accBayanbase");
575       m.add_molecule (r);
576       if (reg.left_string (1) == "T")
577         {
578           Molecule d = fm->find_by_name ("accordion-accDot");
579           d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
580           m.add_molecule (d);
581           reg = reg.right_string (reg.length ()-1);
582         }
583       /* include 4' reed just for completeness. You don't want to use this. */
584       if (reg.left_string (1) == "F")
585         {
586           Molecule d = fm->find_by_name ("accordion-accDot");
587           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
588           m.add_molecule (d);
589           reg = reg.right_string (reg.length ()-1);
590         }
591       if (reg.left_string (2) == "EE")
592         {
593           Molecule d = fm->find_by_name ("accordion-accDot");
594           d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
595           d.translate_axis (0.4 * staff_space PT, X_AXIS);
596           m.add_molecule (d);
597           d.translate_axis (-0.8 * staff_space PT, X_AXIS);
598           m.add_molecule (d);
599           reg = reg.right_string (reg.length ()-2);
600         }
601       if (reg.left_string (1) == "E")
602         {
603           Molecule d = fm->find_by_name ("accordion-accDot");
604           d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
605           m.add_molecule (d);
606           reg = reg.right_string (reg.length ()-1);
607         }
608     }
609   else if (sym == "Stdbase")
610     {
611       Molecule r = fm->find_by_name ("accordion-accStdbase");
612       m.add_molecule (r);
613       if (reg.left_string (1) == "T")
614         {
615           Molecule d = fm->find_by_name ("accordion-accDot");
616           d.translate_axis (staff_space * 3.5 PT, Y_AXIS);
617           m.add_molecule (d);
618           reg = reg.right_string (reg.length ()-1);
619         }
620       if (reg.left_string (1) == "F")
621         {
622           Molecule d = fm->find_by_name ("accordion-accDot");
623           d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
624           m.add_molecule (d);
625           reg = reg.right_string (reg.length ()-1);
626         }
627       if (reg.left_string (1) == "M")
628         {
629           Molecule d = fm->find_by_name ("accordion-accDot");
630           d.translate_axis (staff_space * 2 PT, Y_AXIS);
631           d.translate_axis (staff_space PT, X_AXIS);
632           m.add_molecule (d);
633           reg = reg.right_string (reg.length ()-1);
634         }
635       if (reg.left_string (1) == "E")
636         {
637           Molecule d = fm->find_by_name ("accordion-accDot");
638           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
639           m.add_molecule (d);
640           reg = reg.right_string (reg.length ()-1);
641         }
642       if (reg.left_string (1) == "S")
643         {
644           Molecule d = fm->find_by_name ("accordion-accDot");
645           d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
646           m.add_molecule (d);
647           reg = reg.right_string (reg.length ()-1);
648         }
649     }
650   /* ugh maybe try to use regular font for S.B. and B.B and only use one font
651      for the rectangle */
652   else if (sym == "SB")
653     {
654       Molecule r = fm->find_by_name ("accordion-accSB");
655       m.add_molecule (r);
656     }
657   else if (sym == "BB")
658     {
659       Molecule r = fm->find_by_name ("accordion-accBB");
660       m.add_molecule (r);
661     }
662   else if (sym == "OldEE")
663     {
664       Molecule r = fm->find_by_name ("accordion-accOldEE");
665       m.add_molecule (r);
666     }
667   else if (sym == "OldEES")
668     {
669       Molecule r = fm->find_by_name ("accordion-accOldEES");
670       m.add_molecule (r);
671     }
672   return m;  
673 }
674
675 Molecule
676 Lookup::repeat_slash (Real w, Real s, Real t)
677 {
678   SCM wid = gh_double2scm (w);
679   SCM sl = gh_double2scm (s);
680   SCM thick = gh_double2scm (t);
681   SCM slashnodot = scm_list_n (ly_symbol2scm ("repeat-slash"),
682                             wid, sl, thick, SCM_UNDEFINED);
683
684   Box b (Interval (0, w + sqrt (sqr(t/s) + sqr (t))),
685          Interval (0, w * s));
686
687   return Molecule (b, slashnodot); //  http://slashnodot.org
688 }
689
690
691 Molecule
692 Lookup::bracket (Axis a, Interval iv, Real thick, Real protude, Real blot)
693 {
694   Box b;
695   Axis other = Axis((a+1)%2);
696   b[a] = iv;
697   b[other] = Interval(-1, 1) * thick * 0.5;
698   
699   Molecule m =  round_filled_box (b, blot);
700
701   b[a] = Interval (iv[UP] - thick, iv[UP]);
702   Interval oi = Interval (-thick/2, thick/2 + fabs (protude)) ;
703   oi *=  sign (protude);
704   b[other] = oi;
705   m.add_molecule (round_filled_box (b, blot));
706   b[a] = Interval (iv[DOWN], iv[DOWN]  +thick);
707   m.add_molecule (round_filled_box (b,blot));
708
709   return m;
710 }
711
712 Molecule
713 Lookup::triangle (Interval iv, Real thick, Real protude)
714 {
715   Box b ;
716   b[X_AXIS] = iv;
717   b[Y_AXIS] = Interval (0 <? protude , 0 >? protude);
718
719   SCM s = scm_list_n (ly_symbol2scm ("symmetric-x-triangle"),
720                       gh_double2scm (thick),
721                       gh_double2scm (iv.length()), 
722                       gh_double2scm (protude), SCM_UNDEFINED);
723
724   return Molecule (b, s);
725 }
726
727
728 /*
729   TODO: use rounded boxes.
730  */
731 LY_DEFINE(ly_bracket ,"ly:bracket",
732           4, 0, 0,
733           (SCM a, SCM iv, SCM t, SCM p),
734           "Make a bracket in direction @var{a}. The extent of the bracket is " 
735           "given by @var{iv}. The wings protude by an amount of @var{p}, which "
736           "may be negative. The thickness is given by @var{t}.")
737 {
738   SCM_ASSERT_TYPE(is_axis (a), a, SCM_ARG1, __FUNCTION__, "axis") ;
739   SCM_ASSERT_TYPE(is_number_pair (iv), iv, SCM_ARG2, __FUNCTION__, "number pair") ;
740   SCM_ASSERT_TYPE(gh_number_p (t), a, SCM_ARG3, __FUNCTION__, "number") ;
741   SCM_ASSERT_TYPE(gh_number_p (p), a, SCM_ARG4, __FUNCTION__, "number") ;
742
743
744   return Lookup::bracket ((Axis)gh_scm2int (a), ly_scm2interval (iv),
745                           gh_scm2double (t),
746                           gh_scm2double (p),
747                           gh_scm2double (t)).smobbed_copy ();
748 }
749
750
751
752 LY_DEFINE(ly_filled_box ,"ly:round-filled-box",
753           3, 0, 0,
754           (SCM xext, SCM yext, SCM blot),
755           "Make a filled-box of dimensions @var{xext}, @var{yext} and roundness @var{blot}.")
756 {
757   SCM_ASSERT_TYPE(is_number_pair (xext), xext, SCM_ARG1, __FUNCTION__, "number pair") ;
758   SCM_ASSERT_TYPE(is_number_pair (yext), yext, SCM_ARG2, __FUNCTION__, "number pair") ;
759   SCM_ASSERT_TYPE(gh_number_p (blot), blot, SCM_ARG3, __FUNCTION__, "number") ;
760
761   return Lookup::round_filled_box (Box (ly_scm2interval (xext), ly_scm2interval (yext)),
762                                    gh_scm2double (blot)).smobbed_copy ();
763 }
764