]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/simple-spacer.hh
Merge with master
[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--2007 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   Real force_penalty (bool ragged) const;
53   bool fits () const;
54
55   DECLARE_SIMPLE_SMOBS (Simple_spacer);
56
57 private:
58   Real expand_line ();
59   Real compress_line ();
60   Real rod_force (int l, int r, Real dist);
61
62   vector<Spring_description> springs_;
63   Real line_len_;
64   Real force_;
65   bool ragged_;
66   bool fits_;
67 };
68
69 /* returns a vector of dimensions breaks.size () * breaks.size () */
70 vector<Real> get_line_forces (vector<Grob*> const &columns,
71                               Real line_len,
72                               Real indent,
73                               bool ragged);
74
75 Column_x_positions get_line_configuration (vector<Grob*> const &columns,
76                                            Real line_len,
77                                            Real indent,
78                                            bool ragged);
79
80 #endif /* SIMPLE_SPACER_HH */
81