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