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