src/maths.h

Sun, 19 Jan 2020 02:54:48 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 19 Jan 2020 02:54:48 +0200
changeset 22
6da867fa5429
parent 20
cef43609a374
child 24
1a0faaaceb84
permissions
-rw-r--r--

commit work on GL rendering

20
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #pragma once
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include <cmath>
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 namespace math
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 {
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 using std::abs;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 using std::sqrt;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 using std::sin;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 using std::cos;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 using std::tan;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 using std::atan;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 using std::atan2;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 using std::acos;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 using std::asin;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 using std::exp;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 using std::log;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 using std::log10;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 using std::hypot;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 using std::floor;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 using std::ceil;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 using std::trunc;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 using std::round;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 template<typename T, typename... Rest>
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 inline auto hypot(T&& x, Rest&&... rest)
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 {
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 return math::hypot(x, math::hypot(rest...));
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 }
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 template<typename T, typename... Rest>
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 const T& max(const T& x, const T& y)
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 {
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 if (x > y)
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 return x;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 else
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 return y;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 }
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 template<typename T, typename... Rest>
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 const T& max(const T& x, const T& y, Rest&&... rest)
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 {
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 return math::max(x, math::max(y, rest...));
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 }
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 template<typename T, typename... Rest>
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 const T& min(const T& x, const T& y)
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 {
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 if (x < y)
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 return x;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 else
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 return y;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 }
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 template<typename T, typename... Rest>
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 const T& min(const T& x, const T& y, Rest&&... rest)
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 {
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 return math::min(x, math::min(y, rest...));
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 }
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 constexpr double infinity = std::numeric_limits<double>::infinity();
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 constexpr long double pi = M_PIl;
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 }

mercurial