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