src/basics.h

Thu, 11 Jan 2018 15:09:44 +0200

author
Santeri Piippo
date
Thu, 11 Jan 2018 15:09:44 +0200
changeset 1231
ce0c9f2e6b9c
parent 1223
4f8fa42aed07
permissions
-rw-r--r--

begin rendering rework

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
1222
34def2630300 happy new year 2018
Santeri Piippo
parents: 1219
diff changeset
3 * Copyright (C) 2013 - 2018 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
1223
4f8fa42aed07 simplified RoundToDecimals
Santeri Piippo
parents: 1222
diff changeset
20 #include <cmath>
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1223
diff changeset
21 #include <QSize>
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QString>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <QObject>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include <QStringList>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include <QMetaType>
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
26 #include <QVector3D>
920
147497785496 - fixed stability problems
Teemu Piippo <crimsondusk64@gmail.com>
parents: 890
diff changeset
27 #include <functional>
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "macros.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 class LDObject;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 class QFile;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 class QTextStream;
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
33 class Matrix;
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
34 class LDDocument;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 using int8 = qint8;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 using int16 = qint16;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 using int32 = qint32;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 using int64 = qint64;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 using uint8 = quint8;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 using uint16 = quint16;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 using uint32 = quint32;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 using uint64 = quint64;
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 920
diff changeset
44 using LDObjectList = QList<LDObject*>;
655
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 template<typename T, typename R>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 using Pair = std::pair<T, R>;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 enum Axis
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 X,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 Y,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 Z
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
56 //
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
57 // Derivative of QVector3D: this class is used for the vertices.
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
58 //
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
59 class Vertex : public QVector3D
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
60 {
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
61 public:
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
62 using ApplyFunction = std::function<void(Axis, double&)>;
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
63 using ApplyConstFunction = std::function<void(Axis, double)>;
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
64
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
65 Vertex();
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
66 Vertex(const QVector3D& a);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
67 Vertex(qreal xpos, qreal ypos, qreal zpos);
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
68
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
69 void apply(ApplyFunction func);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
70 void apply(ApplyConstFunction func) const;
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
71 QString toString(bool mangled = false) const;
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
72 void transform(const Matrix& matr, const Vertex& pos);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
73 void setCoordinate(Axis ax, qreal value);
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
74
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
75 Vertex& operator+= (const Vertex& other);
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
76 Vertex operator+(const Vertex& other) const;
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
77 Vertex& operator*= (qreal scalar);
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
78 Vertex operator*(qreal scalar) const;
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
79 bool operator<(const Vertex& other) const;
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
80 double operator[](Axis ax) const;
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
81 };
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
82
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
83 inline Vertex operator*(qreal scalar, const Vertex& vertex)
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
84 {
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
85 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
86 }
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
87
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
88 Q_DECLARE_METATYPE(Vertex)
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
89
1219
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
90 /*
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
91 * A mathematical 3 x 3 matrix
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
92 */
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 class Matrix
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 {
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
95 public:
1219
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
96 Matrix();
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
97 Matrix(std::initializer_list<double> values);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98
1219
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
99 double determinant() const;
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
100 QString toString() const;
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
101 void zero();
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
102 Matrix& operator=(const Matrix& other);
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
103 Matrix operator*(const Matrix& other) const;
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
104 double& operator[](int idx);
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
105 const double& operator[](int idx) const;
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
106 double& operator()(int row, int column);
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
107 const double& operator()(int row, int column) const;
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
108 bool operator==(const Matrix& other) const;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
110 private:
1219
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
111 double coefficients[9];
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
1219
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
114 inline double& Matrix::operator[](int idx)
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
115 {
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
116 return coefficients[idx];
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
117 }
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
118
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
119 inline const double& Matrix::operator[](int idx) const
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
120 {
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
121 return coefficients[idx];
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
122 }
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
123
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
124 inline double& Matrix::operator()(int row, int column)
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
125 {
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
126 return coefficients[row * 3 + column];
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
127 }
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
128
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
129 inline const double& Matrix::operator()(int row, int column) const
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
130 {
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
131 return coefficients[row * 3 + column];
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
132 }
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
133
8e39b5d7c562 simplified Matrix
Santeri Piippo
parents: 1218
diff changeset
134
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
135 //
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
136 // Defines a bounding box that encompasses a given set of objects.
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
137 // vertex0 is the minimum vertex, vertex1 is the maximum vertex.
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 class LDBoundingBox
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 {
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
141 public:
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
142 LDBoundingBox();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
144 void calcObject(LDObject* obj);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
145 void calcVertex(const Vertex& vertex);
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
146 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
147 bool isEmpty() const;
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
148 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
149 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
150 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
151 const Vertex& vertex1() const;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
153 LDBoundingBox& operator<<(LDObject* obj);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
154 LDBoundingBox& operator<<(const Vertex& v);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
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 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
157 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
158 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
159 Vertex m_vertex1;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 847
diff changeset
162 static const double Pi = 3.14159265358979323846;
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
163
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
164
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
165 // =============================================================================
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
166 // Plural expression
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 847
diff changeset
167 template<typename T>
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
168 static inline const char* plural(T n)
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
169 {
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
170 return (n != 1) ? "s" : "";
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
171 }
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
172
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 847
diff changeset
173 template<typename T>
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
174 bool isZero(T a)
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
175 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
176 return qFuzzyCompare(a + 1.0, 1.0);
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
177 }
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
178
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 847
diff changeset
179 template<typename T>
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
180 bool isInteger(T a)
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 847
diff changeset
181 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
182 return (qAbs(a - floor(a)) < 0.00001) or(qAbs(a - ceil(a)) < 0.00001);
847
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
183 }
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
184
274a7fac44fc - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
185 template<typename T>
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
186 void removeDuplicates(T& a)
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
187 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
188 std::sort(a.begin(), a.end());
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
189 a.erase(std::unique(a.begin(), a.end()), a.end());
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
190 }
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
191
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
192 //
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
193 // Returns true if first arg is equal to any of the other args
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
194 //
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
195 template<typename T, typename Arg, typename... Args>
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
196 bool isOneOf(T const& a, Arg const& arg, Args const&... args)
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
197 {
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
198 if (a == arg)
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
199 return true;
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
200
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
201 return isOneOf(a, args...);
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
202 }
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
203
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
204 template<typename T>
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1010
diff changeset
205 bool isOneOf(T const&)
816
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
206 {
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
207 return false;
9adb822de7b9 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 794
diff changeset
208 }

mercurial