src/types/vertex.cpp

Sat, 24 Mar 2018 13:53:56 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 24 Mar 2018 13:53:56 +0200
changeset 1333
ebcb0335d467
parent 1326
69a90bd2dba2
child 1370
c6d5ba08c62c
permissions
-rw-r--r--

removed unused include

1315
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 /*
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1322
diff changeset
3 * Copyright(C) 2013 - 2018 Teemu Piippo
1315
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 *
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 * (at your option) any later version.
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 *
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 * GNU General Public License for more details.
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 *
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 */
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #include "vertex.h"
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 #include "../format.h"
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 void Vertex::transform(const Matrix& matrix, const Vertex& pos)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 double x2 = (matrix(0, 0) * x) + (matrix(0, 1) * y) + (matrix(0, 2) * z) + pos.x;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 double y2 = (matrix(1, 0) * x) + (matrix(1, 1) * y) + (matrix(1, 2) * z) + pos.y;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 double z2 = (matrix(2, 0) * x) + (matrix(2, 1) * y) + (matrix(2, 2) * z) + pos.z;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 this->x = x2;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 this->y = y2;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 this->z = z2;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 void Vertex::apply(ApplyFunction func)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 func(X, this->x);
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 func(Y, this->y);
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 func(Z, this->z);
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 void Vertex::apply(ApplyConstFunction func) const
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 func(X, this->x);
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 func(Y, this->y);
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 func(Z, this->z);
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 double& Vertex::operator[](Axis axis)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 switch (axis)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 case X:
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 return this->x;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 case Y:
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 return this->y;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 case Z:
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 return this->z;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 default:
1322
d8935cdb24c0 renamed sink() to singleton()
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
60 return ::singleton<double>();
1315
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 double Vertex::operator[](Axis axis) const
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 switch (axis)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 case X:
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69 return this->x;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71 case Y:
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 return this->y;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 case Z:
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 return this->z;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77 default:
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78 return 0.0;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
81
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 void Vertex::setCoordinate(Axis axis, qreal value)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
84 (*this)[axis] = value;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
85 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
86
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
87 QString Vertex::toString(bool mangled) const
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 if (mangled)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 return ::format("(%1, %2, %3)", this->x, this->y, this->z);
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
91 else
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
92 return ::format("%1 %2 %3", this->x, this->y, this->z);
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
94
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
95 Vertex Vertex::operator*(qreal scalar) const
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
96 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
97 return {this->x * scalar, this->y * scalar, this->z * scalar};
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
99
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 Vertex& Vertex::operator+= (const QVector3D& other)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 this->x += other.x();
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
103 this->y += other.y();
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 this->z += other.z();
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
105 return *this;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
106 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
107
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
108 Vertex Vertex::operator+ (const QVector3D& other) const
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
109 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
110 Vertex result(*this);
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
111 result += other;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
112 return result;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
113 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
114
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
115 QVector3D Vertex::toVector() const
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
116 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
117 return {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
118 static_cast<float>(this->x),
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
119 static_cast<float>(this->y),
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
120 static_cast<float>(this->z)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
121 };
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
122 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
123
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
124 Vertex Vertex::operator-(const QVector3D& vector) const
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
125 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
126 Vertex result = *this;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
127 result -= vector;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
128 return result;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
129 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
130
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
131 Vertex& Vertex::operator-= (const QVector3D& vector)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
132 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
133 this->x -= vector.x();
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
134 this->y -= vector.y();
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
135 this->z -= vector.z();
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
136 return *this;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
137 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
138
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
139 QVector3D Vertex::operator-(const Vertex& other) const
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
140 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
141 return {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
142 static_cast<float>(this->x - other.x),
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
143 static_cast<float>(this->y - other.y),
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
144 static_cast<float>(this->z - other.z)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
145 };
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
146 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
147
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
148 Vertex& Vertex::operator*= (qreal scalar)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
149 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
150 x *= scalar;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
151 y *= scalar;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
152 z *= scalar;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
153 return *this;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
154 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
155
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
156 bool Vertex::operator== (const Vertex& other) const
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
157 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
158 return this->x == other.x and this->y == other.y and this->z == other.z;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
159 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
160
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
161 bool Vertex::operator!= (const Vertex& other) const
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
162 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
163 return not(*this == other);
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
164 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
165
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
166 bool Vertex::operator<(const Vertex& other) const
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
167 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
168 if (not qFuzzyCompare(this->x, other.x))
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
169 return this->x < other.x;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
170 else if (not qFuzzyCompare(this->y, other.y))
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
171 return this->y < other.y;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
172 else
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
173 return this->z < other.z;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
174 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
175
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
176 /*
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
177 * Transforms this vertex with a tranformation matrix and returns the result.
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
178 */
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
179 Vertex Vertex::transformed(const GLRotationMatrix& matrix) const
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
180 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
181 return {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
182 matrix(0, 0) * this->x
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
183 + matrix(0, 1) * this->y
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
184 + matrix(0, 2) * this->z,
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
185 matrix(1, 0) * this->x
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
186 + matrix(1, 1) * this->y
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
187 + matrix(1, 2) * this->z,
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
188 matrix(2, 0) * this->x
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
189 + matrix(2, 1) * this->y
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
190 + matrix(2, 2) * this->z,
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
191 };
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
192 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
193
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
194 QDataStream& operator<<(QDataStream& out, const Vertex& vertex)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
195 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
196 return out << vertex.x << vertex.y << vertex.z;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
197 }
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
198
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
199 QDataStream& operator>>(QDataStream& in, Vertex& vertex)
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
200 {
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
201 return in >> vertex.x >> vertex.y >> vertex.z;
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
202 }
1319
39d7a9642eea reorganized headers
Teemu Piippo <teemu@hecknology.net>
parents: 1315
diff changeset
203
39d7a9642eea reorganized headers
Teemu Piippo <teemu@hecknology.net>
parents: 1315
diff changeset
204 unsigned int qHash(const Vertex& key)
39d7a9642eea reorganized headers
Teemu Piippo <teemu@hecknology.net>
parents: 1315
diff changeset
205 {
39d7a9642eea reorganized headers
Teemu Piippo <teemu@hecknology.net>
parents: 1315
diff changeset
206 return qHash(key.x) ^ rotl10(qHash(key.y)) ^ rotl20(qHash(key.z));
39d7a9642eea reorganized headers
Teemu Piippo <teemu@hecknology.net>
parents: 1315
diff changeset
207 }

mercurial