2 slur-bezier-bow.cc -- implement Slur_bezier_bow
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "paper-def.hh"
11 #include "slur-bezier-bow.hh"
14 Slur_bezier_bow::Slur_bezier_bow (Array<Offset> encompass, Direction dir)
15 : Bezier_bow (encompass, dir)
20 Slur_bezier_bow::blow_fit ()
22 Real len = curve_.control_[3][X_AXIS];
23 Real h = curve_.control_[1][Y_AXIS] * fit_factor () / len;
24 curve_.control_[1][Y_AXIS] = h * len;
25 curve_.control_[2][Y_AXIS] = h * len;
26 curve_.assert_sanity ();
31 Slur_bezier_bow::enclosed_area_f () const
34 for (int i=0; i < encompass_.size (); i++)
40 x = Interval (0, encompass_[1][X_AXIS] / 2);
42 curve_.get_other_coordinate (X_AXIS,
46 else if (i == encompass_.size () - 1)
48 x = Interval ((encompass_[i-1][X_AXIS] + encompass_[i][X_AXIS])/2,
49 encompass_[i][X_AXIS]);
51 (curve_.get_other_coordinate (X_AXIS,
52 (x[MIN] + x[MAX]) / 2)));
56 x = Interval ((encompass_[i-1][X_AXIS] + encompass_[i][X_AXIS]) / 2,
57 (encompass_[i][X_AXIS] + encompass_[i+1][X_AXIS]) / 2);
58 y = Interval (encompass_[i][Y_AXIS],
59 (curve_.get_other_coordinate (X_AXIS, x[MIN])
60 + curve_.get_other_coordinate (X_AXIS,
61 (x[MIN] + x[MAX]) / 2)
62 + curve_.get_other_coordinate (X_AXIS, x[MAX])) / 3);
65 Real da = x.length () * y.length ();
72 Slur_bezier_bow::area_x_gradients_array (Real area)
74 Real len = curve_.control_[3][X_AXIS];
75 Real grow = len / 10.0;
77 for (int i=0; i < 2; i++)
79 Real r = curve_.control_[i+1][X_AXIS];
80 curve_.control_[i+1][X_AXIS] += grow;
81 da[i] = (enclosed_area_f () - area) / grow;
82 curve_.control_[i+1][X_AXIS] = r;
88 Slur_bezier_bow::minimise_enclosed_area (Paper_def* paper_l,
91 Real length = curve_.control_[3][X_AXIS];
92 Real sb = paper_l->get_var ("slur_beautiful");
93 Real beautiful = length * default_height * sb;
95 DEBUG_OUT << to_str ("Beautiful: %f\n", beautiful);
96 DEBUG_OUT << to_str ("Length: %f\n", length);
97 DEBUG_OUT << to_str ("D-height: %f\n", default_height);
98 DEBUG_OUT << to_str ("FitFac: %f\n", fit_factor ());
100 if (fit_factor () > 1.0)
103 Real pct_c0 = paper_l->get_var ("bezier_pct_c0");
104 Real pct_c3 = paper_l->get_var ("bezier_pct_c3");
105 Real pct_in_max = paper_l->get_var ("bezier_pct_in_max");
106 Real pct_out_max = paper_l->get_var ("bezier_pct_out_max");
107 Real steps = paper_l->get_var ("bezier_area_steps");
109 for (int i=0; i < steps; i++)
111 Real area = enclosed_area_f ();
113 DEBUG_OUT << to_str ("Init area: %f\n", area);
115 if (area <= beautiful)
118 Array<Real> da = area_x_gradients_array (area);
121 Real pct = pct_c0 + pct_c3 * length * length * length;
122 pct *= (steps - i) / steps;
123 if (da[0] > 0 || da[1] < 0)
124 pct = pct <? pct_out_max;
126 pct = pct <? pct_in_max;
128 Real u = (abs (curve_.control_[1][X_AXIS] / da[0])
129 <? abs ((curve_.control_[3][X_AXIS]
130 - curve_.control_[2][X_AXIS]) / da[1]));
132 DEBUG_OUT << to_str ("pct: %f\n", pct);
133 DEBUG_OUT << to_str ("u: %f\n", u);
135 DEBUG_OUT << to_str ("da: (%f, %f)\n", da[0], da[1]);
136 DEBUG_OUT << to_str ("da*u: (%f, %f)\n", da[0]*u*pct, da[1]*u*pct);
137 DEBUG_OUT << to_str ("cx: (%f, %f)\n", curve_.control_[1][X_AXIS],
138 curve_.control_[2][X_AXIS]);
140 curve_.control_[1][X_AXIS] -= da[0] * u * pct;
141 curve_.control_[2][X_AXIS] -= da[1] * u * pct;
144 Real area = enclosed_area_f ();
145 DEBUG_OUT << to_str ("Exarea: %f\n", area);
151 max ( encompass.y / curve.y )
155 Slur_bezier_bow::fit_factor () const
157 Real x1 = encompass_[0][X_AXIS];
158 Real x2 = encompass_.top ()[X_AXIS];
161 for (int i=1; i < encompass_.size ()-1; i++)
163 if (encompass_[i][X_AXIS] > x1 && encompass_[i][X_AXIS] < x2)
165 Real y = curve_.get_other_coordinate (X_AXIS, encompass_[i][X_AXIS]);
168 Real f = encompass_[i][Y_AXIS] / y;
169 factor = factor >? f;