Tue, 15 Mar 2022 18:56:02 +0200
Add missing svg icon
24 | 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 | ||
20 | 19 | #pragma once |
20 | #include <cmath> | |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
21 | #include "utility.h" |
20 | 22 | |
23 | namespace math | |
24 | { | |
25 | using std::abs; | |
26 | using std::sqrt; | |
27 | using std::sin; | |
28 | using std::cos; | |
29 | using std::tan; | |
30 | using std::atan; | |
31 | using std::atan2; | |
32 | using std::acos; | |
33 | using std::asin; | |
34 | using std::exp; | |
35 | using std::log; | |
36 | using std::log10; | |
37 | using std::hypot; | |
38 | using std::floor; | |
39 | using std::ceil; | |
40 | using std::trunc; | |
41 | using std::round; | |
42 | template<typename T, typename... Rest> | |
43 | inline auto hypot(T&& x, Rest&&... rest) | |
44 | { | |
45 | return math::hypot(x, math::hypot(rest...)); | |
46 | } | |
47 | template<typename T, typename... Rest> | |
48 | const T& max(const T& x, const T& y) | |
49 | { | |
50 | if (x > y) | |
51 | return x; | |
52 | else | |
53 | return y; | |
54 | } | |
55 | template<typename T, typename... Rest> | |
56 | const T& max(const T& x, const T& y, Rest&&... rest) | |
57 | { | |
58 | return math::max(x, math::max(y, rest...)); | |
59 | } | |
60 | template<typename T, typename... Rest> | |
61 | const T& min(const T& x, const T& y) | |
62 | { | |
63 | if (x < y) | |
64 | return x; | |
65 | else | |
66 | return y; | |
67 | } | |
68 | template<typename T, typename... Rest> | |
69 | const T& min(const T& x, const T& y, Rest&&... rest) | |
70 | { | |
71 | return math::min(x, math::min(y, rest...)); | |
72 | } | |
73 | constexpr double infinity = std::numeric_limits<double>::infinity(); | |
74 | constexpr long double pi = M_PIl; | |
122
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
75 | // Returns the minimum value of a container |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
76 | template<typename T> |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
77 | inline auto nmin(T&& values) |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
78 | { |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
79 | auto it = std::begin(values); |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
80 | auto result_p = it; |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
81 | for (++it; it != std::end(values); ++it) |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
82 | { |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
83 | if (*it < *result_p) |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
84 | result_p = it; |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
85 | } |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
86 | return *result_p; |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
87 | } |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
88 | // Returns the maximum value of a container |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
89 | template<typename T> |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
90 | inline auto nmax(T&& values) |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
91 | { |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
92 | auto it = std::begin(values); |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
93 | auto result_p = it; |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
94 | for (++it; it != std::end(values); ++it) |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
95 | { |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
96 | if (*it > *result_p) |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
97 | result_p = it; |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
98 | } |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
99 | return *result_p; |
b54b350dff5d
Show concave polygons as red while drawing
Teemu Piippo <teemu@hecknology.net>
parents:
120
diff
changeset
|
100 | } |
26 | 101 | /* |
102 | * Returns the empty sum. (recursion base) | |
103 | */ | |
104 | template<typename T> | |
105 | constexpr T sum() | |
106 | { | |
107 | return {}; | |
108 | } | |
109 | ||
110 | /* | |
111 | * Returns the sum of n arguments. | |
112 | */ | |
113 | template<typename T, typename... Rest> | |
114 | constexpr auto sum(const T& arg, Rest&&... rest) | |
115 | { | |
116 | return arg + sum<T>(rest...); | |
117 | } | |
55 | 118 | |
119 | std::optional<glm::vec3> linePlaneIntersection(); | |
20 | 120 | } |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
121 | |
120
8c9fff699241
rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
122 | template<typename T, glm::qualifier Q> |
8c9fff699241
rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents:
55
diff
changeset
|
123 | inline unsigned int qHash(const glm::vec<3, T, Q>& key) |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
124 | { |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
125 | return qHash(key.x) ^ utility::rotl10(qHash(key.y)) ^ utility::rotl20(qHash(key.z)); |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
126 | } |