]> git.donarmstrong.com Git - lilypond.git/blob - lily/box.cc
use trap to remove tmp directory on failure to avoid hiding mpost
[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 Box::Box ()
37 {
38 }
39
40 void
41 Box::set_empty ()
42 {
43   interval_a_[X_AXIS].set_empty ();
44   interval_a_[Y_AXIS].set_empty ();
45 }
46
47 Box::Box (Interval ix, Interval iy)
48 {
49   x () = ix;
50   y () = iy;
51 }
52
53 Interval &
54 Box::operator [] (Axis a)
55 {
56   return interval_a_[a];
57 }
58
59 Interval
60 Box::operator [] (Axis a) const
61 {
62   return interval_a_[a];
63 }
64
65 void
66 Box::scale (Real s)
67 {
68   interval_a_[X_AXIS] *= s;
69   interval_a_[Y_AXIS] *= s;
70 }
71
72 void
73 Box::add_point (Offset o)
74 {
75   interval_a_[X_AXIS].add_point (o[X_AXIS]);
76   interval_a_[Y_AXIS].add_point (o[Y_AXIS]);
77 }
78
79 Offset
80 Box::center () const
81 {
82   return Offset (interval_a_[X_AXIS].center (),
83                  interval_a_[Y_AXIS].center ());
84 }
85
86 void
87 Box::widen (Real x, Real y)
88 {
89   interval_a_[X_AXIS].widen (x);
90   interval_a_[Y_AXIS].widen (y);
91 }
92
93 // for debugging
94
95 void
96 Box::print ()
97 {
98   printf ("X left %4.4f right %4.4f Y down %4.4f up %4.4f\n",
99           interval_a_[X_AXIS][LEFT], interval_a_[X_AXIS][RIGHT],
100           interval_a_[Y_AXIS][DOWN], interval_a_[Y_AXIS][UP]);
101 }
102
103 /****************************************************************/
104
105 #include "ly-smobs.icc"
106
107 IMPLEMENT_SIMPLE_SMOBS (Box);
108 IMPLEMENT_TYPE_P (Box, "ly:box?");
109 IMPLEMENT_DEFAULT_EQUAL_P (Box);
110
111 SCM
112 Box::mark_smob (SCM /* x */)
113 {
114   return SCM_EOL;
115 }
116
117 int
118 Box::print_smob (SCM /* x */, SCM p, scm_print_state *)
119 {
120   scm_puts ("#<Box>", p);
121   return 1;
122 }