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