]> git.donarmstrong.com Git - lilypond.git/blob - lily/bezier-bow.cc
release: 1.3.29
[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--2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <math.h>
10 #include "bezier-bow.hh"
11 #include "misc.hh"
12 #include "bezier.hh"
13 #include "dimensions.hh"
14 #include "direction.hh"
15 #include "debug.hh"
16 #include "main.hh"
17 #include "lily-guile.hh"
18 #include "paper-def.hh"
19
20
21 Bezier_bow::Bezier_bow (Array<Offset> encompass, Direction dir)
22 {
23   alpha_ = 0;
24   dir_ = dir;
25   encompass_ = encompass;
26   to_canonical_form ();
27 }
28
29 Bezier
30 Bezier_bow::get_bezier () const
31 {
32   Bezier rv = curve_;
33   if (dir_ == DOWN)
34     {
35       rv.flip (Y_AXIS);
36     }
37
38   rv.rotate (alpha_);
39   rv.translate (origin_);
40   
41   return rv;
42 }
43
44 void
45 Bezier_bow::to_canonical_form ()
46 {
47   origin_ = encompass_[0];
48   translate (&encompass_, -origin_);
49
50   Offset delta = encompass_.top () - encompass_[0];
51   alpha_ = delta.arg ();
52
53   rotate (&encompass_, -alpha_);
54   if (dir_ == DOWN)
55     {
56       flip (&encompass_, Y_AXIS);
57     }
58
59   while (encompass_.size () > 1 && encompass_[1][X_AXIS] <= 0.0)
60     {
61       programming_error ("Degenerate bow: infinite steepness reqd");
62       encompass_.del (1);
63     }
64
65   Real l = encompass_.top ()[X_AXIS];
66   while (encompass_.size () > 1 && encompass_.top (1)[X_AXIS] >= l)
67     {
68       programming_error ("Degenerate bow: infinite steepness reqd");
69       encompass_.del (encompass_.size ()-2);
70     }
71 }
72
73 void
74 Bezier_bow::set_default_bezier (Real h_inf, Real r_0)
75 {
76   curve_ = get_default_bezier (h_inf, r_0);
77 }
78
79 /*
80   See Documentation/programmer/fonts.doc
81  */
82 Bezier
83 Bezier_bow::get_default_bezier (Real h_inf, Real r_0) const
84 {
85   Offset delta (encompass_.top ()[X_AXIS] - encompass_[0][X_AXIS], 0);
86   Real b = delta.length ();
87   Real height = get_default_height (h_inf, r_0, b);
88   // urg: scmify this?
89   Real indent = height;
90
91   Bezier curve;
92   curve.control_[0] = Offset (0, 0);
93   curve.control_[1] = Offset (indent, height);
94   curve.control_[2] = Offset (b - indent, height);
95   curve.control_[3] = Offset (b, 0);
96   return curve;
97 }
98
99 /*
100   See Documentation/programmer/fonts.doc
101  */
102 Real
103 Bezier_bow::get_default_height (Real h_inf, Real r_0, Real b) const
104 {
105 #if 0
106   Real pi = M_PI;
107
108   Real alpha = 2.0 * h_inf / pi;
109   Real beta = pi * r_0 / (2.0 * h_inf);
110
111   return alpha * atan (beta * b);
112 #else
113   SCM h = scm_eval (scm_listify (ly_symbol2scm ("slur-default-height"),
114                                  gh_double2scm (h_inf),
115                                  gh_double2scm (r_0),
116                                  gh_double2scm (b),
117                                  SCM_UNDEFINED));
118   return gh_scm2double (h);
119 #endif
120 }
121