src/vertex.h

Sat, 29 Aug 2015 16:30:56 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 29 Aug 2015 16:30:56 +0300
changeset 951
54d90af8542d
parent 941
f895379d7fab
permissions
-rw-r--r--

Closed old branch

941
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013 - 2015 Teemu Piippo
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #pragma once
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QVector3D>
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <functional>
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "basics.h"
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 class Matrix;
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 enum Axis
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 {
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 X,
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 Y,
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 Z
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 };
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 //
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 // Derivative of QVector3D: this class is used for the vertices.
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 //
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 class Vertex : public QVector3D
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 {
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 public:
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 using ApplyFunction = std::function<void (Axis, double&)>;
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 using ApplyConstFunction = std::function<void (Axis, double)>;
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 Vertex();
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 Vertex (const QVector3D& a);
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 Vertex (qreal xpos, qreal ypos, qreal zpos);
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 void apply (ApplyFunction func);
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 void apply (ApplyConstFunction func) const;
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 QString toString (bool mangled = false) const;
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 void transform (const Matrix& matr, const Vertex& pos);
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 void setCoordinate (Axis ax, qreal value);
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 bool operator< (const Vertex& other) const;
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 double operator[] (Axis ax) const;
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 };
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 extern const Vertex Origin;
f895379d7fab Refactoring update.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 Q_DECLARE_METATYPE (Vertex)

mercurial