|
1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2019 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 <cstdio> |
|
21 #include <cstdlib> |
|
22 #include <cmath> |
|
23 #include <QMatrix4x4> |
|
24 #include <QObject> |
|
25 #include <QPointF> |
|
26 #include <QSet> |
|
27 #include <QString> |
|
28 #include <QStringList> |
|
29 #include <QVariant> |
|
30 #include <QVector> |
|
31 #include <QVector3D> |
|
32 |
|
33 using GLRotationMatrix = QMatrix4x4; |
|
34 |
|
35 enum Axis |
|
36 { |
|
37 X, |
|
38 Y, |
|
39 Z |
|
40 }; |
|
41 |
|
42 enum Winding |
|
43 { |
|
44 NoWinding, |
|
45 CounterClockwise, |
|
46 Clockwise, |
|
47 }; |
|
48 |
|
49 /* |
|
50 * Special operator definition that implements the XOR operator for windings. |
|
51 * However, if either winding is NoWinding, then this function returns NoWinding. |
|
52 */ |
|
53 inline Winding operator^(Winding one, Winding other) |
|
54 { |
|
55 if (one == NoWinding or other == NoWinding) |
|
56 return NoWinding; |
|
57 else |
|
58 return static_cast<Winding>(static_cast<int>(one) ^ static_cast<int>(other)); |
|
59 } |
|
60 |
|
61 inline Winding& operator^=(Winding& one, Winding other) |
|
62 { |
|
63 one = one ^ other; |
|
64 return one; |
|
65 } |
|
66 |
|
67 template<typename T, std::size_t N> |
|
68 constexpr std::size_t countof(T(&)[N]) |
|
69 { |
|
70 return N; |
|
71 } |
|
72 |
|
73 static constexpr long double pi = M_PIl; |
|
74 |
|
75 // http://stackoverflow.com/a/18204188/3629665 |
|
76 template<typename T> |
|
77 inline auto rotl10(T x) |
|
78 -> std::enable_if_t<std::is_arithmetic_v<T>, T> |
|
79 { |
|
80 return (x << 10) | ((x >> 22) & 0x000000ff); |
|
81 } |
|
82 |
|
83 template<typename T> |
|
84 inline auto rotl20(T x) |
|
85 -> std::enable_if_t<std::is_arithmetic_v<T>, T> |
|
86 { |
|
87 return (x << 20) | ((x >> 12) & 0x000000ff); |
|
88 } |