]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/simple-spacer.hh
758cd65b32c26a4809325f2dc7ed8a0a3f2f392b
[lilypond.git] / lily / include / simple-spacer.hh
1 /*
2   simple-spacer.hh -- declare Simple_spacer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1999--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef SIMPLE_SPACER_HH
10 #define SIMPLE_SPACER_HH
11
12 #include "std-vector.hh"
13 #include "lily-proto.hh"
14 #include "smobs.hh"
15
16 struct Spring_description
17 {
18   Real ideal_;
19   Real inverse_hooke_;
20   Real block_force_;
21
22   Real length (Real force) const;
23   Spring_description ();
24
25   bool is_sane () const;
26
27   bool operator> (const Spring_description &s) const
28   {
29     return block_force_ > s.block_force_;
30   }
31
32   bool operator< (const Spring_description &s) const
33   {
34     return block_force_ < s.block_force_;
35   }
36 };
37
38 class Simple_spacer
39 {
40 public:
41   Simple_spacer ();
42
43   void solve (Real line_len, bool ragged);
44   void add_rod (int l, int r, Real dist);
45   void add_spring (Real, Real);
46   Real range_ideal_len (int l, int r) const;
47   Real range_stiffness (int l, int r) const;
48   Real configuration_length (Real) const;
49   vector<Real> spring_positions () const;
50
51   Real force () const;
52   bool fits () const;
53
54   DECLARE_SIMPLE_SMOBS (Simple_spacer,);
55
56 private:
57   Real expand_line ();
58   Real compress_line ();
59   Real rod_force (int l, int r, Real dist);
60
61   vector<Spring_description> springs_;
62   Real line_len_;
63   Real force_;
64   bool ragged_;
65   bool fits_;
66 };
67
68 /* returns a vector of dimensions breaks.size () * breaks.size () */
69 vector<Real> get_line_forces (vector<Grob*> const &columns,
70                               Real line_len,
71                               Real indent,
72                               bool ragged);
73
74 Column_x_positions get_line_configuration (vector<Grob*> const &columns,
75                                            Real line_len,
76                                            Real indent,
77                                            bool ragged);
78
79 #endif /* SIMPLE_SPACER_HH */
80