Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Delta Between Two Patch Sets: lily/skyline-pair.cc

Issue 5626052: Gets vertical skylines from grob stencils (Closed)
Left Patch Set: Removes call to reverse in non_overlapping_skyline functions Created 13 years ago
Right Patch Set: Run astyle on c++ files Created 12 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« lily/skyline.cc ('K') | « lily/skyline.cc ('k') | lily/slur.cc » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 This file is part of LilyPond, the GNU music typesetter. 2 This file is part of LilyPond, the GNU music typesetter.
3 3
4 Copyright (C) 2008--2012 Han-Wen Nienhuys <hanwen@lilypond.org> 4 Copyright (C) 2008--2012 Han-Wen Nienhuys <hanwen@lilypond.org>
5 5
6 6
7 LilyPond is free software: you can redistribute it and/or modify 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 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 9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
(...skipping 10 matching lines...) Expand all
21 #include "skyline-pair.hh" 21 #include "skyline-pair.hh"
22 22
23 #include "international.hh" 23 #include "international.hh"
24 #include "ly-smobs.icc" 24 #include "ly-smobs.icc"
25 25
26 Skyline_pair::Skyline_pair () 26 Skyline_pair::Skyline_pair ()
27 : skylines_ (Skyline (DOWN), Skyline (UP)) 27 : skylines_ (Skyline (DOWN), Skyline (UP))
28 { 28 {
29 } 29 }
30 30
31 Skyline_pair::Skyline_pair (vector<Box> const &boxes, Real padding, Axis a) 31 Skyline_pair::Skyline_pair (vector<Box> const &boxes, Axis a)
32 : skylines_ (Skyline (boxes, padding, a, DOWN), Skyline (boxes, padding, a, UP )) 32 : skylines_ (Skyline (boxes, a, DOWN), Skyline (boxes, a, UP))
33 { 33 {
34 } 34 }
35 35
36 Skyline_pair::Skyline_pair (vector<Drul_array<Offset> > const &buildings, Real p adding, Axis a) 36 Skyline_pair::Skyline_pair (vector<Drul_array<Offset> > const &buildings, Axis a )
37 : skylines_ (Skyline (buildings, padding, a, DOWN), Skyline (buildings, paddin g, a, UP)) 37 : skylines_ (Skyline (buildings, a, DOWN), Skyline (buildings, a, UP))
38 { 38 {
39 } 39 }
40 40
41 Skyline_pair::Skyline_pair (vector<Skyline_pair> const &skypairs, Real padding, Axis a) 41 Skyline_pair::Skyline_pair (vector<Skyline_pair> const &skypairs)
42 : skylines_ (Skyline (skypairs, padding, a, DOWN), Skyline (skypairs, padding, a, UP)) 42 : skylines_ (Skyline (skypairs, DOWN), Skyline (skypairs, UP))
43 { 43 {
44 } 44 }
45 45
46 Skyline_pair::Skyline_pair (Box const &b, Real padding, Axis a) 46 Skyline_pair::Skyline_pair (Box const &b, Axis a)
47 : skylines_ (Skyline (b, padding, a, DOWN), Skyline (b, padding, a, UP)) 47 : skylines_ (Skyline (b, a, DOWN), Skyline (b, a, UP))
48 { 48 {
49 } 49 }
50 50
51 void 51 void
52 Skyline_pair::raise (Real r) 52 Skyline_pair::raise (Real r)
53 { 53 {
54 skylines_[UP].raise (r); 54 skylines_[UP].raise (r);
55 skylines_[DOWN].raise (r); 55 skylines_[DOWN].raise (r);
56 } 56 }
57 57
58 void 58 void
59 Skyline_pair::deholify ()
60 {
61 skylines_[UP].deholify ();
62 skylines_[DOWN].deholify ();
63 }
64
65 void
59 Skyline_pair::shift (Real r) 66 Skyline_pair::shift (Real r)
60 { 67 {
61 skylines_[UP].shift (r); 68 skylines_[UP].shift (r);
62 skylines_[DOWN].shift (r); 69 skylines_[DOWN].shift (r);
63 } 70 }
64 71
65 void 72 void
66 Skyline_pair::insert (Box const &b, Real padding, Axis a) 73 Skyline_pair::insert (Box const &b, Axis a)
67 { 74 {
68 skylines_[UP].insert (b, padding, a); 75 skylines_[UP].insert (b, a);
69 skylines_[DOWN].insert (b, padding, a); 76 skylines_[DOWN].insert (b, a);
70 } 77 }
71 78
72 Real 79 Real
73 Skyline_pair::left () 80 Skyline_pair::left () const
74 { 81 {
75 return min (skylines_[UP].left (), skylines_[DOWN].left ()); 82 return min (skylines_[UP].left (), skylines_[DOWN].left ());
76 } 83 }
77 84
78 Real 85 Real
79 Skyline_pair::right () 86 Skyline_pair::right () const
80 { 87 {
81 return max (skylines_[UP].right (), skylines_[DOWN].right ()); 88 return max (skylines_[UP].right (), skylines_[DOWN].right ());
89 }
90
91 // This function comes with the same caveats as smallest_shift:
92 // if the skylines are not contiguous, we may report false
93 // intersections.
94 bool
95 Skyline_pair::intersects (Skyline_pair const &other) const
96 {
97 return skylines_[UP].distance (other[DOWN]) > 0
98 && other[UP].distance (skylines_[DOWN]) > 0;
99 }
100
101 Real
102 Skyline_pair::smallest_shift (Skyline_pair const &other, Direction d,
103 Real h_pad, Real v_pad)
104 {
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
109 // in the case of
110 // AAA
111 // BBBBBB
112 // AAA
113 // will result in
114 // AAA
115 // BBBBBB
116 // AAA
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.
120
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 ));
82 } 123 }
83 124
84 void 125 void
85 Skyline_pair::merge (Skyline_pair const &other) 126 Skyline_pair::merge (Skyline_pair const &other)
86 { 127 {
87 skylines_[UP].merge (other[UP]); 128 skylines_[UP].merge (other[UP]);
88 skylines_[DOWN].merge (other[DOWN]); 129 skylines_[DOWN].merge (other[DOWN]);
89 } 130 }
90 131
91 void 132 void
92 Skyline_pair::print () const 133 Skyline_pair::print () const
93 { 134 {
94 skylines_[UP].print (); 135 skylines_[UP].print ();
95 skylines_[DOWN].print (); 136 skylines_[DOWN].print ();
96 } 137 }
97 138
98 void 139 void
99 Skyline_pair::print_points () const 140 Skyline_pair::print_points () const
100 { 141 {
101 skylines_[UP].print_points (); 142 skylines_[UP].print_points ();
102 skylines_[DOWN].print_points (); 143 skylines_[DOWN].print_points ();
103 } 144 }
104 145
105 bool 146 bool
106 Skyline_pair::is_empty () const 147 Skyline_pair::is_empty () const
107 { 148 {
108 return skylines_[UP].is_empty () 149 return skylines_[UP].is_empty ()
109 && skylines_[DOWN].is_empty (); 150 && skylines_[DOWN].is_empty ();
151 }
152
153 bool
154 Skyline_pair::is_singleton () const
155 {
156 return skylines_[UP].is_singleton ()
157 && skylines_[DOWN].is_singleton ();
110 } 158 }
111 159
112 Skyline & 160 Skyline &
113 Skyline_pair::operator [] (Direction d) 161 Skyline_pair::operator [] (Direction d)
114 { 162 {
115 return skylines_[d]; 163 return skylines_[d];
116 } 164 }
117 165
118 Skyline const & 166 Skyline const &
119 Skyline_pair::operator [] (Direction d) const 167 Skyline_pair::operator [] (Direction d) const
(...skipping 29 matching lines...) Expand all
149 Direction dir = robust_scm2dir (dir_scm, UP); 197 Direction dir = robust_scm2dir (dir_scm, UP);
150 198
151 if (dir == CENTER) 199 if (dir == CENTER)
152 { 200 {
153 warning (_f ("direction must not be CENTER in ly:skyline-pair::skyline")); 201 warning (_f ("direction must not be CENTER in ly:skyline-pair::skyline"));
154 dir = UP; 202 dir = UP;
155 } 203 }
156 204
157 return (*sp)[dir].smobbed_copy (); 205 return (*sp)[dir].smobbed_copy ();
158 } 206 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b