lilypond-1.3.65
[lilypond.git] / lily / bezier-bow.cc
blob8a92e9ddf4cfedd11f116faf96f2ef01869a07a8
1 /*
2 bezier.cc -- implement Bezier and Bezier_bow
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
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"
21 Bezier_bow::Bezier_bow (Array<Offset> encompass, Direction dir)
23 alpha_ = 0;
24 dir_ = dir;
25 encompass_ = encompass;
26 to_canonical_form ();
29 Bezier
30 Bezier_bow::get_bezier () const
32 Bezier rv = curve_;
33 if (dir_ == DOWN)
35 rv.flip (Y_AXIS);
38 rv.rotate (alpha_);
39 rv.translate (origin_);
41 return rv;
44 void
45 Bezier_bow::to_canonical_form ()
47 origin_ = encompass_[0];
48 translate (&encompass_, -origin_);
50 Offset delta = encompass_.top () - encompass_[0];
51 alpha_ = delta.arg ();
53 rotate (&encompass_, -alpha_);
54 if (dir_ == DOWN)
56 flip (&encompass_, Y_AXIS);
59 while (encompass_.size () > 1 && encompass_[1][X_AXIS] <= 0.0)
61 programming_error ("Degenerate bow: infinite steepness reqd");
62 encompass_.del (1);
65 Real l = encompass_.top ()[X_AXIS];
66 while (encompass_.size () > 1 && encompass_.top (1)[X_AXIS] >= l)
68 programming_error ("Degenerate bow: infinite steepness reqd");
69 encompass_.del (encompass_.size ()-2);
73 void
74 Bezier_bow::set_default_bezier (Real h_inf, Real r_0)
76 curve_ = get_default_bezier (h_inf, r_0);
80 See Documentation/programmer/fonts.doc
82 Bezier
83 Bezier_bow::get_default_bezier (Real h_inf, Real r_0) const
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;
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;
100 See Documentation/programmer/fonts.doc
102 Real
103 Bezier_bow::get_default_height (Real h_inf, Real r_0, Real b) const
106 SCM h = scm_eval (scm_listify (ly_symbol2scm ("slur-default-height"),
107 gh_double2scm (h_inf),
108 gh_double2scm (r_0),
109 gh_double2scm (b),
110 SCM_UNDEFINED));
111 return gh_scm2double (h);