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