Allow for nested contexts of any depth.
[lilypond.git] / lily / box.cc
blobe44f166dbce2800bd31ce04aa21b3fb079c6894c
1 /*
2 box.cc -- implement Box
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "box.hh"
11 void
12 Box::translate (Offset o)
14 for (Axis i = X_AXIS; i < NO_AXES; incr (i))
15 interval_a_[i] += o[i];
18 void
19 Box::unite (Box b)
21 for (Axis i = X_AXIS; i < NO_AXES; incr (i))
22 interval_a_[i].unite (b[i]);
25 Box::Box ()
29 void
30 Box::set_empty ()
32 interval_a_[X_AXIS].set_empty ();
33 interval_a_[Y_AXIS].set_empty ();
36 Box::Box (Interval ix, Interval iy)
38 x () = ix;
39 y () = iy;
42 Interval &
43 Box::operator [] (Axis a)
45 return interval_a_[a];
48 Interval
49 Box::operator [] (Axis a) const
51 return interval_a_[a];
54 void
55 Box::scale (Real s)
57 interval_a_[X_AXIS] *= s;
58 interval_a_[Y_AXIS] *= s;
61 void
62 Box::add_point (Offset o)
64 interval_a_[X_AXIS].add_point (o[X_AXIS]);
65 interval_a_[Y_AXIS].add_point (o[Y_AXIS]);
68 Offset
69 Box::center () const
71 return Offset (interval_a_[X_AXIS].center (),
72 interval_a_[Y_AXIS].center ());
75 void
76 Box::widen (Real x, Real y)
78 interval_a_[X_AXIS].widen (x);
79 interval_a_[Y_AXIS].widen (y);
82 /****************************************************************/
84 #include "ly-smobs.icc"
86 IMPLEMENT_SIMPLE_SMOBS (Box);
87 IMPLEMENT_TYPE_P (Box, "ly:box?");
88 IMPLEMENT_DEFAULT_EQUAL_P (Box);
90 SCM
91 Box::mark_smob (SCM x)
93 (void)x;
94 return SCM_EOL;
97 int
98 Box::print_smob (SCM x, SCM p, scm_print_state*)
100 (void)x;
101 scm_puts ("#<Box>", p);
102 return 1;