]> git.donarmstrong.com Git - lilypond.git/blob - lily/box.cc
Web-ja: update introduction
[lilypond.git] / lily / box.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1996--2015 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     if (!is_empty (i))
27       interval_a_[i] += o[i];
28 }
29
30 void
31 Box::unite (Box b)
32 {
33   for (Axis i = X_AXIS; i < NO_AXES; incr (i))
34     interval_a_[i].unite (b[i]);
35 }
36
37 Real
38 Box::area () const
39 {
40   return interval_a_[X_AXIS].length ()
41          * interval_a_[Y_AXIS].length ();
42 }
43
44 Box::Box ()
45 {
46 }
47
48 void
49 Box::set_empty ()
50 {
51   interval_a_[X_AXIS].set_empty ();
52   interval_a_[Y_AXIS].set_empty ();
53 }
54
55 bool
56 Box::is_empty () const
57 {
58   return is_empty (X_AXIS) && is_empty (Y_AXIS);
59 }
60
61 bool
62 Box::is_empty (Axis a) const
63 {
64   Interval empty;
65   empty.set_empty ();
66   return interval_a_[a][LEFT] == empty[LEFT]
67     && interval_a_[a][RIGHT] == empty[RIGHT];
68 }
69
70 Box::Box (Interval ix, Interval iy)
71 {
72   x () = ix;
73   y () = iy;
74 }
75
76 Interval &
77 Box::operator [] (Axis a)
78 {
79   return interval_a_[a];
80 }
81
82 Interval
83 Box::operator [] (Axis a) const
84 {
85   return interval_a_[a];
86 }
87
88 void
89 Box::scale (Real s)
90 {
91   interval_a_[X_AXIS] *= s;
92   interval_a_[Y_AXIS] *= s;
93 }
94
95 void
96 Box::add_point (Offset o)
97 {
98   interval_a_[X_AXIS].add_point (o[X_AXIS]);
99   interval_a_[Y_AXIS].add_point (o[Y_AXIS]);
100 }
101
102 Offset
103 Box::center () const
104 {
105   return Offset (interval_a_[X_AXIS].center (),
106                  interval_a_[Y_AXIS].center ());
107 }
108
109 void
110 Box::widen (Real x, Real y)
111 {
112   interval_a_[X_AXIS].widen (x);
113   interval_a_[Y_AXIS].widen (y);
114 }
115
116 void
117 Box::intersect (Box b)
118 {
119   interval_a_[X_AXIS].intersect (b[X_AXIS]);
120   interval_a_[Y_AXIS].intersect (b[Y_AXIS]);
121 }
122
123 // for debugging
124
125 void
126 Box::print ()
127 {
128   printf ("X left %4.4f right %4.4f Y down %4.4f up %4.4f\n",
129           interval_a_[X_AXIS][LEFT], interval_a_[X_AXIS][RIGHT],
130           interval_a_[Y_AXIS][DOWN], interval_a_[Y_AXIS][UP]);
131 }
132
133 /****************************************************************/
134
135
136 const char * const Box::type_p_name_ = "ly:box?";