src/basics.h

Wed, 08 Jun 2022 23:02:04 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 08 Jun 2022 23:02:04 +0300
changeset 207
5315358a7d91
parent 206
654661eab7f3
child 212
27259810da6d
permissions
-rw-r--r--

well that's embarrassing

3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 /*
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
24
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
3 * Copyright (C) 2013 - 2020 Teemu Piippo
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 *
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 * (at your option) any later version.
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 *
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 * GNU General Public License for more details.
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 *
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 */
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #pragma once
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
20 #include <algorithm>
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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>
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
23 #include <memory>
53
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
24 #include <optional>
96
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents: 92
diff changeset
25 #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
26 #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
27 #include <QDebug>
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 #include <QObject>
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 #include <QPointF>
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 #include <QSet>
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 #include <QString>
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 #include <QStringList>
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 #include <QVariant>
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 #include <QVector>
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
35 #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
36 #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
37 #include "functional.h"
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38
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
39 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
40 using opt = std::optional<T>;
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
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 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
43 Q_DECLARE_METATYPE(glm::mat4)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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 //! \brief count the amount of elements in a basic array
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
46 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
47 constexpr int countof(T(&)[N])
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
48 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
49 return N;
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
50 }
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
51
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
52 //! \brief casts @c x to a suitable unsigned integer
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
53 template<typename T>
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
54 constexpr auto unsigned_cast(T x)
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
55 -> std::enable_if_t<std::is_integral_v<T>, std::make_unsigned_t<T>>
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
56 {
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
57 return static_cast<std::make_unsigned_t<T>>(x);
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
58 }
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
59
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
60 //! \brief casts @c x to a suitable signed integer
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
61 template<typename T>
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
62 constexpr auto signed_cast(T x)
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
63 -> std::enable_if_t<std::is_integral_v<T>, std::make_signed_t<T>>
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
64 {
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
65 return static_cast<std::make_signed_t<T>>(x);
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
66 }
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
67
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
68 //! \brief casts floating point values to float
53
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
69 template<typename T>
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
70 constexpr auto float_cast(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
71 -> std::enable_if_t<std::is_floating_point_v<T>, float>
53
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
72 {
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
73 return static_cast<float>(x);
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
74 }
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
75
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
76 //! \brief casts floating point values to double
53
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
77 template<typename T>
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
78 constexpr auto double_cast(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
79 -> std::enable_if_t<std::is_floating_point_v<T>, double>
53
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
80 {
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
81 return static_cast<double>(x);
3af627f7a40f added grid program
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
82 }
55
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
83
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
84 //! \brief casts floating point values to qreal
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 70
diff changeset
85 template<typename T>
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
86 constexpr auto qreal_cast(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
87 -> std::enable_if_t<std::is_floating_point_v<T>, qreal>
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 70
diff changeset
88 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 70
diff changeset
89 return static_cast<qreal>(x);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 70
diff changeset
90 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 70
diff changeset
91
55
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
92 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
93 constexpr QPointF toQPointF(const glm::vec<N, T, Q>& vec)
55
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
94 {
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
95 return {double_cast(vec.x), double_cast(vec.y)};
55
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
96 }
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
97
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
98 constexpr glm::vec2 toVec2(const QPointF& point)
55
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
99 {
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
100 return {point.x(), point.y()};
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
101 }
cb81ecb5fb23 grid stuff
Teemu Piippo <teemu@hecknology.net>
parents: 53
diff changeset
102
96
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents: 92
diff changeset
103
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
104 template<typename T, typename R, typename K>
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
105 const R* findInMap(const std::map<T, R>& map, K&& key)
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
106 {
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
107 auto pair = map.find(key);
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
108 if (pair != map.end())
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
109 {
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
110 return &pair->second;
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
111 }
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
112 else
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
113 {
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
114 return nullptr;
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
115 }
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
116 }
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
117
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
118 template<typename T, typename R, typename K>
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
119 R* findInMap(std::map<T, R>& map, K&& key)
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
120 {
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
121 auto pair = map.find(key);
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
122 if (pair != map.end())
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
123 {
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
124 return &pair->second;
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
125 }
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
126 else
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
127 {
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
128 return nullptr;
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
129 }
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
130 }
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
131
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
132 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
133 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
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 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
136 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
137 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
138 }
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 }
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
191
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
141 template<typename T = float>
d355d4c52d51 made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
142 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
143
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
144 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
145 {
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 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
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
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
149 //! \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
150 //! 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
151 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
152 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
153 {
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 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
155 }
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 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
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 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
160 .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
161 .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
162 }
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 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
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 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
167 .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
168 .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
169 .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
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 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
173 {
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 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
175 .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
176 .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
177 .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
178 .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
179 }
196
6bcb284679d4 delete unneeded things
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
180
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
181 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
182 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
183 {
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 T 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
185 auto operator<=>(TypeValue other) const = default;
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 };
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 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
189 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
190 {
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 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
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
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 /**
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 * 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
196 */
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 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
198 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
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 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
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 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
203 {
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 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
205 }
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 }
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
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 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
210 {
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 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
212 }
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 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
215 {
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 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
217 }
70
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents: 55
diff changeset
218
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
219 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
220 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
221 {
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 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
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 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
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 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
227 }
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
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 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
230 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
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 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
233 {
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 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
235 });
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 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
237 }
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
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 //! \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
240 //! 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
241 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
242 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
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 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
245 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
246 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
247 }
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 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
249 }
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 // 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
252 // 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
253 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
254 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
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 // 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
257 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
258 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
259 {
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
260 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
261 }
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
262
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
263 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
264 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
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 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
267 }
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 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
270 {
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
271 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
272 {
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
273 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
274 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
275 }
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
276 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
277 {
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
278 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
279 }
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
280 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
281 }
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
282
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
283 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
284 {
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
285 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
286 }
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
287
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
288 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
289 {
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
290 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
291 }
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
292
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
293 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
294 {
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
295 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
296 .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
297 .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
298 .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
299 .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
300 }
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
301
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
302 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
303 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
304 {
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
305 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
306 }

mercurial