-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathp3a_diagonal3x3.hpp
73 lines (65 loc) · 1.67 KB
/
p3a_diagonal3x3.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include "p3a_macros.hpp"
#include "p3a_scaled_identity3x3.hpp"
namespace p3a {
template <class T>
class diagonal3x3 {
T m_xx;
T m_yy;
T m_zz;
public:
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
diagonal3x3(
T const& a,
T const& b,
T const& c)
:m_xx(a)
,m_yy(b)
,m_zz(c)
{}
P3A_ALWAYS_INLINE inline
diagonal3x3() = default;
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& xx() const { return m_xx; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& xx() { return m_xx; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& yy() const { return m_yy; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& yy() { return m_yy; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& zz() const { return m_zz; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& zz() { return m_zz; }
};
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
auto trace(diagonal3x3<T> const& d)
{
return d.xx() + d.yy() + d.zz();
}
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
auto determinant(diagonal3x3<T> const& d)
{
return d.xx() * d.yy() * d.zz();
}
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
diagonal3x3<T> operator-(
diagonal3x3<T> const& a,
scaled_identity3x3<T> const& b)
{
return diagonal3x3<T>(
a.xx() - b.scale(),
a.yy() - b.scale(),
a.zz() - b.scale());
}
template <class T, class U>
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline
diagonal3x3<T>& operator-=(diagonal3x3<T>& a, U const& b)
{
a = a - b;
return a;
}
}