Wed, 16 Oct 2013 15:32:38 +0300
Finally got the ringfinder working! Working on integrating it to ring drawing...
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
4 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
8 | * (at your option) any later version. |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
9 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
14 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #ifndef TYPES_H |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #define TYPES_H |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
22 | #include <QString> |
290
be0c367e7420
Added primitive scanning, replaced parts list in subfile add dialog with it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
288
diff
changeset
|
23 | #include <QObject> |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
24 | #include <deque> |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "common.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
27 | class LDObject; |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
28 | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
29 | typedef QChar qchar; |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
30 | typedef QString str; |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
456
diff
changeset
|
31 | class StringConfig; |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
456
diff
changeset
|
32 | class IntConfig; |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
456
diff
changeset
|
33 | class FloatConfig; |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
34 | class QFile; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
35 | class QTextStream; |
271
d5ec224c1879
Laid down the foundations of the new history system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
270
diff
changeset
|
36 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | typedef unsigned int uint; |
188
4e686b771996
Further removal of hungarian notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
38 | typedef unsigned short ushort; |
4e686b771996
Further removal of hungarian notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
39 | typedef unsigned long ulong; |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
40 | typedef qint8 int8; |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
41 | typedef qint16 int16; |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
42 | typedef qint32 int32; |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
43 | typedef qint64 int64; |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
44 | typedef quint8 uint8; |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
45 | typedef quint16 uint16; |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
46 | typedef quint32 uint32; |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
47 | typedef quint64 uint64; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | template<class T> using initlist = std::initializer_list<T>; |
293
a0ed563e14b2
Added support for regex-based primitive categorization
Santeri Piippo <crimsondusk64@gmail.com>
parents:
290
diff
changeset
|
50 | template<class T, class R> using pair = std::pair<T, R>; |
272
2074672a6554
Cleansed the string class, moved implementations from header to code file
Santeri Piippo <crimsondusk64@gmail.com>
parents:
271
diff
changeset
|
51 | using std::size_t; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | enum Axis { X, Y, Z }; |
274
d232fe4d88a6
Reworked properties a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
273
diff
changeset
|
54 | static const Axis g_Axes[3] = { X, Y, Z }; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | // matrix |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
60 | // |
274
d232fe4d88a6
Reworked properties a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
273
diff
changeset
|
61 | // A mathematical 3 x 3 matrix |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
63 | class matrix |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
64 | { public: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
65 | matrix() {} |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
66 | matrix (initlist<double> vals); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
67 | matrix (double fillval); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
68 | matrix (double vals[]); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
69 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
70 | double determinant () const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
71 | matrix mult (matrix other) const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
72 | void puts () const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
73 | str stringRep () const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
74 | void zero (); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
75 | matrix& operator= (matrix other); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
76 | |
494 | 77 | inline double& val (int idx) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
78 | { return m_vals[idx]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
79 | } |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | |
494 | 81 | inline const double& val (int idx) const |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
82 | { return m_vals[idx]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
83 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
84 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
85 | inline matrix operator* (matrix other) const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
86 | { return mult (other); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
87 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
88 | |
494 | 89 | inline double& operator[] (int idx) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
90 | { return val (idx); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
91 | } |
494 | 92 | inline const double& operator[] (int idx) const |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
93 | { return val (idx); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
94 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
95 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
96 | private: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
97 | double m_vals[9]; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | }; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | // vertex |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
104 | // |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | // Vertex class, contains a single point in 3D space. Not to be confused with |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | // LDVertex, which is a vertex used in an LDraw part file. |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
108 | class vertex |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
109 | { public: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
110 | vertex() {} |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
111 | vertex (double x, double y, double z); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
112 | |
494 | 113 | vertex midpoint (const vertex& other); |
114 | void move (const vertex& other); | |
115 | str stringRep (bool mangled) const; | |
116 | void transform (matrix matr, vertex pos); | |
117 | ||
118 | inline double& coord (int n) | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
119 | { return m_coords[n]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
120 | } |
494 | 121 | |
122 | inline const double& coord (int n) const | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
123 | { return m_coords[n]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
124 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
125 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
126 | inline double& x () |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
127 | { return m_coords[X]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
128 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
129 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
130 | inline const double& x () const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
131 | { return m_coords[X]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
132 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
133 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
134 | inline double& y () |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
135 | { return m_coords[Y]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
136 | } |
191
9bb6a17305ad
Readded BFC red-green view, although determining inversion isn't always correct and it cannot handle CW-certified files...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
189
diff
changeset
|
137 | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
138 | inline const double& y () const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
139 | { return m_coords[Y]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
140 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
141 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
142 | inline double& z () |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
143 | { return m_coords[Z]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
144 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
145 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
146 | inline const double& z () const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
147 | { return m_coords[Z]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
148 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
149 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
150 | vertex& operator+= (const vertex& other); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
151 | vertex operator+ (const vertex& other) const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
152 | vertex operator/ (const double d) const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
153 | vertex& operator/= (const double d); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
154 | bool operator== (const vertex& other) const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
155 | bool operator!= (const vertex& other) const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
156 | vertex operator- () const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
157 | int operator< (const vertex& other) const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
158 | double& operator[] (const Axis ax); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
159 | const double& operator[] (const Axis ax) const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
160 | double& operator[] (const int ax); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
161 | const double& operator[] (const int ax) const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
162 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
163 | private: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
164 | double m_coords[3]; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | }; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | |
251
c4b96bc41298
Made a vector class which wraps around std::vector... finally I have an operator<< for the thing.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
167 | // ============================================================================= |
500
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
168 | // ----------------------------------------------------------------------------- |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
169 | class Line |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
170 | { public: |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
171 | Line() {} |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
172 | Line (const vertex& v0, const vertex v1) : |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
173 | m_v0 (v0), |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
174 | m_v1 (v1) {} |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
175 | |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
176 | inline const vertex& getVertex (int i) const |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
177 | { assert (i == 0 || i == 1); |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
178 | return (i == 0) ? m_v0 : m_v1; |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
179 | } |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
180 | |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
181 | inline void setVertex (int i, const vertex& a) |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
182 | { assert (i == 0 || i == 1); |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
183 | (i == 0) ? m_v0 : m_v1 = a; |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
184 | } |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
185 | |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
186 | inline const vertex& v0() const |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
187 | { return m_v0; |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
188 | } |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
189 | |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
190 | inline const vertex& v1() const |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
191 | { return m_v1; |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
192 | } |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
193 | |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
194 | inline void setV0 (const vertex& a) |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
195 | { m_v0 = a; |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
196 | } |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
197 | |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
198 | inline void setV1 (const vertex& a) |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
199 | { m_v1 = a; |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
200 | } |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
201 | |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
202 | private: |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
203 | vertex m_v0, |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
204 | m_v1; |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
205 | }; |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
206 | |
cad8cdc42a64
Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
207 | // ============================================================================= |
251
c4b96bc41298
Made a vector class which wraps around std::vector... finally I have an operator<< for the thing.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
208 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
c4b96bc41298
Made a vector class which wraps around std::vector... finally I have an operator<< for the thing.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
209 | // ============================================================================= |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
210 | // List |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
211 | // |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
212 | // Array class that wraps around std::deque |
251
c4b96bc41298
Made a vector class which wraps around std::vector... finally I have an operator<< for the thing.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
213 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
214 | template<class T> class List |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
215 | { public: |
494 | 216 | typedef typename std::deque<T>::iterator Iterator; |
217 | typedef typename std::deque<T>::const_iterator ConstIterator; | |
218 | typedef typename std::deque<T>::reverse_iterator ReverseIterator; | |
219 | typedef typename std::deque<T>::const_reverse_iterator ConstReverseIterator; | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
220 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
221 | List() {} |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
222 | List (initlist<T> vals) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
223 | { m_vect = vals; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
224 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
225 | |
494 | 226 | inline Iterator begin() |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
227 | { return m_vect.begin(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
228 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
229 | |
494 | 230 | inline ConstIterator begin() const |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
231 | { return m_vect.cbegin(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
232 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
233 | |
494 | 234 | inline Iterator end() |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
235 | { return m_vect.end(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
236 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
237 | |
494 | 238 | inline ConstIterator end() const |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
239 | { return m_vect.cend(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
240 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
241 | |
494 | 242 | inline ReverseIterator rbegin() |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
243 | { return m_vect.rbegin(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
244 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
245 | |
494 | 246 | inline ConstReverseIterator crbegin() const |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
247 | { return m_vect.crbegin(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
248 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
249 | |
494 | 250 | inline ReverseIterator rend() |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
251 | { return m_vect.rend(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
252 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
253 | |
494 | 254 | inline ConstReverseIterator crend() const |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
255 | { return m_vect.crend(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
256 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
257 | |
498
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
258 | void erase (int pos) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
259 | { assert (pos < size()); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
260 | m_vect.erase (m_vect.begin() + pos); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
261 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
262 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
263 | T& push_back (const T& value) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
264 | { m_vect.push_back (value); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
265 | return m_vect[m_vect.size() - 1]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
266 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
267 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
268 | void push_back (const List<T>& vals) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
269 | { for (const T& val : vals) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
270 | push_back (val); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
271 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
272 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
273 | bool pop (T& val) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
274 | { if (size() == 0) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
275 | return false; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
276 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
277 | val = m_vect[size() - 1]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
278 | erase (size() - 1); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
279 | return true; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
280 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
281 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
282 | T& operator<< (const T& value) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
283 | { return push_back (value); |
273
0a9141118630
Restructed recent files handling, the list shouldn't screw the hell up anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
272
diff
changeset
|
284 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
285 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
286 | void operator<< (const List<T>& vals) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
287 | { push_back (vals); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
288 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
289 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
290 | bool operator>> (T& value) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
291 | { return pop (value); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
292 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
293 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
294 | List<T> reverse() const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
295 | { List<T> rev; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
296 | |
498
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
297 | for (auto it = end() - 1; it != begin(); --it) |
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
298 | rev << *it; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
299 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
300 | return rev; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
301 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
302 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
303 | void clear() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
304 | { m_vect.clear(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
305 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
306 | |
498
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
307 | void insert (int pos, const T& value) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
308 | { m_vect.insert (m_vect.begin() + pos, value); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
309 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
310 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
311 | void makeUnique() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
312 | { // Remove duplicate entries. For this to be effective, the List must be |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
313 | // sorted first. |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
314 | sort(); |
494 | 315 | Iterator pos = std::unique (begin(), end()); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
316 | resize (std::distance (begin(), pos)); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
317 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
318 | |
498
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
319 | int size() const |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
320 | { return m_vect.size(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
321 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
322 | |
498
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
323 | T& operator[] (int n) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
324 | { assert (n < size()); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
325 | return m_vect[n]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
326 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
327 | |
498
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
328 | const T& operator[] (int n) const |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
329 | { assert (n < size()); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
330 | return m_vect[n]; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
331 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
332 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
333 | void resize (std::ptrdiff_t size) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
334 | { m_vect.resize (size); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
335 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
336 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
337 | void sort() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
338 | { std::sort (begin(), end()); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
339 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
340 | |
498
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
341 | int find (const T& needle) |
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
342 | { int i = 0; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
343 | |
498
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
344 | for (const T & hay : *this) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
345 | { if (hay == needle) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
346 | return i; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
347 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
348 | i++; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
349 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
350 | |
498
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
351 | return -1; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
352 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
353 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
354 | private: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
355 | std::deque<T> m_vect; |
251
c4b96bc41298
Made a vector class which wraps around std::vector... finally I have an operator<< for the thing.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
356 | }; |
c4b96bc41298
Made a vector class which wraps around std::vector... finally I have an operator<< for the thing.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
219
diff
changeset
|
357 | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
358 | // ============================================================================= |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
359 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
360 | // ============================================================================= |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
361 | // StringFormatArg |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
362 | // |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
363 | // Converts a given value into a string that can be retrieved with ::value(). |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
364 | // Used as the argument type to the formatting functions, hence its name. |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
365 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
366 | class StringFormatArg |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
367 | { public: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
368 | StringFormatArg (const str& v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
369 | StringFormatArg (const char& v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
370 | StringFormatArg (const uchar& v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
371 | StringFormatArg (const qchar& v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
372 | |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
373 | #define NUMERIC_FORMAT_ARG(T,C) \ |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
374 | StringFormatArg (const T& v) { \ |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
375 | char valstr[32]; \ |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
376 | sprintf (valstr, "%" #C, v); \ |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
377 | m_val = valstr; \ |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
378 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
379 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
380 | NUMERIC_FORMAT_ARG (int, d) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
381 | NUMERIC_FORMAT_ARG (short, d) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
382 | NUMERIC_FORMAT_ARG (long, ld) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
383 | NUMERIC_FORMAT_ARG (uint, u) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
384 | NUMERIC_FORMAT_ARG (ushort, u) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
385 | NUMERIC_FORMAT_ARG (ulong, lu) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
386 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
387 | StringFormatArg (const float& v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
388 | StringFormatArg (const double& v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
389 | StringFormatArg (const vertex& v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
390 | StringFormatArg (const matrix& v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
391 | StringFormatArg (const char* v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
392 | StringFormatArg (const StringConfig& v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
393 | StringFormatArg (const IntConfig& v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
394 | StringFormatArg (const FloatConfig& v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
395 | StringFormatArg (const void* v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
396 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
397 | template<class T> StringFormatArg (const List<T>& v) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
398 | { m_val = "{ "; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
399 | |
498
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
400 | int i = 0; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
401 | |
498
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
494
diff
changeset
|
402 | for (const T& it : v) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
403 | { if (i++) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
404 | m_val += ", "; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
405 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
406 | StringFormatArg arg (it); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
407 | m_val += arg.value(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
408 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
409 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
410 | if (i) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
411 | m_val += " "; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
412 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
413 | m_val += "}"; |
297
2cbd8ac8293b
Added license header to primitives.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
293
diff
changeset
|
414 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
415 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
416 | str value() const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
417 | { return m_val; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
418 | } |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
419 | private: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
420 | str m_val; |
286
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
421 | }; |
7a562bf3d829
Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
274
diff
changeset
|
422 | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
423 | // ============================================================================= |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
424 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
425 | // ============================================================================= |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
426 | // File |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
427 | // |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
428 | // A file interface with simple interface and support for range-for-loops. |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
429 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
430 | class File |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
431 | { private: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
432 | // Iterator class to enable range-for-loop support. Rough hack.. don't use directly! |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
433 | class iterator |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
434 | { public: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
435 | iterator() : m_file (null) {} // end iterator has m_file == null |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
436 | iterator (File* f); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
437 | void operator++(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
438 | str operator*(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
439 | bool operator== (iterator& other); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
440 | bool operator!= (iterator& other); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
441 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
442 | private: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
443 | File* m_file; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
444 | str m_text; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
445 | bool m_gotdata = false; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
446 | }; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
447 | |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
448 | public: |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
449 | enum OpenType |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
450 | { Read, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
451 | Write, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
452 | Append |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
453 | }; |
403
43c1f5b17bfd
Made File::iterator private - it's used only for range-for loops so it should not be used by anything else than File itself.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
402
diff
changeset
|
454 | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
455 | File(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
456 | File (str path, File::OpenType rtype); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
457 | File (FILE* fp, File::OpenType rtype); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
458 | ~File(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
459 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
460 | bool atEnd() const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
461 | iterator begin(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
462 | void close(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
463 | iterator& end(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
464 | bool flush(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
465 | bool isNull() const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
466 | bool readLine (str& line); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
467 | void rewind(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
468 | bool open (FILE* fp, OpenType rtype); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
469 | bool open (str path, OpenType rtype, FILE* fp = null); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
470 | void write (str msg); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
471 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
472 | bool operator!() const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
473 | operator bool() const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
474 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
475 | private: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
476 | QFile* m_file; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
477 | QTextStream* m_textstream; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
478 | iterator m_endIterator; |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
479 | }; |
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
480 | |
380
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
481 | // ============================================================================= |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
482 | // LDBoundingBox |
380
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
483 | // |
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
484 | // The bounding box is the box that encompasses a given set of objects. |
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
485 | // v0 is the minimum vertex, v1 is the maximum vertex. |
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
486 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
487 | class LDBoundingBox |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
488 | { READ_PROPERTY (bool, empty, setEmpty) |
380
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
489 | READ_PROPERTY (vertex, v0, setV0) |
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
490 | READ_PROPERTY (vertex, v1, setV1) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
491 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
492 | public: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
493 | LDBoundingBox(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
494 | void reset(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
495 | void calculate(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
496 | double size() const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
497 | void calcObject (LDObject* obj); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
498 | void calcVertex (const vertex& v); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
499 | vertex center() const; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
500 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
501 | LDBoundingBox& operator<< (LDObject* obj); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
502 | LDBoundingBox& operator<< (const vertex& v); |
380
e442d9b7c251
Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents:
322
diff
changeset
|
503 | }; |
287
3fcccd8c3357
Added a File type that wraps around QFile and provides stuff like a null file and range-for-iterating
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
504 | |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
505 | // Formatter function |
402
ec95fc95e5f3
Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
381
diff
changeset
|
506 | str DoFormat (List<StringFormatArg> args); |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
507 | |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
508 | // printf replacement |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
509 | void doPrint (File& f, initlist<StringFormatArg> args); |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
510 | void doPrint (FILE* f, initlist<StringFormatArg> args); // heh |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
511 | |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
512 | // log() - universal access to the message log. Defined here so that I don't have |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
513 | // to include messagelog.h here and recompile everything every time that file changes. |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
514 | void DoLog (std::initializer_list<StringFormatArg> args); |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
515 | |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
516 | // Macros to access these functions |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
517 | # ifndef IN_IDE_PARSER |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
518 | #define fmt(...) DoFormat ({__VA_ARGS__}) |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
519 | # define print(...) doPrint (g_file_stdout, {__VA_ARGS__}) |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
520 | # define fprint(F, ...) doPrint (F, {__VA_ARGS__}) |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
521 | # define log(...) DoLog({ __VA_ARGS__ }); |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
522 | #else |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
523 | str fmt (const char* fmtstr, ...); |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
524 | void print (const char* fmtstr, ...); |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
525 | void fprint (File& f, const char* fmtstr, ...); |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
403
diff
changeset
|
526 | void log (const char* fmtstr, ...); |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
527 | #endif |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
528 | |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
529 | extern File g_file_stdout; |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
530 | extern File g_file_stderr; |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
531 | extern const vertex g_origin; // Vertex at (0, 0, 0) |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
532 | extern const matrix g_identity; // Identity matrix |
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
533 | |
456 | 534 | static const double pi = 3.14159265358979323846; |
381
241f65769a57
restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents:
380
diff
changeset
|
535 | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
461
diff
changeset
|
536 | #endif // TYPES_H |