src/types.cpp

Fri, 02 Aug 2013 16:33:30 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 02 Aug 2013 16:33:30 +0300
changeset 421
7d26db0be944
parent 409
8da2563c645a
child 455
c5d14d112034
permissions
-rw-r--r--

style cleanup - it should be all unified now

230
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
1 /*
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
2 * LDForge: LDraw parts authoring CAD
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
3 * Copyright (C) 2013 Santeri Piippo
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
4 *
230
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
5 * This program is free software: you can redistribute it and/or modify
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
6 * it under the terms of the GNU General Public License as published by
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
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: 409
diff changeset
8 * (at your option) any later version.
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
9 *
230
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
10 * This program is distributed in the hope that it will be useful,
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
13 * GNU General Public License for more details.
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
14 *
230
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
15 * You should have received a copy of the GNU General Public License
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
17 */
43d722c255d3 Added support for overpaint-less mode since I'm having serious trouble with that
Santeri Piippo <crimsondusk64@gmail.com>
parents: 219
diff changeset
18
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
19 #include <QObject>
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
20 #include <QStringList>
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
21 #include <QTextStream>
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
22 #include <qfile.h>
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <assert.h>
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "common.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "types.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "misc.h"
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
27 #include "ldtypes.h"
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
28 #include "file.h"
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
30 str DoFormat (List<StringFormatArg> args) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
31 assert (args.size() >= 1);
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
32 str text = args[0].value();
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
33
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
34 for (uchar i = 1; i < args.size(); ++i)
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
35 text = text.arg (args[i].value());
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
36
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
37 return text;
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
38 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
39
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
40 vertex::vertex (double x, double y, double z) {
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: 183
diff changeset
41 m_coords[X] = x;
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: 183
diff changeset
42 m_coords[Y] = y;
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: 183
diff changeset
43 m_coords[Z] = z;
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: 183
diff changeset
44 }
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: 183
diff changeset
45
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 // =============================================================================
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
47 void vertex::move (const vertex& other) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
48 for (const Axis ax : g_Axes)
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: 183
diff changeset
49 m_coords[ax] += other[ax];
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: 183
diff changeset
50 }
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: 183
diff changeset
51
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 // =============================================================================
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
53 vertex vertex::midpoint (const vertex& other) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 vertex mid;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
56 for (const Axis ax : g_Axes)
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
57 mid[ax] = (m_coords[ax] + other[ax]) / 2;
183
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 return mid;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 // =============================================================================
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
63 str vertex::stringRep (bool mangled) const {
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
64 str fmtstr = "%1 %2 %3";
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
65 if (mangled)
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
66 fmtstr = "(%1, %2, %3)";
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
67
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
68 return fmt (fmtstr, coord (X), coord (Y), coord (Z));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 // =============================================================================
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
72 void vertex::transform (matrix matr, vertex pos) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
73 double x2 = (matr[0] * x()) + (matr[1] * y()) + (matr[2] * z()) + pos[X];
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
74 double y2 = (matr[3] * x()) + (matr[4] * y()) + (matr[5] * z()) + pos[Y];
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
75 double z2 = (matr[6] * x()) + (matr[7] * y()) + (matr[8] * z()) + pos[Z];
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
77 x() = x2;
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
78 y() = y2;
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
79 z() = z2;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
82 vertex vertex::operator-() const {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
83 return vertex (-m_coords[X], -m_coords[Y], -m_coords[Z]);
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: 183
diff changeset
84 }
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: 183
diff changeset
85
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
86 bool vertex::operator!= (const vertex& other) const {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
87 return !operator== (other);
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
88 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
89
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
90 double& vertex::operator[] (const Axis ax) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
91 return coord ((ushort) ax);
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: 183
diff changeset
92 }
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: 183
diff changeset
93
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
94 const double& vertex::operator[] (const Axis ax) const {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
95 return coord ((ushort) ax);
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: 183
diff changeset
96 }
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: 183
diff changeset
97
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
98 double& vertex::operator[] (const int ax) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
99 return coord (ax);
219
70eb948a2b02 Added ability to set the depth value to something else than 0.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
100 }
70eb948a2b02 Added ability to set the depth value to something else than 0.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
101
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
102 const double& vertex::operator[] (const int ax) const {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
103 return coord (ax);
219
70eb948a2b02 Added ability to set the depth value to something else than 0.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
104 }
70eb948a2b02 Added ability to set the depth value to something else than 0.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
105
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
106 bool vertex::operator== (const vertex& other) const {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
107 return coord (X) == other[X] &&
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
108 coord (Y) == other[Y] &&
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
109 coord (Z) == other[Z];
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: 183
diff changeset
110 }
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: 183
diff changeset
111
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
112 vertex& vertex::operator/= (const double d) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
113 for (const Axis ax : g_Axes)
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: 183
diff changeset
114 m_coords[ax] /= d;
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: 183
diff changeset
115
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: 183
diff changeset
116 return *this;
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: 183
diff changeset
117 }
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: 183
diff changeset
118
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
119 vertex vertex::operator/ (const double d) const {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
120 vertex other (*this);
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: 183
diff changeset
121 return other /= d;
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: 183
diff changeset
122 }
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: 183
diff changeset
123
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
124 vertex& vertex::operator+= (const vertex& other) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
125 move (other);
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: 183
diff changeset
126 return *this;
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: 183
diff changeset
127 }
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: 183
diff changeset
128
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
129 vertex vertex::operator+ (const vertex& other) const {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
130 vertex newvert (*this);
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
131 newvert.move (other);
268
778eed342ee4 Make LDMatrixObject's transform and pos members properties
Santeri Piippo <crimsondusk64@gmail.com>
parents: 261
diff changeset
132 return newvert;
778eed342ee4 Make LDMatrixObject's transform and pos members properties
Santeri Piippo <crimsondusk64@gmail.com>
parents: 261
diff changeset
133 }
778eed342ee4 Make LDMatrixObject's transform and pos members properties
Santeri Piippo <crimsondusk64@gmail.com>
parents: 261
diff changeset
134
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
135 int vertex::operator< (const vertex& other) const {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
136 if (operator== (other))
261
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
137 return false;
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
138
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
139 if (coord (X) < other[X])
261
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
140 return true;
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
141
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
142 if (coord (X) > other[X])
261
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
143 return false;
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
144
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
145 if (coord (Y) < other[Y])
261
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
146 return true;
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
147
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
148 if (coord (Y) > other[Y])
261
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
149 return false;
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
150
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
151 return coord (Z) < other[Z];
261
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
152 }
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
153
c4ad4e3c6839 Added ability to snap to pre-existing vertices while drawing, added changelog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 230
diff changeset
154 // =============================================================================
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
155 matrix::matrix (double vals[]) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
156 for (short i = 0; i < 9; ++i)
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: 183
diff changeset
157 m_vals[i] = vals[i];
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: 183
diff changeset
158 }
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: 183
diff changeset
159
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
160 matrix::matrix (double fillval) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
161 for (short i = 0; i < 9; ++i)
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: 183
diff changeset
162 m_vals[i] = fillval;
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: 183
diff changeset
163 }
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: 183
diff changeset
164
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
165 matrix::matrix (initlist<double> vals) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
166 assert (vals.size() == 9);
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
167 memcpy (&m_vals[0], & (*vals.begin()), sizeof m_vals);
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: 183
diff changeset
168 }
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
169
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
170 void matrix::puts() const {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
171 for (short i = 0; i < 3; ++i) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
172 for (short j = 0; j < 3; ++j)
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
173 print ("%1\t", m_vals[ (i * 3) + j]);
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: 183
diff changeset
174
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
175 print ("\n");
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: 183
diff changeset
176 }
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: 183
diff changeset
177 }
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: 183
diff changeset
178
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: 183
diff changeset
179 // =============================================================================
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
180 str matrix::stringRep() const {
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: 183
diff changeset
181 str val;
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
182
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
183 for (short i = 0; i < 9; ++i) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
184 if (i > 0)
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: 183
diff changeset
185 val += ' ';
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: 183
diff changeset
186
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
187 val += ftoa (m_vals[i]);
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: 183
diff changeset
188 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 288
diff changeset
190 return val;
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: 183
diff changeset
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: 183
diff changeset
192
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: 183
diff changeset
193 // =============================================================================
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
194 void matrix::zero() {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
195 memset (&m_vals[0], 0, sizeof (double) * 9);
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: 183
diff changeset
196 }
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: 183
diff changeset
197
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: 183
diff changeset
198 // =============================================================================
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
199 matrix matrix::mult (matrix other) const {
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: 183
diff changeset
200 matrix val;
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
201 val.zero();
211
8d35e631bef3 Added dialog for rotation points
Santeri Piippo <crimsondusk64@gmail.com>
parents: 191
diff changeset
202
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
203 for (short i = 0; i < 3; ++i)
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
204 for (short j = 0; j < 3; ++j)
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
205 for (short k = 0; k < 3; ++k)
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
206 val[ (i * 3) + j] += m_vals[ (i * 3) + k] * other[ (k * 3) + j];
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
207
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: 183
diff changeset
208 return val;
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: 183
diff changeset
209 }
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: 183
diff changeset
210
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: 183
diff changeset
211 // =============================================================================
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
212 matrix& matrix::operator= (matrix other) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
213 memcpy (&m_vals[0], &other.m_vals[0], sizeof (double) * 9);
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
214 return *this;
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
215 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
216
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
217 // =============================================================================
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
218 double matrix::determinant() const {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
219 return (val (0) * val (4) * val (8)) +
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
220 (val (1) * val (5) * val (6)) +
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
221 (val (2) * val (3) * val (7)) -
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
222 (val (2) * val (4) * val (6)) -
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
223 (val (1) * val (3) * val (8)) -
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
224 (val (0) * val (5) * val (7));
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: 183
diff changeset
225 }
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: 183
diff changeset
226
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: 183
diff changeset
227 // =============================================================================
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
228 StringFormatArg::StringFormatArg (const str& v) {
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
229 m_val = v;
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
230 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
231
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
232 StringFormatArg::StringFormatArg (const char& v) {
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
233 m_val = v;
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
234 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
235
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
236 StringFormatArg::StringFormatArg (const uchar& v) {
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
237 m_val = v;
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
238 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
239
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
240 StringFormatArg::StringFormatArg (const qchar& v) {
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
241 m_val = v;
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
242 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
243
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
244 StringFormatArg::StringFormatArg (const float& v) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
245 m_val = ftoa (v);
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
246 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
247
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
248 StringFormatArg::StringFormatArg (const double& v) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
249 m_val = ftoa (v);
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
250 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
251
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
252 StringFormatArg::StringFormatArg (const vertex& v) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
253 m_val = v.stringRep (false);
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
254 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
255
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
256 StringFormatArg::StringFormatArg (const matrix& v) {
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
257 m_val = v.stringRep();
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
258 }
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
259
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
260 StringFormatArg::StringFormatArg (const char* v) {
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
261 m_val = v;
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
262 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
263
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
264 StringFormatArg::StringFormatArg (const strconfig& v) {
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
265 m_val = v.value;
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
266 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
267
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
268 StringFormatArg::StringFormatArg (const intconfig& v) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
269 m_val.number (v.value);
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
270 }
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
271
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
272 StringFormatArg::StringFormatArg (const floatconfig& v) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
273 m_val.number (v.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
274 }
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
275
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
276 StringFormatArg::StringFormatArg (const void* v) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
277 m_val.sprintf ("%p", v);
322
5e701c3c3d8e Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
278 }
5e701c3c3d8e Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 310
diff changeset
279
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
280 // =============================================================================
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
281 File::File() {
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
282 // Make a null file
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
283 m_file = null;
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
284 m_textstream = null;
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
285 }
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
286
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
287 File::File (str path, OpenType rtype) {
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
288 m_file = null;
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
289 open (path, rtype);
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
290 }
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
291
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
292 File::File (FILE* fp, OpenType rtype) {
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
293 m_file = null;
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
294 open (fp, rtype);
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
295 }
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
296
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
297 File::~File() {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
298 if (m_file) {
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
299 m_file->close();
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
300 delete m_file;
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
301
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
302 if (m_textstream)
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
303 delete m_textstream;
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
304 }
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
305 }
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
306
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
307 bool File::open (FILE* fp, OpenType rtype) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
308 return open ("", rtype, fp);
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
309 }
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
310
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
311 bool File::open (str path, OpenType rtype, FILE* fp) {
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
312 close();
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
313
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
314 if (!m_file)
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
315 m_file = new 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
316
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
317 m_file->setFileName (path);
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
318
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
319 bool result;
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
320
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
321 QIODevice::OpenMode mode =
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
322 (rtype == Read) ? QIODevice::ReadOnly :
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
323 (rtype == Write) ? QIODevice::WriteOnly : QIODevice::Append;
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
324
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
325 if (fp)
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
326 result = m_file->open (fp, mode);
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
327 else
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
328 result = m_file->open (mode);
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
329
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
330 if (result) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
331 m_textstream = new QTextStream (m_file);
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
332 return true;
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
333 }
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
334
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
335 delete m_file;
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
336 m_file = null;
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
337 return false;
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
338 }
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
339
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
340 File::iterator File::begin() {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
341 return iterator (this);
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
342 }
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
343
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
344 File::iterator& File::end() {
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
345 return m_endIterator;
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
346 }
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
347
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
348 void File::write (str msg) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
349 m_file->write (msg.toUtf8(), msg.length());
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
350 }
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
351
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
352 bool File::readLine (str& line) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
353 if (!m_textstream || m_textstream->atEnd())
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
354 return false;
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
355
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
356 line = m_textstream->readLine();
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
357 return true;
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
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
360 bool File::atEnd() const {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
361 if (!m_textstream)
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
362 fatal ("cannot use atEnd on a null file");
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
363
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
364 return m_textstream->atEnd();
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
365 }
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
366
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
367 bool File::isNull() const {
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
368 return m_file == null;
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
369 }
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
370
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
371 bool File::operator!() const {
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
372 return isNull();
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
373 }
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
374
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
375 void File::close() {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
376 if (!m_file)
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
377 return;
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
378
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
379 delete m_file;
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
380 m_file = null;
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
381
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
382 if (m_textstream) {
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
383 delete m_textstream;
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
384 m_textstream = null;
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
385 }
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
386 }
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
387
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
388 bool File::flush() {
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
389 return m_file->flush();
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
390 }
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
391
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
392 File::operator bool() const {
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
393 return !isNull();
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
394 }
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
395
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
396 void File::rewind() {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
397 m_file->seek (0);
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
398 }
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
399
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
400 File::iterator::iterator (File* f) : m_file (f) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
401 operator++();
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
402 }
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
403
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
404 void File::iterator::operator++() {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
405 m_gotdata = m_file->readLine (m_text);
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
406 }
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
407
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
408 str File::iterator::operator*() {
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
409 return m_text;
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
410 }
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
411
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 287
diff changeset
412 // The prime contestant for the weirdest operator== 2013 award?
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
413 bool File::iterator::operator== (File::iterator& other) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
414 return (other.m_file == null && !m_gotdata);
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
415 }
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
416
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
417 bool File::iterator::operator!= (File::iterator& other) {
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 409
diff changeset
418 return !operator== (other);
358
7885fa5b09c5 restyle..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 322
diff changeset
419 }
380
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
420
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
421 // =============================================================================
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
422 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
423 // =============================================================================
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
424 LDBoundingBox::LDBoundingBox() {
380
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
425 reset();
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
426 }
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
427
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
428 // =============================================================================
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
429 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
430 // =============================================================================
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
431 void LDBoundingBox::calculate() {
380
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
432 reset();
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
433
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
434 if (!LDFile::current())
380
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
435 return;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
436
409
8da2563c645a Renamed LDOpenFile to LDFile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 402
diff changeset
437 for (LDObject* obj : LDFile::current()->objs())
380
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
438 calcObject (obj);
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
439 }
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
440
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
441 // =============================================================================
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
442 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
443 // =============================================================================
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
444 void LDBoundingBox::calcObject (LDObject* obj) {
380
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
445 switch (obj->getType()) {
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
446 case LDObject::Line:
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
447 case LDObject::Triangle:
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
448 case LDObject::Quad:
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
449 case LDObject::CondLine:
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
450 for (short i = 0; i < obj->vertices(); ++i)
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
451 calcVertex (obj->getVertex (i));
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
452
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
453 break;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
454
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
455 case LDObject::Subfile: {
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
456 LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj);
402
ec95fc95e5f3 Renamed vector to List, changed it to wrap around std::deque.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 388
diff changeset
457 List<LDObject*> objs = ref->inlineContents (true, true);
380
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
458
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
459 for (LDObject* obj : objs) {
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
460 calcObject (obj);
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
461 delete obj;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
462 }
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
463 }
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
464 break;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
465
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
466 default:
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
467 break;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
468 }
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
469 }
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
470
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
471 LDBoundingBox& LDBoundingBox::operator<< (const vertex& v) {
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
472 calcVertex (v);
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
473 return *this;
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
474 }
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
475
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
476 LDBoundingBox& LDBoundingBox::operator<< (LDObject* obj) {
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
477 calcObject (obj);
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
478 return *this;
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
479 }
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
480
380
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
481 // =============================================================================
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
482 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
483 // =============================================================================
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
484 void LDBoundingBox::calcVertex (const vertex& v) {
380
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
485 for (const Axis ax : g_Axes) {
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
486 if (v[ax] < m_v0[ax])
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
487 m_v0[ax] = v[ax];
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
488
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
489 if (v[ax] > m_v1[ax])
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
490 m_v1[ax] = v[ax];
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
491 }
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
492
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
493 m_empty = false;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
494 }
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
495
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
496 // =============================================================================
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
497 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
498 // =============================================================================
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
499 void LDBoundingBox::reset() {
380
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
500 m_v0[X] = m_v0[Y] = m_v0[Z] = 0x7FFFFFFF;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
501 m_v1[X] = m_v1[Y] = m_v1[Z] = 0xFFFFFFFF;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
502
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
503 m_empty = true;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
504 }
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
505
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
506 // =============================================================================
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
507 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
508 // =============================================================================
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
509 double LDBoundingBox::size() const {
380
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
510 double xscale = (m_v0[X] - m_v1[X]);
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
511 double yscale = (m_v0[Y] - m_v1[Y]);
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
512 double zscale = (m_v0[Z] - m_v1[Z]);
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
513 double size = zscale;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
514
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
515 if (xscale > yscale) {
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
516 if (xscale > zscale)
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
517 size = xscale;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
518 } elif (yscale > zscale)
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
519 size = yscale;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
520
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
521 if (abs (size) >= 2.0f)
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
522 return abs (size / 2);
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
523
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
524 return 1.0f;
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
525 }
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
526
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
527 // =============================================================================
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 380
diff changeset
528 vertex LDBoundingBox::center() const {
380
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
529 return vertex (
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
530 (m_v0[X] + m_v1[X]) / 2,
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
531 (m_v0[Y] + m_v1[Y]) / 2,
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
532 (m_v0[Z] + m_v1[Z]) / 2);
e442d9b7c251 Moved the bbox class to types
Santeri Piippo <crimsondusk64@gmail.com>
parents: 358
diff changeset
533 }

mercurial