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