]> git.donarmstrong.com Git - lilypond.git/blob - lily/lookup.cc
*** empty log message ***
[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
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   
79 Stencil
80 Lookup::dashed_slur (Bezier b, Real thick, Real dash_period, Real dash_fraction)
81 {
82   SCM l = SCM_EOL;
83   
84   Real on = dash_fraction * dash_period; 
85   Real off = dash_period - on; 
86  
87   for (int i = 4; i -- ;)
88     {
89       l = scm_cons (ly_offset2scm (b.control_[i]), l);
90     }
91
92   SCM at = (scm_list_n (ly_symbol2scm ("dashed-slur"),
93                         scm_make_real (thick), 
94                         scm_make_real (on),
95                         scm_make_real (off),
96                         ly_quote_scm (l),
97                         SCM_UNDEFINED));
98
99   Box box (Interval (0, 0), Interval (0, 0));
100   return   Stencil (box, at);
101 }
102
103
104
105 Stencil
106 Lookup::horizontal_line (Interval w, Real th)
107 {
108   SCM at = scm_list_n (ly_symbol2scm ("horizontal-line"),
109                        scm_make_real (w[LEFT]), 
110                        scm_make_real (w[RIGHT]),
111                        scm_make_real (th),
112                        SCM_UNDEFINED);
113
114
115   Box box ;
116   box[X_AXIS] = w;
117   box[Y_AXIS] = Interval (-th/2, th/2);
118
119   return Stencil (box, at);
120 }
121
122
123 Stencil
124 Lookup::blank (Box b) 
125 {
126   return Stencil (b, scm_makfrom0str (""));
127 }
128
129 Stencil
130 Lookup::filled_box (Box b) 
131 {
132   SCM  at  = (scm_list_n (ly_symbol2scm ("filledbox"),
133                      scm_make_real (-b[X_AXIS][LEFT]),
134                      scm_make_real (b[X_AXIS][RIGHT]),                 
135                      scm_make_real (-b[Y_AXIS][DOWN]),
136                      scm_make_real (b[Y_AXIS][UP]),                    
137                      SCM_UNDEFINED));
138
139   return Stencil (b, at);
140 }
141
142 /*
143  * round filled box:
144  *
145  *   __________________________________
146  *  /     \  ^           /     \      ^
147  * |         |blot              |     |
148  * |       | |dia       |       |     |
149  * |         |meter             |     |
150  * |\ _ _ /  v           \ _ _ /|     |
151  * |                            |     |
152  * |                            |     | Box
153  * |                    <------>|     | extent
154  * |                      blot  |     | (Y_AXIS)
155  * |                    diameter|     |
156  * |                            |     |
157  * |  _ _                  _ _  |     |
158  * |/     \              /     \|     |
159  * |                            |     |
160  * |       |            |       |     |
161  * |                            |     |
162  * x\_____/______________\_____/|_____v
163  * |(0, 0)                       |
164  * |                            |
165  * |                            |
166  * |<-------------------------->|
167  *       Box extent (X_AXIS)
168  */
169 Stencil
170 Lookup::round_filled_box (Box b, Real blotdiameter)
171 {
172   if (b.x ().length () < blotdiameter)
173     {
174       blotdiameter = b.x ().length ();
175     }
176   if (b.y ().length () < blotdiameter)
177     {
178       blotdiameter = b.y ().length ();
179     }
180
181   SCM at = (scm_list_n (ly_symbol2scm ("round-filled-box"),
182                         scm_make_real (-b[X_AXIS][LEFT]),
183                         scm_make_real (b[X_AXIS][RIGHT]),
184                         scm_make_real (-b[Y_AXIS][DOWN]),
185                         scm_make_real (b[Y_AXIS][UP]),
186                         scm_make_real (blotdiameter),
187                         SCM_UNDEFINED));
188
189   return Stencil (b, at);
190 }
191
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> points, Real blotdiameter)
236 {
237   /* TODO: Maybe print a warning if one of the above limitations
238      applies to the given polygon.  However, this is quite complicated
239      to check. */
240
241   /* remove consecutive duplicate points */
242   const Real epsilon = 0.01;
243   for (int i = 0; i < points.size ();)
244     {
245       int next_i = (i + 1) % points.size ();
246       Real d = (points[i] - points[next_i]).length ();
247       if (d < epsilon)
248         points.del (next_i);
249       else
250         i++;
251     }
252
253   /* special cases: degenerated polygons */
254   if (points.size () == 0)
255     return Stencil ();
256   if (points.size () == 1)
257     return dot (points[0], 0.5 * blotdiameter);
258   if (points.size () == 2)
259     return Line_interface::make_line (blotdiameter, points[0], points[1]);
260
261   /* shrink polygon in size by 0.5 * blotdiameter */
262   Array<Offset> shrinked_points;
263   shrinked_points.set_size (points.size ());
264   bool ccw = 1; // true, if three adjacent points are counterclockwise ordered
265   for (int i = 0; i < points.size (); i++)
266     {
267       int i0 = i;
268       int i1 = (i + 1) % points.size ();
269       int i2 = (i + 2) % points.size ();
270       Offset p0 = points[i0];
271       Offset p1 = points[i1];
272       Offset p2 = points[i2];
273       Offset p10 = p0 - p1;
274       Offset p12 = p2 - p1;
275       if (p10.length () != 0.0)
276         { // recompute ccw
277           Real phi = p10.arg ();
278           // rotate (p2 - p0) by (-phi)
279           Offset q = complex_multiply (p2 - p0, complex_exp (Offset (1.0, -phi)));
280
281           if (q[Y_AXIS] > 0)
282             ccw = 1;
283           else if (q[Y_AXIS] < 0)
284             ccw = 0;
285           else {} // keep ccw unchanged
286         }
287       else {} // keep ccw unchanged
288       Offset p10n = (1.0 / p10.length ()) * p10; // normalize length to 1.0
289       Offset p12n = (1.0 / p12.length ()) * p12;
290       Offset p13n = 0.5 * (p10n + p12n);
291       Offset p14n = 0.5 * (p10n - p12n);
292       Offset p13;
293       Real d = p13n.length () * p14n.length (); // distance p3n to line (p1..p0)
294       if (d < epsilon)
295         // special case: p0, p1, p2 are on a single line => build
296         // vector orthogonal to (p2-p0) of length 0.5 blotdiameter
297         {
298           p13[X_AXIS] = p10[Y_AXIS];
299           p13[Y_AXIS] = -p10[X_AXIS];
300           p13 = (0.5 * blotdiameter / p13.length ()) * p13;
301         }
302       else
303         p13 = (0.5 * blotdiameter / d) * p13n;
304       shrinked_points[i1] = p1 + ((ccw) ? p13 : -p13);
305     }
306
307   /* build scm expression and bounding box */
308   SCM shrinked_points_scm = SCM_EOL;
309   Box box;
310   for (int i = 0; i < shrinked_points.size (); i++)
311     {
312       SCM x = scm_make_real (shrinked_points[i][X_AXIS]);
313       SCM y = scm_make_real (shrinked_points[i][Y_AXIS]);
314       shrinked_points_scm = scm_cons (x, scm_cons (y, shrinked_points_scm));
315       box.add_point (points[i]);
316     }
317   SCM polygon_scm = scm_list_n (ly_symbol2scm ("polygon"),
318                                 ly_quote_scm (shrinked_points_scm),
319                                 scm_make_real (blotdiameter),
320                                 SCM_UNDEFINED);
321
322   Stencil polygon = Stencil (box, polygon_scm);
323   shrinked_points.clear ();
324   return polygon;
325 }
326
327
328 /*
329   TODO: deprecate?
330  */
331 Stencil
332 Lookup::frame (Box b, Real thick, Real blot)
333 {
334   Stencil m;
335   Direction d = LEFT;
336   for (Axis a = X_AXIS; a < NO_AXES; a = Axis (a + 1))
337     {
338       Axis o = Axis ((a+1)%NO_AXES);
339       do
340         {
341           Box edges;
342           edges[a] = b[a][d] + 0.5 * thick * Interval (-1, 1);
343           edges[o][DOWN] = b[o][DOWN] - thick/2;
344           edges[o][UP] = b[o][UP] + thick/2;      
345           
346           m.add_stencil (round_filled_box (edges, blot));
347         }
348       while (flip (&d) != LEFT);
349     }
350   return m;
351 }
352
353 /*
354   Make a smooth curve along the points 
355  */
356 Stencil
357 Lookup::slur (Bezier curve, Real curvethick, Real linethick) 
358 {
359   Real alpha = (curve.control_[3] - curve.control_[0]).arg ();
360   Bezier back = curve;
361   Offset perp = curvethick * complex_exp (Offset (0, alpha + M_PI/2)) * 0.5;
362   back.reverse ();
363   back.control_[1] += perp;
364   back.control_[2] += perp;
365
366   curve.control_[1] -= perp;
367   curve.control_[2] -= perp;
368   
369   SCM scontrols[8];
370
371   for (int i =4; i--;)
372     scontrols[ i ] = ly_offset2scm (back.control_[i]);
373   for (int i =4 ; i--;)
374     scontrols[i+4] = ly_offset2scm (curve.control_[i]);
375
376   /*
377     Need the weird order b.o. the way PS want its arguments  
378    */
379   int indices[]= {5, 6, 7, 4, 1, 2, 3, 0};
380   SCM list = SCM_EOL;
381   for (int i = 8; i--;)
382     {
383       list = scm_cons (scontrols[indices[i]], list);
384     }
385   
386   
387   SCM at = (scm_list_n (ly_symbol2scm ("bezier-sandwich"),
388                      ly_quote_scm (list),
389                      scm_make_real (linethick),
390                      SCM_UNDEFINED));
391   Box b (curve.extent (X_AXIS),
392         curve.extent (Y_AXIS));
393
394   b[X_AXIS].unite (back.extent (X_AXIS));
395   b[Y_AXIS].unite (back.extent (Y_AXIS));
396
397   return Stencil (b, at);
398 }
399
400 /*
401  * Bezier Sandwich:
402  *
403  *                               .|
404  *                        .       |
405  *              top .             |
406  *              . curve           |
407  *          .                     |
408  *       .                        |
409  *     .                          |
410  *    |                           |
411  *    |                          .|
412  *    |                     .
413  *    |         bottom .
414  *    |            . curve
415  *    |         .
416  *    |      .
417  *    |   .
418  *    | .
419  *    |.
420  *    |
421  *
422  */
423 Stencil
424 Lookup::bezier_sandwich (Bezier top_curve, Bezier bottom_curve)
425 {
426   /*
427     Need the weird order b.o. the way PS want its arguments  
428    */
429   SCM list = SCM_EOL;
430   list = scm_cons (ly_offset2scm (bottom_curve.control_[3]), list);
431   list = scm_cons (ly_offset2scm (bottom_curve.control_[0]), list);
432   list = scm_cons (ly_offset2scm (bottom_curve.control_[1]), list);
433   list = scm_cons (ly_offset2scm (bottom_curve.control_[2]), list);
434   list = scm_cons (ly_offset2scm (top_curve.control_[0]), list);
435   list = scm_cons (ly_offset2scm (top_curve.control_[3]), list);
436   list = scm_cons (ly_offset2scm (top_curve.control_[2]), list);
437   list = scm_cons (ly_offset2scm (top_curve.control_[1]), list);
438
439   SCM horizontal_bend = scm_list_n (ly_symbol2scm ("bezier-sandwich"),
440                                     ly_quote_scm (list),
441                                     scm_make_real (0.0),
442                                     SCM_UNDEFINED);
443
444   Interval x_extent = top_curve.extent (X_AXIS);
445   x_extent.unite (bottom_curve.extent (X_AXIS));
446   Interval y_extent = top_curve.extent (Y_AXIS);
447   y_extent.unite (bottom_curve.extent (Y_AXIS));
448   Box b (x_extent, y_extent);
449
450   return Stencil (b, horizontal_bend);
451 }
452
453 /*
454   TODO: junk me.
455  */
456 Stencil
457 Lookup::accordion (SCM s, Real staff_space, Font_metric *fm) 
458 {
459   Stencil m;
460   String sym = ly_scm2string (scm_car (s));
461   String reg = ly_scm2string (scm_car (scm_cdr (s)));
462
463   if (sym == "Discant")
464     {
465       Stencil r = fm->find_by_name ("accordion.accDiscant");
466       m.add_stencil (r);
467       if (reg.left_string (1) == "F")
468         {
469           Stencil d = fm->find_by_name ("accordion.accDot");
470           d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
471           m.add_stencil (d);
472           reg = reg.right_string (reg.length ()-1);
473         }
474       int eflag = 0x00;
475       if (reg.left_string (3) == "EEE")
476         {
477           eflag = 0x07;
478           reg = reg.right_string (reg.length ()-3);
479         }
480       else if (reg.left_string (2) == "EE")
481         {
482           eflag = 0x05;
483           reg = reg.right_string (reg.length ()-2);
484         }
485       else if (reg.left_string (2) == "Eh")
486         {
487           eflag = 0x04;
488           reg = reg.right_string (reg.length ()-2);
489         }
490       else if (reg.left_string (1) == "E")
491         {
492           eflag = 0x02;
493           reg = reg.right_string (reg.length ()-1);
494         }
495       if (eflag & 0x02)
496         {
497           Stencil d = fm->find_by_name ("accordion.accDot");
498           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
499           m.add_stencil (d);
500         }
501       if (eflag & 0x04)
502         {
503           Stencil d = fm->find_by_name ("accordion.accDot");
504           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
505           d.translate_axis (0.8 * staff_space PT, X_AXIS);
506           m.add_stencil (d);
507         }
508       if (eflag & 0x01)
509         {
510           Stencil d = fm->find_by_name ("accordion.accDot");
511           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
512           d.translate_axis (-0.8 * staff_space PT, X_AXIS);
513           m.add_stencil (d);
514         }
515       if (reg.left_string (2) == "SS")
516         {
517           Stencil d = fm->find_by_name ("accordion.accDot");
518           d.translate_axis (0.5 * staff_space PT, Y_AXIS);
519           d.translate_axis (0.4 * staff_space PT, X_AXIS);
520           m.add_stencil (d);
521           d.translate_axis (-0.8 * staff_space PT, X_AXIS);
522           m.add_stencil (d);
523           reg = reg.right_string (reg.length ()-2);
524         }
525       if (reg.left_string (1) == "S")
526         {
527           Stencil d = fm->find_by_name ("accordion.accDot");
528           d.translate_axis (0.5 * staff_space PT, Y_AXIS);
529           m.add_stencil (d);
530           reg = reg.right_string (reg.length ()-1);
531         }
532     }
533   else if (sym == "Freebase")
534     {
535       Stencil r = fm->find_by_name ("accordion.accFreebase");
536       m.add_stencil (r);
537       if (reg.left_string (1) == "F")
538         {
539           Stencil d = fm->find_by_name ("accordion.accDot");
540           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
541           m.add_stencil (d);
542           reg = reg.right_string (reg.length ()-1);
543         }
544       if (reg == "E")
545         {
546           Stencil d = fm->find_by_name ("accordion.accDot");
547           d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
548           m.add_stencil (d);
549         }
550     }
551   else if (sym == "Bayanbase")
552     {
553       Stencil r = fm->find_by_name ("accordion.accBayanbase");
554       m.add_stencil (r);
555       if (reg.left_string (1) == "T")
556         {
557           Stencil d = fm->find_by_name ("accordion.accDot");
558           d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
559           m.add_stencil (d);
560           reg = reg.right_string (reg.length ()-1);
561         }
562       /* include 4' reed just for completeness. You don't want to use this. */
563       if (reg.left_string (1) == "F")
564         {
565           Stencil d = fm->find_by_name ("accordion.accDot");
566           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
567           m.add_stencil (d);
568           reg = reg.right_string (reg.length ()-1);
569         }
570       if (reg.left_string (2) == "EE")
571         {
572           Stencil d = fm->find_by_name ("accordion.accDot");
573           d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
574           d.translate_axis (0.4 * staff_space PT, X_AXIS);
575           m.add_stencil (d);
576           d.translate_axis (-0.8 * staff_space PT, X_AXIS);
577           m.add_stencil (d);
578           reg = reg.right_string (reg.length ()-2);
579         }
580       if (reg.left_string (1) == "E")
581         {
582           Stencil d = fm->find_by_name ("accordion.accDot");
583           d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
584           m.add_stencil (d);
585           reg = reg.right_string (reg.length ()-1);
586         }
587     }
588   else if (sym == "Stdbase")
589     {
590       Stencil r = fm->find_by_name ("accordion.accStdbase");
591       m.add_stencil (r);
592       if (reg.left_string (1) == "T")
593         {
594           Stencil d = fm->find_by_name ("accordion.accDot");
595           d.translate_axis (staff_space * 3.5 PT, Y_AXIS);
596           m.add_stencil (d);
597           reg = reg.right_string (reg.length ()-1);
598         }
599       if (reg.left_string (1) == "F")
600         {
601           Stencil d = fm->find_by_name ("accordion.accDot");
602           d.translate_axis (staff_space * 2.5 PT, Y_AXIS);
603           m.add_stencil (d);
604           reg = reg.right_string (reg.length ()-1);
605         }
606       if (reg.left_string (1) == "M")
607         {
608           Stencil d = fm->find_by_name ("accordion.accDot");
609           d.translate_axis (staff_space * 2 PT, Y_AXIS);
610           d.translate_axis (staff_space PT, X_AXIS);
611           m.add_stencil (d);
612           reg = reg.right_string (reg.length ()-1);
613         }
614       if (reg.left_string (1) == "E")
615         {
616           Stencil d = fm->find_by_name ("accordion.accDot");
617           d.translate_axis (staff_space * 1.5 PT, Y_AXIS);
618           m.add_stencil (d);
619           reg = reg.right_string (reg.length ()-1);
620         }
621       if (reg.left_string (1) == "S")
622         {
623           Stencil d = fm->find_by_name ("accordion.accDot");
624           d.translate_axis (staff_space * 0.5 PT, Y_AXIS);
625           m.add_stencil (d);
626           reg = reg.right_string (reg.length ()-1);
627         }
628     }
629   /* ugh maybe try to use regular font for S.B. and B.B and only use one font
630      for the rectangle */
631   else if (sym == "SB")
632     {
633       Stencil r = fm->find_by_name ("accordion.accSB");
634       m.add_stencil (r);
635     }
636   else if (sym == "BB")
637     {
638       Stencil r = fm->find_by_name ("accordion.accBB");
639       m.add_stencil (r);
640     }
641   else if (sym == "OldEE")
642     {
643       Stencil r = fm->find_by_name ("accordion.accOldEE");
644       m.add_stencil (r);
645     }
646   else if (sym == "OldEES")
647     {
648       Stencil r = fm->find_by_name ("accordion.accOldEES");
649       m.add_stencil (r);
650     }
651   return m;  
652 }
653
654 Stencil
655 Lookup::repeat_slash (Real w, Real s, Real t)
656 {
657   SCM wid = scm_make_real (w);
658   SCM sl = scm_make_real (s);
659   SCM thick = scm_make_real (t);
660   SCM slashnodot = scm_list_n (ly_symbol2scm ("repeat-slash"),
661                                wid, sl, thick, SCM_UNDEFINED);
662
663   Box b (Interval (0, w + sqrt (sqr (t/s) + sqr (t))),
664          Interval (0, w * s));
665
666   return Stencil (b, slashnodot); //  http://slashnodot.org
667 }
668
669
670 Stencil
671 Lookup::bracket (Axis a, Interval iv, Real thick, Real protude, Real blot)
672 {
673   Box b;
674   Axis other = Axis ((a+1)%2);
675   b[a] = iv;
676   b[other] = Interval (-1, 1) * thick * 0.5;
677   
678   Stencil m = round_filled_box (b, blot);
679
680   b[a] = Interval (iv[UP] - thick, iv[UP]);
681   Interval oi = Interval (-thick/2, thick/2 + fabs (protude));
682   oi *= sign (protude);
683   b[other] = oi;
684   m.add_stencil (round_filled_box (b, blot));
685   b[a] = Interval (iv[DOWN], iv[DOWN] + thick);
686   m.add_stencil (round_filled_box (b, blot));
687
688   return m;
689 }
690
691 Stencil
692 Lookup::triangle (Interval iv, Real thick, Real protude)
693 {
694   Box b ;
695   b[X_AXIS] = Interval (0, iv.length());
696   b[Y_AXIS] = Interval (0 <? protude , 0 >? protude);
697
698
699   Offset z1(iv[LEFT], 0);
700   Offset z2(iv[RIGHT], 0);
701   Offset z3((z1 + z2)[X_AXIS]/2, protude);
702
703   /*
704     TODO: move Triangle to Line_interface ?
705    */
706   Stencil tri = Line_interface::make_line (thick, z1, z2);
707   tri.add_stencil (Line_interface::make_line (thick, z2, z3));
708   tri.add_stencil (Line_interface::make_line (thick, z3, z1));
709
710   return tri;
711 }
712