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