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