Mon, 20 Feb 2017 07:56:21 +0200
Made fixed cameras matrix-based. This simplifies some math.
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> |
920
147497785496
- fixed stability problems
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
28 | #include <functional> |
1058
695edd4f0411
Cleaned up crash catcher, fixed missing <math.h> include
Teemu Piippo <teemu@hecknology.net>
parents:
1056
diff
changeset
|
29 | #include <math.h> |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #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
|
31 | #include "transform.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | class LDObject; |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1136
diff
changeset
|
34 | class Matrix; |
944 | 35 | using LDObjectList = QList<LDObject*>; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | template<typename T, typename R> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | using Pair = std::pair<T, R>; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | enum Axis |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | X, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | Y, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | Z |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | }; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | |
1056
27b7991b3bea
Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents:
1053
diff
changeset
|
47 | static const Axis axes[] = {X, Y, Z}; |
27b7991b3bea
Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents:
1053
diff
changeset
|
48 | |
794 | 49 | // |
50 | // Derivative of QVector3D: this class is used for the vertices. | |
51 | // | |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
52 | class Vertex : public QVector3D |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
53 | { |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
54 | public: |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
55 | 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
|
56 | 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
|
57 | |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
58 | Vertex(); |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
59 | Vertex (const QVector3D& a); |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
60 | Vertex (qreal xpos, qreal ypos, qreal zpos); |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
61 | |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
62 | void apply (ApplyFunction func); |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
63 | void apply (ApplyConstFunction func) const; |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
784
diff
changeset
|
64 | QString toString (bool mangled = false) const; |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
65 | void transform (const Matrix& matr, const Vertex& pos); |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
66 | 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
|
67 | |
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
|
68 | Vertex& operator+= (const Vertex& other); |
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
|
69 | Vertex operator+ (const Vertex& other) const; |
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
|
70 | 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
|
71 | 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
|
72 | bool operator< (const Vertex& other) const; |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
73 | double operator[] (Axis ax) const; |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
74 | }; |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
75 | |
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
|
76 | 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
|
77 | { |
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
|
78 | 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
|
79 | } |
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
|
80 | |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
81 | 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
|
82 | uint qHash(const Vertex& key); |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
83 | |
1064
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
84 | static inline qreal abs(const QVector3D &vector) |
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
85 | { |
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
86 | return vector.length(); |
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
87 | } |
4c7a353cf583
Replaced '.length()' with 'length()' where appropriate
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
88 | |
794 | 89 | // |
90 | // Defines a bounding box that encompasses a given set of objects. | |
91 | // vertex0 is the minimum vertex, vertex1 is the maximum vertex. | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | // |
1013
fa025ba493d8
Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
93 | class BoundingBox |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | { |
794 | 95 | public: |
1013
fa025ba493d8
Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
96 | BoundingBox(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | |
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
|
98 | 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
|
99 | 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
|
100 | bool isEmpty() const; |
794 | 101 | 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
|
102 | 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
|
103 | 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
|
104 | const Vertex& vertex1() const; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
1013
fa025ba493d8
Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1010
diff
changeset
|
106 | BoundingBox& operator<< (const Vertex& v); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
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
|
108 | 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
|
109 | 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
|
110 | 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
|
111 | Vertex m_vertex1; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | }; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
114 | extern const Vertex Origin; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | |
1026
fb320996cce0
Rename Pi to lowercase pi
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1017
diff
changeset
|
116 | static const double pi = 3.14159265358979323846; |
816 | 117 | |
118 | ||
119 | // ============================================================================= | |
120 | // Plural expression | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
121 | 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
|
122 | static inline const char* plural (T n) |
816 | 123 | { |
124 | return (n != 1) ? "s" : ""; | |
125 | } | |
126 | ||
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
127 | 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
|
128 | bool isZero (T a) |
816 | 129 | { |
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
130 | return qFuzzyCompare (a + 1.0, 1.0); |
816 | 131 | } |
132 | ||
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
133 | 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
|
134 | bool isInteger (T a) |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
135 | { |
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
136 | return (qAbs (a - floor(a)) < 0.00001) or (qAbs (a - ceil(a)) < 0.00001); |
847 | 137 | } |
138 | ||
816 | 139 | // |
140 | // Returns true if first arg is equal to any of the other args | |
141 | // | |
142 | 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
|
143 | bool isOneOf (T const& a, Arg const& arg, Args const&... args) |
816 | 144 | { |
145 | if (a == arg) | |
146 | return true; | |
147 | ||
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
148 | return isOneOf (a, args...); |
816 | 149 | } |
150 | ||
151 | 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
|
152 | bool isOneOf (T const&) |
816 | 153 | { |
154 | return false; | |
155 | } | |
1015
92c6ec099075
Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
156 | |
92c6ec099075
Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
157 | 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
|
158 | { |
92c6ec099075
Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
159 | a = not a; |
92c6ec099075
Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
160 | } |
1036
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
161 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
162 | // |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
163 | // Iterates an enum |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
164 | // |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
165 | template<typename Enum> |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
166 | struct EnumIterShell |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
167 | { |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
168 | struct Iterator |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
169 | { |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
170 | 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
|
171 | i(i) {} |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
172 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
173 | 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
|
174 | 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
|
175 | 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
|
176 | 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
|
177 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
178 | 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
|
179 | }; |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
180 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
181 | Iterator begin() |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
182 | { |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
183 | 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
|
184 | }; |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
185 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
186 | Iterator end() |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
187 | { |
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
|
188 | 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
|
189 | } |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
190 | }; |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
191 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
192 | template<typename Enum> |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
193 | EnumIterShell<Enum> iterateEnum() |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
194 | { |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
195 | return EnumIterShell<Enum>(); |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
196 | } |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
197 | |
993c46d7eb75
Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents:
1031
diff
changeset
|
198 | // 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
|
199 | 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
|
200 | 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
|
201 | { |
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
|
202 | 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
|
203 | return index >= EnumLimits<Enum>::First and index <= EnumLimits<Enum>::Last; |
1053 | 204 | } |
205 | ||
206 | double getRadialPoint(int segment, int divisions, double(*func)(double)); | |
207 | QVector<QLineF> makeCircle(int segments, int divisions, double radius); | |
1062
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
208 | |
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
|
209 | /* |
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
|
210 | * 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
|
211 | * 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
|
212 | * |
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
|
213 | * 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
|
214 | * |
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
|
215 | * 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
|
216 | * 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
|
217 | * 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
|
218 | * 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
|
219 | */ |
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
|
220 | 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
|
221 | 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
|
222 | { |
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
|
223 | 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
|
224 | // 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
|
225 | 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
|
226 | 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
|
227 | |
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
|
228 | 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
|
229 | 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
|
230 | _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
|
231 | _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
|
232 | |
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
|
233 | 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
|
234 | 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
|
235 | { |
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
|
236 | 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
|
237 | { |
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
|
238 | // 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
|
239 | 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
|
240 | } |
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
|
241 | 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
|
242 | { |
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
|
243 | 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
|
244 | |
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
|
245 | // 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
|
246 | 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
|
247 | 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
|
248 | |
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
|
249 | 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
|
250 | } |
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
|
251 | } |
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
|
252 | |
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
|
253 | 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
|
254 | { |
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
|
255 | 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
|
256 | } |
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
|
257 | }; |
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
|
258 | |
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
|
259 | /* |
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
|
260 | * 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
|
261 | * 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
|
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 | 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
|
264 | 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
|
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 | 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
|
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 | |
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 | /* |
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 | * 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
|
271 | */ |
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 | 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
|
273 | 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
|
274 | { |
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 | 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
|
276 | } |
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 | |
1062
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
278 | // |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
279 | // 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
|
280 | // |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
281 | 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
|
282 | 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
|
283 | { |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
284 | return N; |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
285 | } |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
286 | |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
287 | 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
|
288 | { |
1063
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
289 | 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
|
290 | } |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
291 | |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
292 | template<typename T> |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
293 | 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
|
294 | { |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
295 | return vector.size(); |
4119185b56ca
refactor: added the length() function that's like Python's len()
Teemu Piippo <teemu@hecknology.net>
parents:
1058
diff
changeset
|
296 | } |
1063
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
297 | |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
298 | template<typename T> |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
299 | 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
|
300 | { |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
301 | return vector.size(); |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
302 | } |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
303 | |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
304 | 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
|
305 | 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
|
306 | { |
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
|
307 | 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
|
308 | } |
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
|
309 | |
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
|
310 | template<typename T> |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1064
diff
changeset
|
311 | 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
|
312 | { |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
313 | return vector.size(); |
1f15c52c11f6
Replaced uses of 'x.size()' with 'length(x)'
Teemu Piippo <teemu@hecknology.net>
parents:
1062
diff
changeset
|
314 | } |
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
|
315 | |
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
|
316 | 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
|
317 | 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
|
318 | { |
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
|
319 | 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
|
320 | } |