Mon, 20 Jun 2022 02:04:51 +0300
Add base code for circular primitives
3 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
24 | 3 | * Copyright (C) 2013 - 2020 Teemu Piippo |
3 | 4 | * |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #pragma once | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
20 | #include <algorithm> |
3 | 21 | #include <cmath> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
22 | #include <compare> |
213
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
23 | #include <deque> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
24 | #include <memory> |
53 | 25 | #include <optional> |
212
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
26 | #include <set> |
96 | 27 | #include <type_traits> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
28 | #include <QDataStream> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
29 | #include <QDebug> |
3 | 30 | #include <QObject> |
31 | #include <QPointF> | |
32 | #include <QSet> | |
33 | #include <QString> | |
34 | #include <QStringList> | |
35 | #include <QVariant> | |
36 | #include <QVector> | |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
37 | #include <glm/glm.hpp> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
38 | #include "geometry.h" |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
39 | #include "functional.h" |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
40 | #include "typeconversions.h" |
3 | 41 | |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
42 | template<typename T> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
43 | using opt = std::optional<T>; |
26 | 44 | |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
45 | Q_DECLARE_METATYPE(glm::vec3) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
46 | Q_DECLARE_METATYPE(glm::mat4) |
3 | 47 | |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
48 | //! \brief count the amount of elements in a basic array |
21 | 49 | template<typename T, int N> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
50 | constexpr int countof(T(&)[N]) |
21 | 51 | { |
52 | return N; | |
53 | } | |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
54 | |
55 | 55 | template<int N, typename T, glm::qualifier Q> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
56 | constexpr QPointF toQPointF(const glm::vec<N, T, Q>& vec) |
55 | 57 | { |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
58 | return {double_cast(vec.x), double_cast(vec.y)}; |
55 | 59 | } |
60 | ||
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
61 | constexpr glm::vec2 toVec2(const QPointF& point) |
55 | 62 | { |
63 | return {point.x(), point.y()}; | |
64 | } | |
65 | ||
96 | 66 | |
148 | 67 | template<typename T, typename R, typename K> |
68 | const R* findInMap(const std::map<T, R>& map, K&& key) | |
69 | { | |
70 | auto pair = map.find(key); | |
71 | if (pair != map.end()) | |
72 | { | |
73 | return &pair->second; | |
74 | } | |
75 | else | |
76 | { | |
77 | return nullptr; | |
78 | } | |
79 | } | |
80 | ||
81 | template<typename T, typename R, typename K> | |
82 | R* findInMap(std::map<T, R>& map, K&& key) | |
83 | { | |
212
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
84 | static_assert(std::is_convertible_v<K, T>, "bad type for key parameter"); |
148 | 85 | auto pair = map.find(key); |
86 | if (pair != map.end()) | |
87 | { | |
88 | return &pair->second; | |
89 | } | |
90 | else | |
91 | { | |
92 | return nullptr; | |
93 | } | |
94 | } | |
95 | ||
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
96 | template<typename T, typename R> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
97 | void removeFromMap(std::map<T, R>& map, T&& key) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
98 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
99 | const auto it = map.find(key); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
100 | if (it != map.end()) { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
101 | map.erase(it); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
102 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
103 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
104 | |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
105 | template<typename T = float> |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
106 | constexpr std::enable_if_t<std::is_floating_point_v<T>, T> pi = static_cast<T>(M_PIl); |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
107 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
108 | inline QSizeF sizeToSizeF(const QSize& size) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
109 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
110 | return {static_cast<qreal>(size.width()), static_cast<qreal>(size.height())}; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
111 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
112 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
113 | //! \brief Hints to the specified vector that a certain amount of new elements |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
114 | //! are going to be added. |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
115 | template<typename T> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
116 | void reserveMore(std::vector<T>& vector, std::size_t amount) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
117 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
118 | vector.reserve(vector.size() + amount); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
119 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
120 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
121 | inline QString vectorToString(const glm::vec2& vec) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
122 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
123 | return QStringLiteral("(%1, %2)") |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
124 | .arg(double_cast(vec.x)) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
125 | .arg(double_cast(vec.y)); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
126 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
127 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
128 | inline QString vectorToString(const glm::vec3& vec) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
129 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
130 | return QStringLiteral("(%1, %2, %3)") |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
131 | .arg(double_cast(vec.x)) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
132 | .arg(double_cast(vec.y)) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
133 | .arg(double_cast(vec.z)); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
134 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
135 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
136 | inline QString vectorToString(const glm::vec4& vec) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
137 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
138 | return QStringLiteral("%1, %2, %3, %4)") |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
139 | .arg(double_cast(vec.x)) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
140 | .arg(double_cast(vec.y)) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
141 | .arg(double_cast(vec.z)) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
142 | .arg(double_cast(vec.w)); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
143 | } |
196 | 144 | |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
145 | template<typename T, typename IdentifierType> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
146 | struct TypeValue |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
147 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
148 | T value; |
213
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
149 | auto operator<=>(const TypeValue& other) const = default; |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
150 | }; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
151 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
152 | template<typename T, typename R> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
153 | int qHash(TypeValue<T, R> value) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
154 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
155 | return qHash(value.value); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
156 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
157 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
158 | /** |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
159 | * Iterates a @c glm::mat |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
160 | */ |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
161 | template<int X, int Y, typename T, glm::qualifier Q, typename Fn> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
162 | void iter_matrix(const glm::mat<X, Y, T, Q>& matrix, Fn&& fn) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
163 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
164 | for (int i = 0; i < X; ++i) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
165 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
166 | for (int j = 0; j < Y; ++j) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
167 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
168 | fn(i, j, matrix[i][j]); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
169 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
170 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
171 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
172 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
173 | inline QDataStream& operator<<(QDataStream& stream, const glm::vec3& vec) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
174 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
175 | return stream << vec.x << vec.y << vec.z; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
176 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
177 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
178 | inline QDataStream& operator>>(QDataStream& stream, glm::vec3& vec) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
179 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
180 | return stream >> vec.x >> vec.y >> vec.z; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
181 | } |
70 | 182 | |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
183 | template<int X, int Y, typename T, glm::qualifier Q> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
184 | QDataStream& operator<<(QDataStream& stream, const glm::mat<X, Y, T, Q>& mat) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
185 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
186 | iter_matrix(mat, [&stream](int, int, float x) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
187 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
188 | stream << x; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
189 | }); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
190 | return stream; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
191 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
192 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
193 | template<int X, int Y, typename T, glm::qualifier Q> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
194 | QDataStream& operator>>(QDataStream& stream, glm::mat<X, Y, T, Q>& mat) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
195 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
196 | iter_matrix(mat, [&stream](int, int, float x) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
197 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
198 | stream >> x; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
199 | }); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
200 | return stream; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
201 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
202 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
203 | //! \brief Converts a pointer value to an \c std::optional value. If p has a |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
204 | //! value, it will be copied into the result value. |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
205 | template<typename T> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
206 | std::optional<T> pointerToOptional(const T* p) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
207 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
208 | std::optional<T> result; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
209 | if (p != nullptr) { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
210 | result = *p; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
211 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
212 | return result; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
213 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
214 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
215 | // some magic code from https://en.cppreference.com/w/cpp/utility/variant/visit |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
216 | // for use with std::visit |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
217 | template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; }; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
218 | template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
219 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
220 | // http://stackoverflow.com/a/18204188/3629665 |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
221 | template<typename T> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
222 | constexpr T rotl10(T x) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
223 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
224 | return (x << 10) | ((x >> 22) & 0x000000ff); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
225 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
226 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
227 | template<typename T> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
228 | constexpr T rotl20(T x) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
229 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
230 | return (x << 20) | ((x >> 12) & 0x000000ff); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
231 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
232 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
233 | inline QString quoted(QString string) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
234 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
235 | if (string.contains("'")) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
236 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
237 | string.replace("\"", "\\\""); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
238 | string = "\"" + string + "\""; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
239 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
240 | else |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
241 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
242 | string = "'" + string + "'"; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
243 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
244 | return string; |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
245 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
246 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
247 | inline QString vertexToString(const glm::vec3& vertex) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
248 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
249 | return QStringLiteral("%1 %2 %3").arg(vertex.x).arg(vertex.y).arg(vertex.z); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
250 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
251 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
252 | inline QString vertexToStringParens(const glm::vec3& vertex) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
253 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
254 | return QStringLiteral("(%1 %2 %3)").arg(vertex.x).arg(vertex.y).arg(vertex.z); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
255 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
256 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
257 | inline QString transformToString(const glm::mat4& matrix) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
258 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
259 | return QStringLiteral("%1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12") |
207
5315358a7d91
well that's embarrassing
Teemu Piippo <teemu@hecknology.net>
parents:
206
diff
changeset
|
260 | .arg(matrix[3][0]).arg(matrix[3][1]).arg(matrix[3][2]) |
5315358a7d91
well that's embarrassing
Teemu Piippo <teemu@hecknology.net>
parents:
206
diff
changeset
|
261 | .arg(matrix[0][0]).arg(matrix[1][0]).arg(matrix[2][0]) |
5315358a7d91
well that's embarrassing
Teemu Piippo <teemu@hecknology.net>
parents:
206
diff
changeset
|
262 | .arg(matrix[0][1]).arg(matrix[1][1]).arg(matrix[2][1]) |
5315358a7d91
well that's embarrassing
Teemu Piippo <teemu@hecknology.net>
parents:
206
diff
changeset
|
263 | .arg(matrix[0][2]).arg(matrix[1][2]).arg(matrix[2][2]); |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
264 | } |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
265 | |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
266 | template<typename T, glm::qualifier Q> |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
267 | constexpr unsigned int qHash(const glm::vec<3, T, Q>& key) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
268 | { |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
269 | return qHash(key.x) ^ rotl10(qHash(key.y)) ^ rotl20(qHash(key.z)); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
196
diff
changeset
|
270 | } |
212
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
271 | |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
213
diff
changeset
|
272 | template<typename T, typename Fn> |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
213
diff
changeset
|
273 | void forValueInMap(T&& map, Fn&& fn) |
212
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
274 | { |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
275 | for (const auto& it : map) { |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
276 | fn(it.second); |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
277 | } |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
278 | } |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
279 | |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
280 | inline QString joined(QString value, const QString& separator, const QString& element) |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
281 | { |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
282 | if (not value.isEmpty()) { |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
283 | value += separator; |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
284 | } |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
285 | value += element; |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
286 | return value; |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
207
diff
changeset
|
287 | } |
213
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
288 | |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
289 | template<typename T> |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
290 | struct GraphEdge |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
291 | { |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
292 | T from; |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
293 | T to; |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
294 | }; |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
295 | |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
296 | template<typename T> |
ee5758ddb6d2
Rewrite prune to use graphs rather than O(n²) searches
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
297 | using Graph = std::deque<GraphEdge<T>>; |