LEFT | RIGHT |
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 1998--2012 Jan Nieuwenhuizen <janneke@gnu.org> | 4 Copyright (C) 1998--2012 Jan Nieuwenhuizen <janneke@gnu.org> |
5 | 5 |
6 LilyPond is free software: you can redistribute it and/or modify | 6 LilyPond is free software: you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation, either version 3 of the License, or | 8 the Free Software Foundation, either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 #endif | 138 #endif |
139 | 139 |
140 return o; | 140 return o; |
141 } | 141 } |
142 | 142 |
143 Real | 143 Real |
144 Bezier::slope_at_point (Real t) const | 144 Bezier::slope_at_point (Real t) const |
145 { | 145 { |
146 Offset second_order[3]; | 146 Offset second_order[3]; |
147 Offset third_order[2]; | 147 Offset third_order[2]; |
148 | 148 |
149 for (vsize i = 0; i < 3; i++) | 149 for (vsize i = 0; i < 3; i++) |
150 second_order[i] = ((control_[i + 1] - control_[i]) * t) + control_[i]; | 150 second_order[i] = ((control_[i + 1] - control_[i]) * t) + control_[i]; |
151 | 151 |
152 for (vsize i = 0; i < 2; i++) | 152 for (vsize i = 0; i < 2; i++) |
153 third_order[i] = ((second_order[i + 1] - second_order[i]) * t) + second_orde
r[i]; | 153 third_order[i] = ((second_order[i + 1] - second_order[i]) * t) + second_orde
r[i]; |
154 | 154 |
155 if (third_order[1][X_AXIS] - third_order[0][X_AXIS] == 0) | 155 if (third_order[1][X_AXIS] - third_order[0][X_AXIS] == 0) |
156 return infinity_f; | 156 return infinity_f; |
157 | 157 |
158 return (third_order[1][Y_AXIS] - third_order[0][Y_AXIS]) / (third_order[1][X_A
XIS] - third_order[0][X_AXIS]); | 158 return (third_order[1][Y_AXIS] - third_order[0][Y_AXIS]) / (third_order[1][X_A
XIS] - third_order[0][X_AXIS]); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 Interval iv; | 256 Interval iv; |
257 for (vsize i = sols.size (); i--;) | 257 for (vsize i = sols.size (); i--;) |
258 { | 258 { |
259 Offset p (curve_point (sols[i])); | 259 Offset p (curve_point (sols[i])); |
260 if (p[ax] >= l && p[ax] <= r) | 260 if (p[ax] >= l && p[ax] <= r) |
261 iv.add_point (p[bx]); | 261 iv.add_point (p[bx]); |
262 } | 262 } |
263 | 263 |
264 // or intersections of the curve with the bounding lines at L and R. | 264 // or intersections of the curve with the bounding lines at L and R. |
265 Interval lr (l, r); | 265 Interval lr (l, r); |
266 Direction dir = LEFT; | 266 for (LEFT_and_RIGHT (dir)) |
267 do | |
268 { | 267 { |
269 vector<Real> v = get_other_coordinates (ax, lr[dir]); | 268 vector<Real> v = get_other_coordinates (ax, lr[dir]); |
270 for (vsize i = v.size (); i--;) | 269 for (vsize i = v.size (); i--;) |
271 iv.add_point (v[i]); | 270 iv.add_point (v[i]); |
272 } | 271 } |
273 while (flip (&dir) != LEFT); | |
274 | 272 |
275 if (iv.is_empty ()) | 273 if (iv.is_empty ()) |
276 { | 274 { |
277 programming_error ("Bezier curve does not cross region of concern"); | 275 programming_error ("Bezier curve does not cross region of concern"); |
278 return 0.0; | 276 return 0.0; |
279 } | 277 } |
280 | 278 |
281 return iv.at (d); | 279 return iv.at (d); |
282 } | 280 } |
283 | 281 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 else | 395 else |
398 subdivide (t_min, &bez1, &bez2); | 396 subdivide (t_min, &bez1, &bez2); |
399 if (t_max == 1.0) | 397 if (t_max == 1.0) |
400 return bez2; | 398 return bez2; |
401 else | 399 else |
402 { | 400 { |
403 bez2.subdivide ((t_max - t_min) / (1 - t_min), &bez3, &bez4); | 401 bez2.subdivide ((t_max - t_min) / (1 - t_min), &bez3, &bez4); |
404 return bez3; | 402 return bez3; |
405 } | 403 } |
406 } | 404 } |
LEFT | RIGHT |