Thu, 29 Mar 2018 12:09:03 +0300
Branch close bfc
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 |
844
11587d419d2f
- changed copyright lines to use my legal name instead of my nickname
Teemu Piippo <crimsondusk64@gmail.com>
parents:
818
diff
changeset
|
3 | * Copyright (C) 2013, 2014 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 |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
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> |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
24 | #include <QVector3D> |
768
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
739
diff
changeset
|
25 | #include <QSharedPointer> |
907
cf150959ccc4
- bfc stuff (at least it works now...)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
891
diff
changeset
|
26 | #include <functional> |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | #include "macros.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | class LDObject; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | class QFile; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | class QTextStream; |
768
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
739
diff
changeset
|
32 | 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
|
33 | class LDDocument; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | using int8 = qint8; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | using int16 = qint16; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | using int32 = qint32; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | using int64 = qint64; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | using uint8 = quint8; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | using uint16 = quint16; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | using uint32 = quint32; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | using uint64 = quint64; |
768
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
739
diff
changeset
|
43 | using LDObjectPtr = QSharedPointer<LDObject>; |
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
739
diff
changeset
|
44 | using LDObjectList = QList<LDObjectPtr>; |
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
739
diff
changeset
|
45 | using LDObjectWeakPtr = QWeakPointer<LDObject>; |
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
739
diff
changeset
|
46 | using LDObjectWeakList = QList<LDObjectWeakPtr>; |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
768
diff
changeset
|
47 | using LDDocumentPtr = QSharedPointer<LDDocument>; |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
768
diff
changeset
|
48 | using LDDocumentWeakPtr = QWeakPointer<LDDocument>; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | template<typename T, typename R> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | using Pair = std::pair<T, R>; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | enum Axis |
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 | X, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | Y, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | Z |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | }; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | |
891
00d76b281021
- re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
60 | enum class Winding |
00d76b281021
- re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
61 | { |
00d76b281021
- re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
62 | CW, |
00d76b281021
- re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
63 | CCW, |
00d76b281021
- re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
64 | None |
00d76b281021
- re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
65 | }; |
00d76b281021
- re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
66 | |
00d76b281021
- re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
67 | inline void invertWinding (Winding& winding) |
00d76b281021
- re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
68 | { |
907
cf150959ccc4
- bfc stuff (at least it works now...)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
891
diff
changeset
|
69 | if (winding != Winding::None) |
cf150959ccc4
- bfc stuff (at least it works now...)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
891
diff
changeset
|
70 | winding = Winding (int (winding) ^ 1); |
891
00d76b281021
- re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
71 | } |
00d76b281021
- re-committed bfc work (this makes 903ec1e46298 a suitable common ancestor for experimental branch features)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
890
diff
changeset
|
72 | |
794 | 73 | // |
74 | // Derivative of QVector3D: this class is used for the vertices. | |
75 | // | |
733
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
76 | class Vertex : public QVector3D |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
77 | { |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
78 | public: |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
79 | 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
|
80 | 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
|
81 | |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
82 | Vertex(); |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
83 | Vertex (const QVector3D& a); |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
84 | 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
|
85 | |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
86 | void apply (ApplyFunction func); |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
87 | void apply (ApplyConstFunction func) const; |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
784
diff
changeset
|
88 | 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
|
89 | 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
|
90 | 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
|
91 | |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
92 | 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
|
93 | double operator[] (Axis ax) const; |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
94 | }; |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
95 | |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
96 | Q_DECLARE_METATYPE (Vertex) |
cc39df788660
- reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents:
655
diff
changeset
|
97 | |
794 | 98 | // |
99 | // A mathematical 3 x 3 matrix | |
100 | // | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | class Matrix |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | { |
794 | 103 | public: |
104 | Matrix() {} | |
105 | Matrix (const std::initializer_list<double>& vals); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | |
794 | 107 | // Constructs a matrix all 9 elements initialized to the same value. |
108 | Matrix (double fillval); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | |
794 | 110 | // Constructs a matrix with a C-array. |
111 | // note: @vals is expected to have exactly 9 elements. | |
112 | Matrix (double vals[]); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | |
794 | 114 | // Calculates the matrix's determinant. |
115 | double getDeterminant() const; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | |
794 | 117 | // Multiplies this matrix with @other |
118 | // note: a.mult(b) is not equivalent to b.mult(a)! | |
119 | Matrix mult (const Matrix& other) const; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | |
794 | 121 | // Prints the matrix to stdout. |
122 | void dump() const; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | |
794 | 124 | // Yields a string representation of the matrix. |
125 | QString toString() const; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | |
794 | 127 | // Zeroes the matrix out. |
128 | void zero(); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | |
794 | 130 | // Assigns the matrix values to the values of @other. |
131 | Matrix& operator= (const Matrix& other); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | |
794 | 133 | // Returns a mutable reference to a value by @idx |
134 | inline double& value (int idx) | |
135 | { | |
136 | return m_vals[idx]; | |
137 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | |
794 | 139 | // An overload of value() for const matrices. |
140 | inline const double& value (int idx) const | |
141 | { | |
142 | return m_vals[idx]; | |
143 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | |
794 | 145 | // An operator overload for mult(). |
146 | inline Matrix operator* (const Matrix& other) const | |
147 | { | |
148 | return mult (other); | |
149 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | |
794 | 151 | // An operator overload for value(). |
152 | inline double& operator[] (int idx) | |
153 | { | |
154 | return value (idx); | |
155 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | |
794 | 157 | // An operator overload for value() const. |
158 | inline const double& operator[] (int idx) const | |
159 | { | |
160 | return value (idx); | |
161 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | |
794 | 163 | // Checks whether the two matrices have the same values. |
164 | bool operator== (const Matrix& other) const; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | |
794 | 166 | private: |
167 | double m_vals[9]; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | }; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | |
794 | 170 | // |
171 | // Defines a bounding box that encompasses a given set of objects. | |
172 | // vertex0 is the minimum vertex, vertex1 is the maximum vertex. | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | // |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | class LDBoundingBox |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | PROPERTY (private, bool, isEmpty, setEmpty, STOCK_WRITE) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | PROPERTY (private, Vertex, vertex0, setVertex0, STOCK_WRITE) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | PROPERTY (private, Vertex, vertex1, setVertex1, STOCK_WRITE) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | |
794 | 180 | public: |
181 | // Constructs an empty bounding box. | |
182 | LDBoundingBox(); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | |
794 | 184 | // Clears the bounding box |
185 | void reset(); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | |
794 | 187 | // Calculates the bounding box's values from the objects in the current |
188 | // document. | |
189 | void calculateFromCurrentDocument(); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | |
794 | 191 | // Returns the length of the bounding box on the longest measure. |
192 | double longestMeasurement() const; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | |
794 | 194 | // Calculates the given \c obj to the bounding box, adjusting |
195 | // extremas if necessary. | |
196 | void calcObject (LDObjectPtr obj); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | |
794 | 198 | // Calculates the given \c vertex to the bounding box, adjusting |
199 | // extremas if necessary. | |
200 | void calcVertex (const Vertex& vertex); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | |
794 | 202 | // Yields the center of the bounding box. |
203 | Vertex center() const; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | |
794 | 205 | // An operator overload for calcObject() |
206 | LDBoundingBox& operator<< (LDObjectPtr obj); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | |
794 | 208 | // An operator overload for calcVertex() |
209 | LDBoundingBox& operator<< (const Vertex& v); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | }; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
212 | extern const Vertex Origin; |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
213 | extern const Matrix IdentityMatrix; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
215 | static const double Pi = 3.14159265358979323846; |
816 | 216 | |
217 | ||
218 | // ============================================================================= | |
219 | // Plural expression | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
220 | template<typename T> |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
221 | static inline const char* Plural (T n) |
816 | 222 | { |
223 | return (n != 1) ? "s" : ""; | |
224 | } | |
225 | ||
226 | // ============================================================================= | |
227 | // Templated clamp | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
228 | template<typename T> |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
229 | static inline T Clamp (T a, T min, T max) |
816 | 230 | { |
231 | return (a > max) ? max : (a < min) ? min : a; | |
232 | } | |
233 | ||
234 | // Templated minimum | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
235 | template<typename T> |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
236 | static inline T Min (T a, T b) |
816 | 237 | { |
238 | return (a < b) ? a : b; | |
239 | } | |
240 | ||
241 | // Templated maximum | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
242 | template<typename T> |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
243 | static inline T Max (T a, T b) |
816 | 244 | { |
245 | return (a > b) ? a : b; | |
246 | } | |
247 | ||
248 | // Templated absolute value | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
249 | template<typename T> |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
250 | static inline T Abs (T a) |
816 | 251 | { |
252 | return (a >= 0) ? a : -a; | |
253 | } | |
254 | ||
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
255 | template<typename T> |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
256 | inline bool IsZero (T a) |
816 | 257 | { |
868
6e03c68c81ba
- ring finder now also tries scaling by 10 (3.4, 6.4 -> 34, 64), fixed floating point math argghhhhhhhh
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
258 | return Abs<T> (a) < 0.00001; |
816 | 259 | } |
260 | ||
818
748ba8818af8
- added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents:
816
diff
changeset
|
261 | template<typename T> |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
262 | inline bool IsIntegral (T a) |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
263 | { |
868
6e03c68c81ba
- ring finder now also tries scaling by 10 (3.4, 6.4 -> 34, 64), fixed floating point math argghhhhhhhh
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
264 | return (Abs (a - floor(a)) < 0.00001) or (Abs (a - ceil(a)) < 0.00001); |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
265 | } |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
266 | |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
267 | template<typename T> |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
268 | inline bool IsWithin (T a, T b, T c) |
847 | 269 | { |
270 | return a >= b and a <= c; | |
271 | } | |
272 | ||
273 | template<typename T> | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
274 | void RemoveDuplicates (T& a) |
816 | 275 | { |
276 | std::sort (a.begin(), a.end()); | |
277 | a.erase (std::unique (a.begin(), a.end()), a.end()); | |
278 | } | |
279 | ||
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
280 | inline QString UTF16 (const char16_t* a) |
816 | 281 | { |
282 | if (Q_LIKELY (sizeof(char16_t) == sizeof(unsigned short))) | |
283 | return QString::fromUtf16 (reinterpret_cast<const unsigned short*> (a)); | |
284 | ||
285 | QVector<unsigned short> data; | |
286 | ||
287 | for (const char16_t* ap = &a[0]; *ap != '\u0000'; ++ap) | |
288 | data << *ap; | |
289 | ||
290 | data << '\u0000'; | |
291 | return QString::fromUtf16 (data.constData()); | |
292 | } | |
293 | ||
294 | // | |
295 | // Returns true if first arg is equal to any of the other args | |
296 | // | |
297 | template<typename T, typename Arg, typename... Args> | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
298 | bool Eq (T const& a, Arg const& arg, Args const&... args) |
816 | 299 | { |
300 | if (a == arg) | |
301 | return true; | |
302 | ||
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
303 | return Eq (a, args...); |
816 | 304 | } |
305 | ||
306 | template<typename T> | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
847
diff
changeset
|
307 | bool Eq (T const&) |
816 | 308 | { |
309 | return false; | |
310 | } |