1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013 - 2020 Teemu Piippo |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #pragma once |
|
20 #include <functional> |
|
21 #include <QVector3D> |
|
22 #include "basics.h" |
|
23 #include "maths.h" |
|
24 #include "matrix.h" |
|
25 |
|
26 struct Point3D |
|
27 { |
|
28 double x, y, z; |
|
29 using CoordinateType = decltype(x); |
|
30 void assign(Axis axis, CoordinateType value); |
|
31 CoordinateType& get(Axis ax); |
|
32 CoordinateType get(Axis ax) const; |
|
33 operator QVariant() const; |
|
34 }; |
|
35 |
|
36 constexpr Point3D origin = {0, 0, 0}; |
|
37 |
|
38 namespace math |
|
39 { |
|
40 Point3D transform(const Point3D& point, const Matrix4x4& matrix); |
|
41 qreal distance(const Point3D& one, const Point3D& other); |
|
42 } |
|
43 |
|
44 Point3D& operator+=(Point3D &point, const QVector3D& other); |
|
45 Point3D operator+(Point3D point, const QVector3D& other); |
|
46 QVector3D operator-(const Point3D& point, const Point3D& other); |
|
47 Point3D operator-(Point3D point, const QVector3D& vector); |
|
48 Point3D& operator-=(Point3D &point, const QVector3D& vector); |
|
49 Point3D& operator*=(Point3D &point, Point3D::CoordinateType scalar); |
|
50 Point3D operator*(const Point3D &point, Point3D::CoordinateType scalar); |
|
51 bool operator<(const Point3D &point, const Point3D& other); |
|
52 bool operator==(const Point3D &point, const Point3D& other); |
|
53 bool operator!=(const Point3D &point, const Point3D& other); |
|
54 |
|
55 inline Point3D operator*(qreal scalar, const Point3D& vertex) |
|
56 { |
|
57 return vertex * scalar; |
|
58 } |
|
59 |
|
60 Q_DECLARE_METATYPE(Point3D) |
|
61 Point3D vertexFromVector(const QVector3D& vector); |
|
62 QVector3D vertexToVector(const Point3D &vertex); |
|
63 QString vertexToStringParens(const Point3D& vertex); |
|
64 unsigned int qHash(const Point3D& key); |
|
65 Point3D operator-(const Point3D& vertex); |
|
66 QDataStream& operator<<(QDataStream& out, const Point3D& vertex); |
|
67 QDataStream& operator>>(QDataStream& in, Point3D& vertex); |
|
68 |
|
69 /* |
|
70 * Calls 'function' with the x, y and z coordinates of 'vertex'. |
|
71 */ |
|
72 template<typename Function> |
|
73 inline auto xyz(Function&& function, const Point3D& vertex) |
|
74 { |
|
75 return function(vertex.x, vertex.y, vertex.z); |
|
76 } |
|