]> git.donarmstrong.com Git - lilypond.git/blob - lily/box.cc
Makes all side-positioning based on skylines instead of boxes.
[lilypond.git] / lily / box.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1996--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
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 #include "box.hh"
21
22 void
23 Box::translate (Offset o)
24 {
25   for (Axis i = X_AXIS; i < NO_AXES; incr (i))
26     interval_a_[i] += o[i];
27 }
28
29 void
30 Box::unite (Box b)
31 {
32   for (Axis i = X_AXIS; i < NO_AXES; incr (i))
33     interval_a_[i].unite (b[i]);
34 }
35
36 Real
37 Box::area () const
38 {
39   return interval_a_[X_AXIS].length ()
40          * interval_a_[Y_AXIS].length ();
41 }
42
43 Box::Box ()
44 {
45 }
46
47 void
48 Box::set_empty ()
49 {
50   interval_a_[X_AXIS].set_empty ();
51   interval_a_[Y_AXIS].set_empty ();
52 }
53
54 bool
55 Box::is_empty () const
56 {
57   return interval_a_[X_AXIS].is_empty ()
58          || interval_a_[Y_AXIS].is_empty ();
59 }
60
61 Box::Box (Interval ix, Interval iy)
62 {
63   x () = ix;
64   y () = iy;
65 }
66
67 Interval &
68 Box::operator [] (Axis a)
69 {
70   return interval_a_[a];
71 }
72
73 Interval
74 Box::operator [] (Axis a) const
75 {
76   return interval_a_[a];
77 }
78
79 void
80 Box::scale (Real s)
81 {
82   interval_a_[X_AXIS] *= s;
83   interval_a_[Y_AXIS] *= s;
84 }
85
86 void
87 Box::add_point (Offset o)
88 {
89   interval_a_[X_AXIS].add_point (o[X_AXIS]);
90   interval_a_[Y_AXIS].add_point (o[Y_AXIS]);
91 }
92
93 Offset
94 Box::center () const
95 {
96   return Offset (interval_a_[X_AXIS].center (),
97                  interval_a_[Y_AXIS].center ());
98 }
99
100 void
101 Box::widen (Real x, Real y)
102 {
103   interval_a_[X_AXIS].widen (x);
104   interval_a_[Y_AXIS].widen (y);
105 }
106
107 void
108 Box::intersect (Box b)
109 {
110   interval_a_[X_AXIS].intersect (b[X_AXIS]);
111   interval_a_[Y_AXIS].intersect (b[Y_AXIS]);
112 }
113
114 // for debugging
115
116 void
117 Box::print ()
118 {
119   printf ("X left %4.4f right %4.4f Y down %4.4f up %4.4f\n",
120           interval_a_[X_AXIS][LEFT], interval_a_[X_AXIS][RIGHT],
121           interval_a_[Y_AXIS][DOWN], interval_a_[Y_AXIS][UP]);
122 }
123
124 /****************************************************************/
125
126 #include "ly-smobs.icc"
127
128 IMPLEMENT_SIMPLE_SMOBS (Box);
129 IMPLEMENT_TYPE_P (Box, "ly:box?");
130 IMPLEMENT_DEFAULT_EQUAL_P (Box);
131
132 SCM
133 Box::mark_smob (SCM /* x */)
134 {
135   return SCM_EOL;
136 }
137
138 int
139 Box::print_smob (SCM /* x */, SCM p, scm_print_state *)
140 {
141   scm_puts ("#<Box>", p);
142   return 1;
143 }