LEFT | RIGHT |
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) 2020 Han-Wen Nienhuys <hanwen@lilypond.org> | 4 Copyright (C) 2020 Han-Wen Nienhuys <hanwen@lilypond.org> |
5 | 5 |
6 LilyPond is free software: you can redistribute it and/or modify | 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 | 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 | 8 the Free Software Foundation, either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
11 LilyPond is distributed in the hope that it will be useful, | 11 LilyPond is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 GNU General Public License for more details. | 14 GNU General Public License for more details. |
15 | 15 |
16 You should have received a copy of the GNU General Public License | 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/>. | 17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>. |
18 */ | 18 */ |
19 | 19 |
20 #ifndef LAZY_SKYLINE_PAIR_HH | 20 #ifndef LAZY_SKYLINE_PAIR_HH |
21 #define LAZY_SKYLINE_PAIR_HH | 21 #define LAZY_SKYLINE_PAIR_HH |
22 | 22 |
23 #include <vector> | |
24 | |
25 #include "skyline-pair.hh" | 23 #include "skyline-pair.hh" |
26 #include "transform.hh" | 24 #include "transform.hh" |
| 25 |
| 26 #include <vector> |
27 | 27 |
28 enum Orientation { | 28 enum Orientation { |
29 CCW = DOWN, | 29 CCW = DOWN, |
30 CW = UP, | 30 CW = UP, |
31 }; | 31 }; |
32 | 32 |
33 class Lazy_skyline_pair | 33 class Lazy_skyline_pair |
34 { | 34 { |
35 Axis a_; | 35 Axis a_; |
36 std::vector<Drul_array<Offset>> todo_; | 36 std::vector<Drul_array<Offset>> todo_; |
37 Drul_array<std::vector<Drul_array<Offset>>> per_dir_todo_; | 37 Drul_array<std::vector<Drul_array<Offset>>> per_dir_todo_; |
38 Skyline_pair skylines_; | 38 Skyline_pair skylines_; |
39 | 39 |
40 public: | 40 public: |
(...skipping 25 matching lines...) Expand all Loading... |
66 Offset widen; | 66 Offset widen; |
67 widen[a_] = radius; | 67 widen[a_] = radius; |
68 Offset pad; | 68 Offset pad; |
69 pad[other_axis (a_)] = radius; | 69 pad[other_axis (a_)] = radius; |
70 | 70 |
71 p1 = tr (p1); | 71 p1 = tr (p1); |
72 p2 = tr (p2); | 72 p2 = tr (p2); |
73 p1 -= widen; | 73 p1 -= widen; |
74 p2 += widen; | 74 p2 += widen; |
75 | 75 |
76 // TODO - should have separate todo_ for UP and DOWN | 76 for (DOWN_and_UP(d)) { |
77 todo_.push_back (Drul_array<Offset> (p1 + pad, p2 + pad)); | 77 per_dir_todo_[d].push_back (Drul_array<Offset> (p1 + d * pad, p2 + d * pad
)); |
78 todo_.push_back (Drul_array<Offset> (p1 - pad, p2 - pad)); | 78 } |
79 } | 79 } |
80 | 80 |
81 Axis axis () const { return a_; } | 81 Axis axis () const { return a_; } |
82 void add_box (Transform const &tr, Box b) { | 82 void add_box (Transform const &tr, Box b) { |
83 Offset ps[] = {Offset(b[X_AXIS][LEFT],b[Y_AXIS][DOWN]), | 83 Offset ps[] = {Offset(b[X_AXIS][LEFT],b[Y_AXIS][DOWN]), |
84 Offset(b[X_AXIS][LEFT],b[Y_AXIS][UP]), | 84 Offset(b[X_AXIS][LEFT],b[Y_AXIS][UP]), |
85 Offset(b[X_AXIS][RIGHT],b[Y_AXIS][UP]), | 85 Offset(b[X_AXIS][RIGHT],b[Y_AXIS][UP]), |
86 Offset(b[X_AXIS][RIGHT],b[Y_AXIS][DOWN])}; | 86 Offset(b[X_AXIS][RIGHT],b[Y_AXIS][DOWN])}; |
87 for (int i = 0; i < 4; i++) { | 87 for (int i = 0; i < 4; i++) { |
88 add_segment(tr, ps[i], ps[(i+1)%4]); | 88 add_contour_segment(tr, CW, ps[i], ps[(i+1)%4]); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 void merge () | 92 void merge () |
93 { | 93 { |
94 for (DOWN_and_UP(d)) { | 94 for (DOWN_and_UP(d)) { |
95 if (todo_.empty () && per_dir_todo_[d].empty()) | 95 if (todo_.empty () && per_dir_todo_[d].empty()) |
96 continue; | 96 continue; |
97 | 97 |
98 per_dir_todo_[d].insert(per_dir_todo_[d].end(), todo_.begin(), todo_.end()
); | 98 per_dir_todo_[d].insert(per_dir_todo_[d].end(), todo_.begin(), todo_.end()
); |
99 skylines_[d].merge(Skyline(per_dir_todo_[d], a_, d)); | 99 skylines_[d].merge(Skyline(per_dir_todo_[d], a_, d)); |
100 per_dir_todo_[d].clear (); | 100 per_dir_todo_[d].clear (); |
101 } | 101 } |
102 todo_.clear(); | 102 todo_.clear(); |
103 } | 103 } |
104 | 104 |
105 Skyline_pair to_pair () | 105 Skyline_pair to_pair () |
106 { | 106 { |
107 merge (); | 107 merge (); |
108 return skylines_; | 108 return skylines_; |
109 } | 109 } |
110 }; | 110 }; |
111 | 111 |
112 #endif | 112 #endif |
LEFT | RIGHT |