]> git.donarmstrong.com Git - lilypond.git/blob - lily/skyline-pair.cc
5dc217d3426217e5174b10699646fedbe2f8cee4
[lilypond.git] / lily / skyline-pair.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2008--2015 Han-Wen Nienhuys <hanwen@lilypond.org>
5
6
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.
11
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.
16
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/>.
19 */
20
21 #include "skyline-pair.hh"
22
23 #include "international.hh"
24
25 using std::vector;
26
27 Skyline_pair::Skyline_pair ()
28   : skylines_ (Skyline (DOWN), Skyline (UP))
29 {
30 }
31
32 Skyline_pair::Skyline_pair (vector<Box> const &boxes, Axis a)
33   : skylines_ (Skyline (boxes, a, DOWN), Skyline (boxes, a, UP))
34 {
35 }
36
37 Skyline_pair::Skyline_pair (vector<Drul_array<Offset> > const &buildings, Axis a)
38   : skylines_ (Skyline (buildings, a, DOWN), Skyline (buildings, a, UP))
39 {
40 }
41
42 Skyline_pair::Skyline_pair (vector<Skyline_pair> const &skypairs)
43   : skylines_ (Skyline (skypairs, DOWN), Skyline (skypairs, UP))
44 {
45 }
46
47 Skyline_pair::Skyline_pair (Box const &b, Axis a)
48   : skylines_ (Skyline (b, a, DOWN), Skyline (b, a, UP))
49 {
50 }
51
52 void
53 Skyline_pair::raise (Real r)
54 {
55   skylines_[UP].raise (r);
56   skylines_[DOWN].raise (r);
57 }
58
59 void
60 Skyline_pair::shift (Real r)
61 {
62   skylines_[UP].shift (r);
63   skylines_[DOWN].shift (r);
64 }
65
66 void
67 Skyline_pair::insert (Box const &b, Axis a)
68 {
69   skylines_[UP].insert (b, a);
70   skylines_[DOWN].insert (b, a);
71 }
72
73 void
74 Skyline_pair::merge (Skyline_pair const &other)
75 {
76   skylines_[UP].merge (other[UP]);
77   skylines_[DOWN].merge (other[DOWN]);
78 }
79
80 void
81 Skyline_pair::print () const
82 {
83   skylines_[UP].print ();
84   skylines_[DOWN].print ();
85 }
86
87 Real
88 Skyline_pair::left () const
89 {
90   return std::min (skylines_[UP].left (), skylines_[DOWN].left ());
91 }
92
93 Real
94 Skyline_pair::right () const
95 {
96   return std::max (skylines_[UP].right (), skylines_[DOWN].right ());
97 }
98
99 void
100 Skyline_pair::print_points () const
101 {
102   skylines_[UP].print_points ();
103   skylines_[DOWN].print_points ();
104 }
105
106 bool
107 Skyline_pair::is_empty () const
108 {
109   return skylines_[UP].is_empty ()
110          && skylines_[DOWN].is_empty ();
111 }
112
113 Skyline &
114 Skyline_pair::operator [] (Direction d)
115 {
116   return skylines_[d];
117 }
118
119 Skyline const &
120 Skyline_pair::operator [] (Direction d) const
121 {
122   return skylines_[d];
123 }
124
125 const char Skyline_pair::type_p_name_[] = "ly:skyline-pair?";
126
127
128 MAKE_SCHEME_CALLBACK (Skyline_pair, skyline, 2);
129 SCM
130 Skyline_pair::skyline (SCM smob, SCM dir_scm)
131 {
132   Skyline_pair *sp = unsmob<Skyline_pair> (smob);
133   Direction dir = robust_scm2dir (dir_scm, UP);
134
135   if (dir == CENTER)
136     {
137       warning (_f ("direction must not be CENTER in ly:skyline-pair::skyline"));
138       dir = UP;
139     }
140
141   return (*sp)[dir].smobbed_copy ();
142 }