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 class Lazy_skyline_pair | 28 class Lazy_skyline_pair |
29 { | 29 { |
30 Axis a_; | 30 Axis a_; |
31 std::vector<Drul_array<Offset>> todo_; | 31 std::vector<Drul_array<Offset>> todo_; |
32 Skyline_pair skylines_; | 32 Skyline_pair skylines_; |
33 | 33 |
34 public: | 34 public: |
35 Lazy_skyline_pair (Axis a) { a_ = a; } | 35 Lazy_skyline_pair (Axis a) { a_ = a; } |
36 | 36 |
37 void add_segment (Transform const &tr, Offset p1, Offset p2) | 37 void add_segment (Transform const &tr, Offset p1, Offset p2) |
38 { | 38 { |
39 todo_.push_back (Drul_array<Offset> (tr (p1), tr (p2))); | 39 todo_.push_back (Drul_array<Offset> (tr (p1), tr (p2))); |
40 } | 40 } |
41 void add_segment (Transform const &tr, Offset p1, Offset p2, Real thickness) | 41 void add_segment (Transform const &tr, Offset p1, Offset p2, Real thickness) |
42 { | 42 { |
43 Real radius = 0.0; | 43 if (!thickness) { |
44 if (thickness) | 44 add_segment(tr, p1, p2); |
45 { | 45 return; |
46 radius | 46 } |
47 = (tr (Offset (thickness / 2, 0)) - tr (Offset (0, 0))).length (); | 47 Real radius = (tr (Offset (thickness / 2, 0)) - tr (Offset (0, 0))).length (
); |
48 } | |
49 | 48 |
50 Offset widen; | 49 Offset widen; |
51 widen[a_] = radius; | 50 widen[a_] = radius; |
52 Offset pad; | 51 Offset pad; |
53 pad[other_axis (a_)] = radius; | 52 pad[other_axis (a_)] = radius; |
54 | 53 |
55 p1 = tr (p1); | 54 p1 = tr (p1); |
56 p2 = tr (p2); | 55 p2 = tr (p2); |
57 p1 -= widen; | 56 p1 -= widen; |
58 p2 += widen; | 57 p2 += widen; |
59 | 58 |
60 // TODO - should have separate todo_ for UP and DOWN | 59 // TODO - should have separate todo_ for UP and DOWN |
61 todo_.push_back (Drul_array<Offset> (p1 + pad, p2 + pad)); | 60 todo_.push_back (Drul_array<Offset> (p1 + pad, p2 + pad)); |
62 if (thickness) | 61 todo_.push_back (Drul_array<Offset> (p1 - pad, p2 - pad)); |
63 { | |
64 todo_.push_back (Drul_array<Offset> (p1 - pad, p2 - pad)); | |
65 } | |
66 } | 62 } |
67 | 63 |
68 Axis axis () const { return a_; } | 64 Axis axis () const { return a_; } |
69 void add_box (Transform const &tr, Box b) { | 65 void add_box (Transform const &tr, Box b) { |
70 Offset ps[] = {Offset(b[X_AXIS][LEFT],b[Y_AXIS][DOWN]), | 66 Offset ps[] = {Offset(b[X_AXIS][LEFT],b[Y_AXIS][DOWN]), |
71 Offset(b[X_AXIS][LEFT],b[Y_AXIS][UP]), | 67 Offset(b[X_AXIS][LEFT],b[Y_AXIS][UP]), |
72 Offset(b[X_AXIS][RIGHT],b[Y_AXIS][UP]), | 68 Offset(b[X_AXIS][RIGHT],b[Y_AXIS][UP]), |
73 Offset(b[X_AXIS][RIGHT],b[Y_AXIS][DOWN])}; | 69 Offset(b[X_AXIS][RIGHT],b[Y_AXIS][DOWN])}; |
74 for (int i = 0; i < 4; i++) { | 70 for (int i = 0; i < 4; i++) { |
75 add_segment(tr, ps[i], ps[(i+1)%4]); | 71 add_segment(tr, ps[i], ps[(i+1)%4]); |
(...skipping 11 matching lines...) Expand all Loading... |
87 } | 83 } |
88 | 84 |
89 Skyline_pair to_pair () | 85 Skyline_pair to_pair () |
90 { | 86 { |
91 merge (); | 87 merge (); |
92 return skylines_; | 88 return skylines_; |
93 } | 89 } |
94 }; | 90 }; |
95 | 91 |
96 #endif | 92 #endif |
LEFT | RIGHT |