Fri, 23 Mar 2018 21:36:37 +0200
added stream operators to Vertex
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1072 | 3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
1006
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1002
diff
changeset
|
8 | * (at your option) any later version. |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #pragma once |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <QString> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include <QObject> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include <QStringList> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include <QMetaType> |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
24 | #include <QSet> |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
25 | #include <QVector3D> |
1062
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
26 | #include <QVector> |
1136
9a7a945c0e93
Rearranged declarations in basics.h
Teemu Piippo <teemu@hecknology.net>
parents:
1135
diff
changeset
|
27 | #include <QFile> |
1177
8661b9237ed5
Added support for ideal co-ordinates, which should make writing editing tools a lot easier. For some reason they don't yet work with the back and right cameras.
Teemu Piippo <teemu@hecknology.net>
parents:
1162
diff
changeset
|
28 | #include <QMatrix4x4> |
920
147497785496
- fixed stability problems
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
29 | #include <functional> |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
30 | #include <type_traits> |
1058
695edd4f0411
Cleaned up crash catcher, fixed missing <math.h> include
Teemu Piippo <teemu@hecknology.net>
parents:
1056
diff
changeset
|
31 | #include <math.h> |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include "macros.h" |
1017
fc1c13db9618
Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1015
diff
changeset
|
33 | #include "transform.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
1311
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
35 | #if (QT_VERSION < QT_VERSION_CHECK(5, 7, 0)) |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
36 | template <typename... Args> |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
37 | struct QNonConstOverload |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
38 | { |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
39 | template <typename R, typename T> |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
40 | Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr) |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
41 | { return ptr; } |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
42 | template <typename R, typename T> |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
43 | static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr) |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
44 | { return ptr; } |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
45 | }; |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
46 | template <typename... Args> |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
47 | struct QConstOverload |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
48 | { |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
49 | template <typename R, typename T> |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
50 | Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...) const) const Q_DECL_NOTHROW -> decltype(ptr) |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
51 | { return ptr; } |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
52 | template <typename R, typename T> |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
53 | static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...) const) Q_DECL_NOTHROW -> decltype(ptr) |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
54 | { return ptr; } |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
55 | }; |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
56 | template <typename... Args> |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
57 | struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...> |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
58 | { |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
59 | using QConstOverload<Args...>::of; |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
60 | using QConstOverload<Args...>::operator(); |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
61 | using QNonConstOverload<Args...>::of; |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
62 | using QNonConstOverload<Args...>::operator(); |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
63 | template <typename R> |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
64 | Q_DECL_CONSTEXPR auto operator()(R (*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr) |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
65 | { return ptr; } |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
66 | template <typename R> |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
67 | static Q_DECL_CONSTEXPR auto of(R (*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr) |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
68 | { return ptr; } |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
69 | }; |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
70 | template <typename... Args> Q_CONSTEXPR Q_DECL_UNUSED QOverload<Args...> qOverload = {}; |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
71 | template <typename... Args> Q_CONSTEXPR Q_DECL_UNUSED QConstOverload<Args...> qConstOverload = {}; |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
72 | template <typename... Args> Q_CONSTEXPR Q_DECL_UNUSED QNonConstOverload<Args...> qNonConstOverload = {}; |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
73 | #endif |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
74 | |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1136
diff
changeset
|
75 | class Matrix; |
1177
8661b9237ed5
Added support for ideal co-ordinates, which should make writing editing tools a lot easier. For some reason they don't yet work with the back and right cameras.
Teemu Piippo <teemu@hecknology.net>
parents:
1162
diff
changeset
|
76 | using GLRotationMatrix = QMatrix4x4; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | template<typename T, typename R> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | using Pair = std::pair<T, R>; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | enum Axis |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | X, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | Y, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | Z |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | }; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | |
1305
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
88 | enum Winding |
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
89 | { |
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
90 | NoWinding, |
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
91 | CounterClockwise, |
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
92 | Clockwise, |
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
93 | }; |
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
94 | |
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
95 | Winding operator^(Winding one, Winding other); |
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
96 | Winding& operator^=(Winding& one, Winding other); |
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1291
diff
changeset
|
97 | |
1313
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1311
diff
changeset
|
98 | struct Vertex |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
99 | { |
1313
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1311
diff
changeset
|
100 | qreal x, y, z; |
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1311
diff
changeset
|
101 | |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
102 | using ApplyFunction = std::function<void (Axis, double&)>; |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
103 | using ApplyConstFunction = std::function<void (Axis, double)>; |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
104 | |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
105 | void apply (ApplyFunction func); |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
106 | void apply (ApplyConstFunction func) const; |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
784
diff
changeset
|
107 | QString toString (bool mangled = false) const; |
1313
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1311
diff
changeset
|
108 | QVector3D toVector() const; |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
109 | void transform (const Matrix& matr, const Vertex& pos); |
1177
8661b9237ed5
Added support for ideal co-ordinates, which should make writing editing tools a lot easier. For some reason they don't yet work with the back and right cameras.
Teemu Piippo <teemu@hecknology.net>
parents:
1162
diff
changeset
|
110 | Vertex transformed(const GLRotationMatrix& matrix) const; |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
111 | void setCoordinate (Axis ax, qreal value); |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
112 | |
1313
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1311
diff
changeset
|
113 | Vertex& operator+= (const QVector3D& other); |
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1311
diff
changeset
|
114 | Vertex operator+ (const QVector3D& other) const; |
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1311
diff
changeset
|
115 | QVector3D operator- (const Vertex& other) const; |
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1311
diff
changeset
|
116 | Vertex operator- (const QVector3D& vector) const; |
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1311
diff
changeset
|
117 | Vertex& operator-= (const QVector3D& vector); |
1002
a3ee23db8393
Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
118 | Vertex& operator*= (qreal scalar); |
a3ee23db8393
Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
119 | Vertex operator* (qreal scalar) const; |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
120 | bool operator< (const Vertex& other) const; |
1313
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1311
diff
changeset
|
121 | double& operator[] (Axis ax); |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
122 | double operator[] (Axis ax) const; |
1313
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1311
diff
changeset
|
123 | bool operator==(const Vertex& other) const; |
4baed9f54de3
reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents:
1311
diff
changeset
|
124 | bool operator!=(const Vertex& other) const; |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
125 | }; |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
126 | |
1002
a3ee23db8393
Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
127 | inline Vertex operator* (qreal scalar, const Vertex& vertex) |
a3ee23db8393
Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
128 | { |
a3ee23db8393
Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
129 | return vertex * scalar; |
a3ee23db8393
Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
130 | } |
a3ee23db8393
Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
978
diff
changeset
|
131 | |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
132 | Q_DECLARE_METATYPE (Vertex) |
1031
55c0d3beea0d
removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1026
diff
changeset
|
133 | uint qHash(const Vertex& key); |
1314
d94cf95608ac
added stream operators to Vertex
Teemu Piippo <teemu@hecknology.net>
parents:
1313
diff
changeset
|
134 | QDataStream& operator<<(QDataStream& out, const Vertex& vertex); |
d94cf95608ac
added stream operators to Vertex
Teemu Piippo <teemu@hecknology.net>
parents:
1313
diff
changeset
|
135 | QDataStream& operator>>(QDataStream& in, Vertex& vertex); |
d94cf95608ac
added stream operators to Vertex
Teemu Piippo <teemu@hecknology.net>
parents:
1313
diff
changeset
|
136 | |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
137 | |
1064
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
138 | static inline qreal abs(const QVector3D &vector) |
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
139 | { |
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
140 | return vector.length(); |
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
141 | } |
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
142 | |
794 | 143 | // |
144 | // Defines a bounding box that encompasses a given set of objects. | |
145 | // vertex0 is the minimum vertex, vertex1 is the maximum vertex. | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | // |
1013
fa025ba493d8
Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
147 | class BoundingBox |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | { |
794 | 149 | public: |
1013
fa025ba493d8
Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
150 | BoundingBox(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | |
1010
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
152 | void calcVertex (const Vertex& vertex); |
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
153 | Vertex center() const; |
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
154 | bool isEmpty() const; |
794 | 155 | double longestMeasurement() const; |
1010
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
156 | void reset(); |
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
157 | const Vertex& vertex0() const; |
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
158 | const Vertex& vertex1() const; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | |
1013
fa025ba493d8
Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
160 | BoundingBox& operator<< (const Vertex& v); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | |
1010
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
162 | private: |
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
163 | bool m_isEmpty; |
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
164 | Vertex m_vertex0; |
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
165 | Vertex m_vertex1; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | }; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | |
1026
fb320996cce0
Rename Pi to lowercase pi
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1017
diff
changeset
|
168 | static const double pi = 3.14159265358979323846; |
816 | 169 | |
170 | ||
171 | // ============================================================================= | |
172 | // Plural expression | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
173 | template<typename T> |
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
174 | static inline const char* plural (T n) |
816 | 175 | { |
176 | return (n != 1) ? "s" : ""; | |
177 | } | |
178 | ||
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
179 | template<typename T> |
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
180 | bool isZero (T a) |
816 | 181 | { |
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
182 | return qFuzzyCompare (a + 1.0, 1.0); |
816 | 183 | } |
184 | ||
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
185 | template<typename T> |
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
186 | bool isInteger (T a) |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
187 | { |
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
188 | return (qAbs (a - floor(a)) < 0.00001) or (qAbs (a - ceil(a)) < 0.00001); |
847 | 189 | } |
190 | ||
816 | 191 | // |
192 | // Returns true if first arg is equal to any of the other args | |
193 | // | |
194 | template<typename T, typename Arg, typename... Args> | |
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
195 | bool isOneOf (T const& a, Arg const& arg, Args const&... args) |
816 | 196 | { |
197 | if (a == arg) | |
198 | return true; | |
199 | ||
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
200 | return isOneOf (a, args...); |
816 | 201 | } |
202 | ||
203 | template<typename T> | |
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
204 | bool isOneOf (T const&) |
816 | 205 | { |
206 | return false; | |
207 | } | |
1015
92c6ec099075
Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
208 | |
92c6ec099075
Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
209 | inline void toggle (bool& a) |
92c6ec099075
Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
210 | { |
92c6ec099075
Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
211 | a = not a; |
92c6ec099075
Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
212 | } |
1036
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
213 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
214 | // |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
215 | // Iterates an enum |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
216 | // |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
217 | template<typename Enum> |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
218 | struct EnumIterShell |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
219 | { |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
220 | struct Iterator |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
221 | { |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
222 | Iterator(typename std::underlying_type<Enum>::type i) : |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
223 | i(i) {} |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
224 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
225 | Iterator& operator++() { ++i; return *this; } |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
226 | bool operator==(Iterator other) { return i == other.i; } |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
227 | bool operator!=(Iterator other) { return i != other.i; } |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
228 | Enum operator*() const { return Enum(i); } |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
229 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
230 | typename std::underlying_type<Enum>::type i; |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
231 | }; |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
232 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
233 | Iterator begin() |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
234 | { |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
235 | return Iterator(EnumLimits<Enum>::First); |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
236 | }; |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
237 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
238 | Iterator end() |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
239 | { |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1122
diff
changeset
|
240 | return Iterator(EnumLimits<Enum>::Last + 1); |
1036
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
241 | } |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
242 | }; |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
243 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
244 | template<typename Enum> |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
245 | EnumIterShell<Enum> iterateEnum() |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
246 | { |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
247 | return EnumIterShell<Enum>(); |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
248 | } |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
249 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
250 | // Is a value inside an enum? |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
251 | template<typename Enum> |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1122
diff
changeset
|
252 | bool valueInEnum(Enum enumerator) |
1036
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
253 | { |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1122
diff
changeset
|
254 | typename std::underlying_type<Enum>::type index = static_cast<typename std::underlying_type<Enum>::type>(enumerator); |
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1122
diff
changeset
|
255 | return index >= EnumLimits<Enum>::First and index <= EnumLimits<Enum>::Last; |
1053 | 256 | } |
257 | ||
258 | double getRadialPoint(int segment, int divisions, double(*func)(double)); | |
259 | QVector<QLineF> makeCircle(int segments, int divisions, double radius); | |
1181
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
260 | qreal distanceFromPointToRectangle(const QPointF& point, const QRectF& rectangle); |
1062
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
261 | |
1122
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
262 | /* |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
263 | * Implements a ring adapter over T. This class corrects indices given to the element-operator so that they're within bounds. |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
264 | * The maximum amount can be specified manually. |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
265 | * |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
266 | * Example: |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
267 | * |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
268 | * int A[] = {10,20,30,40}; |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
269 | * ring(A)[0] == A[0 % 4] == A[0] |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
270 | * ring(A)[5] == A[5 % 4] == A[1] |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
271 | * ring(A)[-1] == ring(A)[-1 + 4] == A[3] |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
272 | */ |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
273 | template<typename T> |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
274 | class RingAdapter |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
275 | { |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
276 | private: |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
277 | // The private section must come first because _collection is used in decltype() below. |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
278 | T& _collection; |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
279 | const int _count; |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
280 | |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
281 | public: |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
282 | RingAdapter(T& collection, int count) : |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
283 | _collection {collection}, |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
284 | _count {count} {} |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
285 | |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
286 | template<typename IndexType> |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
287 | decltype(_collection[IndexType()]) operator[](IndexType index) |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
288 | { |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
289 | if (_count == 0) |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
290 | { |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
291 | // Argh! ...let the collection deal with this case. |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
292 | return _collection[0]; |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
293 | } |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
294 | else |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
295 | { |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
296 | index %= _count; |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
297 | |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
298 | // Fix negative modulus... |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
299 | if (index < 0) |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
300 | index += _count; |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
301 | |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
302 | return _collection[index]; |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
303 | } |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
304 | } |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
305 | |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
306 | int size() const |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
307 | { |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
308 | return _count; |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
309 | } |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
310 | }; |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
311 | |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
312 | /* |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
313 | * Casts a reference to an enum into a reference to its underlying integer type. |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
314 | */ |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
315 | template<typename T> |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
316 | typename std::underlying_type<T>::type& enum_cast(T& enu) |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
317 | { |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
318 | return *reinterpret_cast<typename std::underlying_type<T>::type*>(&enu); |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
319 | } |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
320 | |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
321 | /* |
1122
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
322 | * Convenience function for RingAdapter so that the template parameter does not have to be provided. The ring amount is assumed |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
323 | * to be the amount of elements in the collection. |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
324 | */ |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
325 | template<typename T> |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
326 | RingAdapter<T> ring(T& collection) |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
327 | { |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
328 | return RingAdapter<T> {collection, countof(collection)}; |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
329 | } |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
330 | |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
331 | /* |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
332 | * Version of ring() that allows manual specification of the count. |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
333 | */ |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
334 | template<typename T> |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
335 | RingAdapter<T> ring(T& collection, int count) |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
336 | { |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
337 | return RingAdapter<T> {collection, count}; |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
338 | } |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
339 | |
1308
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
340 | struct Library |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
341 | { |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
342 | QString path; |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
343 | enum |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
344 | { |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
345 | ReadOnlyStorage, // for official files, etc |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
346 | UnofficialFiles, // put downloaded files here |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
347 | WorkingDirectory, // for editable documents |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
348 | } role = ReadOnlyStorage; |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
349 | |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
350 | bool operator==(const Library& other) const |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
351 | { |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
352 | return (this->path == other.path) and (this->role == other.role); |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
353 | } |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
354 | }; |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
355 | |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
356 | Q_DECLARE_METATYPE(Library) |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
357 | using Libraries = QVector<Library>; |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
358 | |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
359 | QDataStream& operator<<(QDataStream& out, const Library& library); |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
360 | QDataStream& operator>>(QDataStream& in, Library& library); |
dcc8c02530c2
Begin rework to add support for multiple libraries
Teemu Piippo <teemu@hecknology.net>
parents:
1305
diff
changeset
|
361 | |
1062
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
362 | // |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
363 | // Get the amount of elements in something. |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
364 | // |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
365 | template<typename T, size_t N> |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
366 | int countof(T(&)[N]) |
1062
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
367 | { |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
368 | return N; |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
369 | } |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
370 | |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
371 | static inline int countof(const QString& string) |
1062
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
372 | { |
1063
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
373 | return string.length(); |
1062
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
374 | } |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
375 | |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
376 | template<typename T> |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
377 | int countof(const QVector<T>& vector) |
1062
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
378 | { |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
379 | return vector.size(); |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
380 | } |
1063
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
381 | |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
382 | template<typename T> |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
383 | int countof(const QList<T>& vector) |
1063
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
384 | { |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
385 | return vector.size(); |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
386 | } |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
387 | |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
388 | template<typename T> |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
389 | int countof(const QSet<T>& set) |
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
390 | { |
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
391 | return set.size(); |
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
392 | } |
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
393 | |
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
394 | template<typename T> |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
395 | int countof(const std::initializer_list<T>& vector) |
1063
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
396 | { |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
397 | return vector.size(); |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
398 | } |
1122
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
399 | |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
400 | template<typename T> |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
401 | int countof(const RingAdapter<T>& ring) |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
402 | { |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
403 | return ring.size(); |
795d1c3554b9
Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents:
1079
diff
changeset
|
404 | } |
1178
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
405 | |
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
406 | /* |
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
407 | * Extracts the sign of x. |
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
408 | */ |
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
409 | template<typename T> |
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
410 | T sign(T x) |
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
411 | { |
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
412 | if (isZero(x)) |
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
413 | return {}; |
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
414 | else |
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
415 | return x / qAbs(x); |
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
416 | } |
1181
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
417 | |
1273
900f1dfae46b
Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents:
1181
diff
changeset
|
418 | template<> |
900f1dfae46b
Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents:
1181
diff
changeset
|
419 | inline int sign(int x) |
900f1dfae46b
Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents:
1181
diff
changeset
|
420 | { |
900f1dfae46b
Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents:
1181
diff
changeset
|
421 | if (x == 0) |
900f1dfae46b
Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents:
1181
diff
changeset
|
422 | return 0; |
900f1dfae46b
Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents:
1181
diff
changeset
|
423 | else |
900f1dfae46b
Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents:
1181
diff
changeset
|
424 | return x / qAbs(x); |
900f1dfae46b
Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents:
1181
diff
changeset
|
425 | } |
900f1dfae46b
Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents:
1181
diff
changeset
|
426 | |
1181
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
427 | /* |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
428 | * Returns the maximum of a single parameter (the parameter itself). |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
429 | */ |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
430 | template <typename T> |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
431 | T max(T a) |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
432 | { |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
433 | return a; |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
434 | } |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
435 | |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
436 | /* |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
437 | * Returns the maximum of two parameters. |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
438 | */ |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
439 | template <typename T> |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
440 | T max(T a, T b) |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
441 | { |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
442 | return a > b ? a : b; |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
443 | } |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
444 | |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
445 | /* |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
446 | * Returns the maximum of n parameters. |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
447 | */ |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
448 | template <typename T, typename... Rest> |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
449 | T max(T a, Rest&&... rest) |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
450 | { |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
451 | return max(a, max(rest...)); |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
452 | } |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
453 | |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
454 | /* |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
455 | * Returns the minimum of a single parameter (the parameter itself). |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
456 | */ |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
457 | template <typename T> |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
458 | T min(T a) |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
459 | { |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
460 | return a; |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
461 | } |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
462 | |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
463 | /* |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
464 | * Returns the minimum of two parameters. |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
465 | */ |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
466 | template <typename T> |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
467 | T min(T a, T b) |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
468 | { |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
469 | return a < b ? a : b; |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
470 | } |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
471 | |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
472 | /* |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
473 | * Returns the minimum of n parameters. |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
474 | */ |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
475 | template <typename T, typename... Rest> |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
476 | T min(T a, Rest&&... rest) |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
477 | { |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
478 | return min(a, min(rest...)); |
ca6d0ef9aadb
Added polar grid rendering (which is disabled for now).
Teemu Piippo <teemu@hecknology.net>
parents:
1178
diff
changeset
|
479 | } |
1291
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1273
diff
changeset
|
480 | |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1273
diff
changeset
|
481 | /* |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1273
diff
changeset
|
482 | * Assigns the value of a single flag in a flagset |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1273
diff
changeset
|
483 | */ |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1273
diff
changeset
|
484 | template<int Flag, typename T> |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1273
diff
changeset
|
485 | void assignFlag(QFlags<T>& flagset, bool value) |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1273
diff
changeset
|
486 | { |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1273
diff
changeset
|
487 | if (value) |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1273
diff
changeset
|
488 | flagset |= static_cast<T>(Flag); |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1273
diff
changeset
|
489 | else |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1273
diff
changeset
|
490 | flagset &= ~static_cast<T>(Flag); |
9c570a30c98a
Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
1273
diff
changeset
|
491 | } |
1311
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
492 | |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
493 | /* |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
494 | * Returns a singleton of type T, useful for providing a valid but unused |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
495 | * pointer. |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
496 | */ |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
497 | template<typename T> |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
498 | inline T& sink() |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
499 | { |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
500 | static T result; |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
501 | return result; |
8d22e1dd272d
ported qOverload to drop minimum Qt requirement down to 5.5
Teemu Piippo <teemu@hecknology.net>
parents:
1308
diff
changeset
|
502 | } |