]> git.donarmstrong.com Git - lilypond.git/blob - lily/bezier-bow.cc
* lily/tie-column.cc (set_manual_tie_configuration): new function.
[lilypond.git] / lily / bezier-bow.cc
1 /*
2   bezier.cc -- implement Bezier and Bezier_bow
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <cmath>
10 using namespace std;
11
12 #include "misc.hh"
13 #include "bezier.hh"
14
15 static Real
16 F0_1 (Real x)
17 {
18   return 2 / M_PI *atan (M_PI *x / 2);
19 }
20
21 Real
22 slur_height (Real width, Real h_inf, Real r_0)
23 {
24   return F0_1 (width * r_0 / h_inf) * h_inf;
25 }
26
27 /*
28   ^                x                    x
29   |
30   height   <indent>
31   |
32   v      x                                       x
33
34
35
36   For small w, the height should be proportional to w, for w ->
37   infinity, the height should rise to a limit asymptotically.
38
39   Hence we take F (x) such that
40   F (0) = 0 , F' (0) = 1, and F (infty) = 1
41
42   and use
43
44   h = h_infinity * F (x * r_0 / h_infinity)
45
46
47   Examples:
48
49   * F (x) = 2/pi * atan (pi x/2)
50
51   * F (x) = 1/alpha * x^alpha / (1 + x^alpha)
52
53   * (etc.)
54
55   [with the 2nd recipe you can determine how quickly the conversion from
56   `small' slurs to `big' slurs occurs.]
57
58   Although this might seem cand_idates to SCM-ify, it is not all clear
59   which parameters (ie. h_inf, r_0, F (.)) should be candidates for
60   this.  At present h_inf and r_0 come from layout settings, but we did
61   no experiments for determining the best combinations of F, h_inf and
62   r_0.
63
64
65   The indent is proportional to the height of the slur for small
66   slurs.  For large slurs, this gives a certain hookiness at the end,
67   so we increase the indent.
68
69   indent = G(w)
70
71   w -> 0,  G(w) -> .33 w
72
73
74   (due to derivative constraints, we cannot have indent > len/3)
75
76   w -> inf, G(w) -> 2*h_inf
77
78   i.e.
79
80
81   G(0) = 0 , G'(0) 1/3, G(infty) = 2h_inf
82
83   solve from
84
85   G(w) = r  + p/(w+q)
86
87   yields
88
89   G(w) = 2 h_inf - max_fraction * q^2/ (w + q)
90
91   with q = 2 h_inf
92 */
93
94 void
95 get_slur_indent_height (Real *indent, Real *height,
96                         Real width, Real h_inf, Real r_0)
97 {
98   Real max_fraction = 1.0 / 3.1;
99   *height = slur_height (width, h_inf, r_0);
100
101   Real q = 2 * h_inf / max_fraction;
102   *indent = 2 * h_inf - sqr (q) * max_fraction / (width + q);
103 }
104
105 Bezier
106 slur_shape (Real width, Real h_inf, Real r_0)
107 {
108   Real indent;
109   Real height;
110
111   get_slur_indent_height (&indent, &height,
112                           width, h_inf, r_0);
113
114   Bezier curve;
115   curve.control_[0] = Offset (0, 0);
116   curve.control_[1] = Offset (indent, height);
117   curve.control_[2] = Offset (width - indent, height);
118   curve.control_[3] = Offset (width, 0);
119   return curve;
120 }