Thu, 13 Feb 2020 15:25:01 +0200
made the grid look nicer
| 3 | 1 | /* |
| 2 | * LDForge: LDraw parts authoring CAD | |
| 24 | 3 | * Copyright (C) 2013 - 2020 Teemu Piippo |
| 3 | 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 | |
|
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
20 | #include <algorithm> |
| 3 | 21 | #include <cstdio> |
| 22 | #include <cstdlib> | |
|
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
23 | #include <cstring> |
| 3 | 24 | #include <cmath> |
| 53 | 25 | #include <optional> |
| 3 | 26 | #include <QMatrix4x4> |
| 27 | #include <QObject> | |
| 28 | #include <QPointF> | |
| 29 | #include <QSet> | |
| 30 | #include <QString> | |
| 31 | #include <QStringList> | |
| 32 | #include <QVariant> | |
| 33 | #include <QVector> | |
| 34 | #include <QVector3D> | |
|
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
35 | #include <glm/glm.hpp> |
| 3 | 36 | |
| 37 | using GLRotationMatrix = QMatrix4x4; | |
| 38 | ||
| 39 | enum Axis | |
| 40 | { | |
| 21 | 41 | X = 0, |
| 42 | Y = 1, | |
| 43 | Z = 2 | |
| 3 | 44 | }; |
| 45 | ||
| 26 | 46 | enum Result |
| 47 | { | |
| 48 | Success = 0, | |
| 49 | PartialSuccess, | |
| 50 | Failure | |
| 51 | }; | |
| 52 | ||
| 53 | constexpr bool failed(Result r) | |
| 54 | { | |
| 55 | return r == Failure; | |
| 56 | } | |
| 57 | ||
| 3 | 58 | enum Winding |
| 59 | { | |
| 60 | NoWinding, | |
|
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
7
diff
changeset
|
61 | Anticlockwise, |
| 3 | 62 | Clockwise, |
| 63 | }; | |
| 64 | ||
| 65 | /* | |
| 66 | * Special operator definition that implements the XOR operator for windings. | |
| 67 | * However, if either winding is NoWinding, then this function returns NoWinding. | |
| 68 | */ | |
| 69 | inline Winding operator^(Winding one, Winding other) | |
| 70 | { | |
| 71 | if (one == NoWinding or other == NoWinding) | |
| 72 | return NoWinding; | |
| 73 | else | |
| 74 | return static_cast<Winding>(static_cast<int>(one) ^ static_cast<int>(other)); | |
| 75 | } | |
| 76 | ||
| 77 | inline Winding& operator^=(Winding& one, Winding other) | |
| 78 | { | |
| 79 | one = one ^ other; | |
| 80 | return one; | |
| 81 | } | |
| 21 | 82 | |
| 83 | template<typename T, int N> | |
| 84 | constexpr int countof(T(&)[N]) | |
| 85 | { | |
| 86 | return N; | |
| 87 | } | |
|
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
88 | |
| 51 | 89 | /** |
| 90 | * @brief casts @c x to a suitable unsigned integer | |
| 91 | */ | |
| 92 | template<typename T> | |
| 93 | constexpr auto unsigned_cast(T x) | |
| 94 | -> std::enable_if_t<std::is_integral_v<T>, std::make_unsigned_t<T>> | |
| 95 | { | |
| 96 | return static_cast<std::make_unsigned_t<T>>(x); | |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * @brief casts @c x to a suitable signed integer | |
| 101 | */ | |
| 102 | template<typename T> | |
| 103 | constexpr auto signed_cast(T x) | |
| 104 | -> std::enable_if_t<std::is_integral_v<T>, std::make_signed_t<T>> | |
| 105 | { | |
| 106 | return static_cast<std::make_signed_t<T>>(x); | |
| 107 | } | |
| 108 | ||
| 53 | 109 | |
| 110 | /** | |
| 111 | * @brief casts double and long double - and only those types - to float | |
| 112 | * @param[in] x double or long double to cast | |
| 113 | * @returns float | |
| 114 | */ | |
| 115 | template<typename T> | |
| 116 | auto doubleToFloat(T x) | |
| 117 | -> std::enable_if_t< | |
| 118 | std::is_same_v<std::decay_t<T>, double> || | |
| 119 | std::is_same_v<std::decay_t<T>, long double | |
| 120 | >, float> | |
| 121 | { | |
| 122 | return static_cast<float>(x); | |
| 123 | } | |
| 124 | ||
| 125 | /** | |
| 126 | * @brief Casts float - and only float - to double | |
| 127 | * @param[in] x float to cast | |
| 128 | * @returns double | |
| 129 | */ | |
| 130 | template<typename T> | |
| 131 | auto floatToDouble(T x) | |
| 132 | -> std::enable_if_t<std::is_same_v<std::decay_t<T>, float>, double> | |
| 133 | { | |
| 134 | return static_cast<double>(x); | |
| 135 | } | |
|
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
136 | Q_DECLARE_METATYPE(glm::vec3) |
|
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
137 | Q_DECLARE_METATYPE(glm::mat4) |