]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/bezier.hh
d09c0ac8bee4a7870d319ab1b64a240278bbcfbf
[lilypond.git] / lily / include / bezier.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1998--2012 Jan Nieuwenhuizen <janneke@gnu.org>
5
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
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef BEZIER_HH
21 #define BEZIER_HH
22
23 #include "interval.hh"
24 #include "offset.hh"
25 #include "polynomial.hh"
26
27 /**
28    Simple bezier curve
29 */
30 class Bezier
31 {
32 public:
33   void assert_sanity () const;
34   void scale (Real x, Real y);
35   void reverse ();
36   void rotate (Real);
37   void translate (Offset);
38   void subdivide (Real, Bezier *, Bezier *) const;
39   Bezier extract (Real, Real) const;
40
41   Real get_other_coordinate (Axis a, Real x) const;
42   vector<Real> get_other_coordinates (Axis a, Real x) const;
43   vector<Real> solve_point (Axis, Real coordinate) const;
44   Real minmax (Axis, Real, Real, Direction) const;
45   vector<Real> solve_derivative (Offset) const;
46   Interval extent (Axis) const;
47   Interval control_point_extent (Axis) const;
48
49   Polynomial polynomial (Axis)const;
50   Offset curve_point (Real t) const;
51   Real slope_at_point (Real t) const;
52   Real curve_coordinate (Real t, Axis) const;
53
54   static const int CONTROL_COUNT = 4;
55
56   /*
57     Bezier curves always have 4 control points. Making this into an
58     vector<> gives unnecessary overhead, and makes debugging a royal
59     pain.  */
60
61   Offset control_[4];
62 };
63
64 void scale (vector<Offset> *array, Real xscale, Real yscale);
65 void rotate (vector<Offset> *array, Real phi);
66 void translate (vector<Offset> *array, Offset o);
67
68 Bezier slur_shape (Real width, Real height_limit,
69                    Real height_proportion);
70 Real slur_height (Real width, Real height_limit, Real height_proportion);
71 void get_slur_indent_height (Real *indent, Real *height, Real width, Real h_inf, Real r_0);
72
73 #endif // BEZIER_HH
74