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