src/basics.cpp

Sat, 28 Jan 2017 17:14:05 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 28 Jan 2017 17:14:05 +0200
changeset 1068
283de3bd8b0e
parent 1053
2a48c0fff107
child 1072
9ce9496427f2
permissions
-rw-r--r--

Reworked the Matrix interface so that less index math is involved

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1014
f0a8ecb6a357 Happy new year 2016!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1013
diff changeset
3 * Copyright (C) 2013 - 2016 Teemu Piippo
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QObject>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QStringList>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <QTextStream>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QFile>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <assert.h>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "main.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "basics.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "miscallenous.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "ldObject.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "ldDocument.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
30 Vertex::Vertex() :
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
31 QVector3D() {}
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
32
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
33 Vertex::Vertex (const QVector3D& a) :
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
34 QVector3D (a) {}
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
36 Vertex::Vertex (qreal xpos, qreal ypos, qreal zpos) :
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
37 QVector3D(xpos, ypos, zpos) {}
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
38
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
39
1068
283de3bd8b0e Reworked the Matrix interface so that less index math is involved
Teemu Piippo <teemu@hecknology.net>
parents: 1053
diff changeset
40 void Vertex::transform (const Matrix& matrix, const Vertex& pos)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 {
1068
283de3bd8b0e Reworked the Matrix interface so that less index math is involved
Teemu Piippo <teemu@hecknology.net>
parents: 1053
diff changeset
42 double x2 = (matrix(0, 0) * x()) + (matrix(0, 1) * y()) + (matrix(0, 2) * z()) + pos.x();
283de3bd8b0e Reworked the Matrix interface so that less index math is involved
Teemu Piippo <teemu@hecknology.net>
parents: 1053
diff changeset
43 double y2 = (matrix(1, 0) * x()) + (matrix(1, 1) * y()) + (matrix(1, 2) * z()) + pos.y();
283de3bd8b0e Reworked the Matrix interface so that less index math is involved
Teemu Piippo <teemu@hecknology.net>
parents: 1053
diff changeset
44 double z2 = (matrix(2, 0) * x()) + (matrix(2, 1) * y()) + (matrix(2, 2) * z()) + pos.z();
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
45 setX (x2);
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
46 setY (y2);
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
47 setZ (z2);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
50 void Vertex::apply (ApplyFunction func)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 {
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
52 double newX = x(), newY = y(), newZ = z();
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
53 func (X, newX);
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
54 func (Y, newY);
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
55 func (Z, newZ);
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
56 *this = Vertex (newX, newY, newZ);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
59 void Vertex::apply (ApplyConstFunction func) const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 {
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
61 func (X, x());
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
62 func (Y, y());
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
63 func (Z, z());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
66 double Vertex::operator[] (Axis ax) const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 {
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
68 switch (ax)
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
69 {
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
70 case X: return x();
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
71 case Y: return y();
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
72 case Z: return z();
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
73 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
75 return 0.0;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
78 void Vertex::setCoordinate (Axis ax, qreal value)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 {
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
80 switch (ax)
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
81 {
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
82 case X: setX (value); break;
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
83 case Y: setY (value); break;
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
84 case Z: setZ (value); break;
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
85 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
88 QString Vertex::toString (bool mangled) const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 {
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
90 if (mangled)
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
91 return format ("(%1, %2, %3)", x(), y(), z());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
93 return format ("%1 %2 %3", x(), y(), z());
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
94 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
1002
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
96 Vertex Vertex::operator* (qreal scalar) const
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
97 {
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
98 return Vertex (x() * scalar, y() * scalar, z() * scalar);
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
99 }
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
100
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
101 Vertex& Vertex::operator+= (const Vertex& other)
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
102 {
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
103 setX (x() + other.x());
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
104 setY (y() + other.y());
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
105 setZ (z() + other.z());
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
106 return *this;
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
107 }
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
108
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
109 Vertex Vertex::operator+ (const Vertex& other) const
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
110 {
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
111 Vertex result (*this);
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
112 result += other;
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
113 return result;
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
114 }
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
115
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
116 Vertex& Vertex::operator*= (qreal scalar)
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
117 {
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
118 setX (x() * scalar);
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
119 setY (y() * scalar);
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
120 setZ (z() * scalar);
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
121 return *this;
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
122 }
a3ee23db8393 Bézier curves may now be serialized down using the "Demote" function. I need to rename that now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
123
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
124 bool Vertex::operator< (const Vertex& other) const
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
125 {
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
126 if (x() != other.x()) return x() < other.x();
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
127 if (y() != other.y()) return y() < other.y();
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
128 if (z() != other.z()) return z() < other.z();
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
129 return false;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 //
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
134 BoundingBox::BoundingBox()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 reset();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 //
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
141 void BoundingBox::calcObject (LDObject* obj)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 switch (obj->type())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 {
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
145 case OBJ_Line:
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
146 case OBJ_Triangle:
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
147 case OBJ_Quad:
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
148 case OBJ_CondLine:
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
149 for (int i = 0; i < obj->numVertices(); ++i)
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
150 calcVertex (obj->vertex (i));
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
151 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1010
diff changeset
153 case OBJ_SubfileReference:
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1010
diff changeset
154 for (LDObject* it : static_cast<LDSubfileReference*> (obj)->inlineContents (true, false))
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
155 {
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
156 calcObject (it);
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
157 it->destroy();
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
158 }
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
159 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
161 default:
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
162 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 //
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
168 BoundingBox& BoundingBox::operator<< (const Vertex& v)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 calcVertex (v);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 return *this;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 //
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
176 BoundingBox& BoundingBox::operator<< (LDObject* obj)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 calcObject (obj);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 return *this;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 //
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
184 void BoundingBox::calcVertex (const Vertex& vertex)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 {
966
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 958
diff changeset
186 m_vertex0.setX (qMin (vertex.x(), m_vertex0.x()));
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 958
diff changeset
187 m_vertex0.setY (qMin (vertex.y(), m_vertex0.y()));
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 958
diff changeset
188 m_vertex0.setZ (qMin (vertex.z(), m_vertex0.z()));
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 958
diff changeset
189 m_vertex1.setX (qMax (vertex.x(), m_vertex1.x()));
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 958
diff changeset
190 m_vertex1.setY (qMax (vertex.y(), m_vertex1.y()));
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 958
diff changeset
191 m_vertex1.setZ (qMax (vertex.z(), m_vertex1.z()));
1010
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
192 m_isEmpty = false;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 //
1010
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
197 // Clears the bounding box
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
198 //
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
199 void BoundingBox::reset()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 {
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
201 m_vertex0 = Vertex (10000.0, 10000.0, 10000.0);
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
202 m_vertex1 = Vertex (-10000.0, -10000.0, -10000.0);
1010
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
203 m_isEmpty = true;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 //
1010
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
208 // Returns the length of the bounding box on the longest measure.
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
209 //
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
210 double BoundingBox::longestMeasurement() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 {
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
212 double xscale = (m_vertex0.x() - m_vertex1.x());
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
213 double yscale = (m_vertex0.y() - m_vertex1.y());
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
214 double zscale = (m_vertex0.z() - m_vertex1.z());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 double size = zscale;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 if (xscale > yscale)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 if (xscale > zscale)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 size = xscale;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 }
967
eb586d3e1a6a elif -> else if
Teemu Piippo <crimsondusk64@gmail.com>
parents: 966
diff changeset
222 else if (yscale > zscale)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223 size = yscale;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224
966
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 958
diff changeset
225 if (qAbs (size) >= 2.0)
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 958
diff changeset
226 return qAbs (size / 2);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
228 return 1.0;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 //
1010
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
233 // Yields the center of the bounding box.
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
234 //
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
235 Vertex BoundingBox::center() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 return Vertex (
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
238 (m_vertex0.x() + m_vertex1.x()) / 2,
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
239 (m_vertex0.y() + m_vertex1.y()) / 2,
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 714
diff changeset
240 (m_vertex0.z() + m_vertex1.z()) / 2);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 }
1010
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
242
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
243 bool BoundingBox::isEmpty() const
1010
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
244 {
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
245 return m_isEmpty;
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
246 }
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
247
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
248 const Vertex& BoundingBox::vertex0() const
1010
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
249 {
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
250 return m_vertex0;
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
251 }
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
252
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
253 const Vertex& BoundingBox::vertex1() const
1010
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
254 {
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1002
diff changeset
255 return m_vertex1;
1031
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
256 }
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
257
1036
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
258 // http://stackoverflow.com/a/18204188/3629665
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
259 template<typename T>
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
260 inline int rotl10(T x)
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
261 {
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
262 return (((x) << 10) | (((x) >> 22) & 0x000000ff));
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
263 }
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
264
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
265 template<typename T>
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
266 inline int rotl20(T x)
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
267 {
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
268 return (((x) << 20) | (((x) >> 12) & 0x000000ff));
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
269 }
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
270
1031
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
271 uint qHash(const Vertex& key)
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
272 {
1036
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1031
diff changeset
273 return qHash(key.x()) ^ rotl10(qHash(key.y())) ^ rotl20(qHash(key.z()));
1031
55c0d3beea0d removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
274 }
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
275
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
276 /*
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
277 * getRadialPoint
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
278 *
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
279 * Gets an ordinate of a point in circle.
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
280 * If func == sin, then this gets the Y co-ordinate, if func == cos, then X co-ordinate.
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
281 */
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
282 double getRadialPoint(int segment, int divisions, double(*func)(double))
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
283 {
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
284 return (*func)((segment * 2 * pi) / divisions);
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
285 }
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
286
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
287 /*
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
288 * makeCircle
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
289 *
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
290 * Creates a possibly partial circle rim.
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
291 * Divisions is how many segments the circle makes if up if it's full.
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
292 * Segments is now many segments are added.
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
293 * Radius is the radius of the circle.
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
294 *
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
295 * If divisions == segments, this yields a full circle rim.
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
296 * The rendered circle is returned as a vector of lines.
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
297 */
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
298 QVector<QLineF> makeCircle(int segments, int divisions, double radius)
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
299 {
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
300 QVector<QLineF> lines;
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
301
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
302 for (int i = 0; i < segments; ++i)
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
303 {
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
304 double x0 = radius * getRadialPoint(i, divisions, cos);
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
305 double x1 = radius * getRadialPoint(i + 1, divisions, cos);
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
306 double z0 = radius * getRadialPoint(i, divisions, sin);
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
307 double z1 = radius * getRadialPoint(i + 1, divisions, sin);
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
308 lines.append(QLineF {QPointF {x0, z0}, QPointF {x1, z1}});
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
309 }
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
310
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
311 return lines;
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1037
diff changeset
312 }

mercurial