]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-configuration.cc
* Documentation/topdocs/NEWS.tely (Top): document new feature.
[lilypond.git] / lily / tie-configuration.cc
1 /*
2   tie-configuration.cc -- implement Tie_configuration
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include "tie-configuration.hh"
11 #include "warn.hh"
12 #include "tie-formatting-problem.hh"
13 #include "bezier.hh"
14
15 int
16 Tie_configuration::compare (Tie_configuration const &a,
17                             Tie_configuration const &b)
18 {
19   if (a.position_ - b.position_)
20     return sign (a.position_ - b.position_);
21   return sign (a.dir_ - b.dir_);
22 }
23                             
24
25 Tie_configuration::Tie_configuration ()
26 {
27   dir_ = CENTER;
28   position_ = 0;
29   delta_y_ = 0.0;
30 }
31
32
33 void
34 Tie_configuration::center_tie_vertically (Tie_details const &details)
35 {
36   Bezier b = get_untransformed_bezier (details);
37   Offset middle = b.curve_point (0.5);
38   Offset edge = b.curve_point (0.0);
39   Real center = (edge[Y_AXIS] + middle[Y_AXIS])/2.0;
40
41   delta_y_ = - dir_ * center;
42 }
43
44
45 /*
46   Get bezier with left control at (0,0)
47  */
48 Bezier
49 Tie_configuration::get_transformed_bezier (Tie_details const &details) const
50 {
51   Bezier b (get_untransformed_bezier (details));
52
53   b.scale (1, dir_);
54   b.translate (Offset (attachment_x_[LEFT],
55                        delta_y_ + details.staff_space_ * 0.5 * position_));
56
57   return b;
58 }
59
60 /*
61   Get bezier with left control at (0,0)
62  */
63 Bezier
64 Tie_configuration::get_untransformed_bezier (Tie_details const &details) const
65 {
66   Real l = attachment_x_.length();
67   if (isnan (l) || isnan (l))
68     {
69       programming_error ("Inf or NaN encountered");
70       l = 1.0;
71     }
72   return slur_shape (l,
73                      details.height_limit_,
74                      details.ratio_);
75 }
76
77 Real
78 Tie_configuration::distance (Tie_configuration const &a,
79                              Tie_configuration const &b)
80 {
81
82   Real d = 3 * (a.position_ - b.position_);
83   if (d < 0)
84     return d + (2 + (b.dir_ - a.dir_));
85   else
86     return d + (2 + (a.dir_ - b.dir_));
87 }
88
89 Real
90 Tie_configuration::height (Tie_details const &details) const
91 {
92   Real l = attachment_x_.length();
93
94   return slur_shape (l,
95                      details.height_limit_,
96                      details.ratio_).curve_point (0.5)[Y_AXIS]; 
97 }