2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2008--2012 Han-Wen Nienhuys <hanwen@lilypond.org>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
21 #include "skyline-pair.hh"
23 #include "international.hh"
24 #include "ly-smobs.icc"
26 Skyline_pair::Skyline_pair ()
27 : skylines_ (Skyline (DOWN), Skyline (UP))
31 Skyline_pair::Skyline_pair (vector<Box> const &boxes, Axis a)
32 : skylines_ (Skyline (boxes, a, DOWN), Skyline (boxes, a, UP))
36 Skyline_pair::Skyline_pair (vector<Drul_array<Offset> > const &buildings, Axis a)
37 : skylines_ (Skyline (buildings, a, DOWN), Skyline (buildings, a, UP))
41 Skyline_pair::Skyline_pair (vector<Skyline_pair> const &skypairs)
42 : skylines_ (Skyline (skypairs, DOWN), Skyline (skypairs, UP))
46 Skyline_pair::Skyline_pair (Box const &b, Axis a)
47 : skylines_ (Skyline (b, a, DOWN), Skyline (b, a, UP))
52 Skyline_pair::raise (Real r)
54 skylines_[UP].raise (r);
55 skylines_[DOWN].raise (r);
59 Skyline_pair::deholify ()
61 skylines_[UP].deholify ();
62 skylines_[DOWN].deholify ();
66 Skyline_pair::shift (Real r)
68 skylines_[UP].shift (r);
69 skylines_[DOWN].shift (r);
73 Skyline_pair::insert (Box const &b, Axis a)
75 skylines_[UP].insert (b, a);
76 skylines_[DOWN].insert (b, a);
80 Skyline_pair::left () const
82 return min (skylines_[UP].left (), skylines_[DOWN].left ());
86 Skyline_pair::right () const
88 return max (skylines_[UP].right (), skylines_[DOWN].right ());
91 // This function comes with the same caveats as smallest_shift:
92 // if the skylines are not contiguous, we may report false
95 Skyline_pair::intersects (Skyline_pair const &other) const
97 return skylines_[UP].distance (other[DOWN]) > 0
98 && other[UP].distance (skylines_[DOWN]) > 0;
102 Skyline_pair::smallest_shift (Skyline_pair const &other, Direction d,
103 Real h_pad, Real v_pad)
105 // If skylines_[UP] avoids other[DOWN] or skylines_[DOWN] avoids
106 // other[UP] then we will not intersect.
107 // Note that this is not guaranteed to return the smallest shift
108 // if one Skyline_pair is not connected: the smallest_shift left
117 // even though the originals did not collide. If it becomes necessary,
118 // this case could be handled by splitting the Skyline_pairs up into
119 // their connected components.
121 return d * min (d * skylines_[UP].smallest_shift (other[DOWN], d, h_pad, v_pad),
122 d * skylines_[DOWN].smallest_shift (other[UP], d, h_pad, v_pad));
126 Skyline_pair::merge (Skyline_pair const &other)
128 skylines_[UP].merge (other[UP]);
129 skylines_[DOWN].merge (other[DOWN]);
133 Skyline_pair::print () const
135 skylines_[UP].print ();
136 skylines_[DOWN].print ();
140 Skyline_pair::print_points () const
142 skylines_[UP].print_points ();
143 skylines_[DOWN].print_points ();
147 Skyline_pair::is_empty () const
149 return skylines_[UP].is_empty ()
150 && skylines_[DOWN].is_empty ();
154 Skyline_pair::is_singleton () const
156 return skylines_[UP].is_singleton ()
157 && skylines_[DOWN].is_singleton ();
161 Skyline_pair::operator [] (Direction d)
167 Skyline_pair::operator [] (Direction d) const
172 IMPLEMENT_SIMPLE_SMOBS (Skyline_pair);
173 IMPLEMENT_TYPE_P (Skyline_pair, "ly:skyline-pair?");
174 IMPLEMENT_DEFAULT_EQUAL_P (Skyline_pair);
177 Skyline_pair::mark_smob (SCM)
183 Skyline_pair::print_smob (SCM s, SCM port, scm_print_state *)
185 Skyline_pair *r = (Skyline_pair *) SCM_CELL_WORD_1 (s);
188 scm_puts ("#<Skyline-pair>", port);
192 MAKE_SCHEME_CALLBACK (Skyline_pair, skyline, 2);
194 Skyline_pair::skyline (SCM smob, SCM dir_scm)
196 Skyline_pair *sp = Skyline_pair::unsmob (smob);
197 Direction dir = robust_scm2dir (dir_scm, UP);
201 warning (_f ("direction must not be CENTER in ly:skyline-pair::skyline"));
205 return (*sp)[dir].smobbed_copy ();