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