-
Notifications
You must be signed in to change notification settings - Fork 4
/
p3a_scaled_identity3x3.hpp
72 lines (64 loc) · 2.22 KB
/
p3a_scaled_identity3x3.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
#pragma once
#include "p3a_scalar.hpp"
#include "p3a_macros.hpp"
#include "p3a_identity3x3.hpp"
#include "p3a_constants.hpp"
namespace p3a {
template <class T>
class scaled_identity3x3 {
T m_scale;
public:
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
scaled_identity3x3(T const& a)
:m_scale(a)
{}
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& scale() const { return m_scale; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T xx() const { return m_scale; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T xy() const { return zero_value<T>(); }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T xz() const { return zero_value<T>(); }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T yx() const { return zero_value<T>(); }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T yy() const { return m_scale; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T yz() const { return zero_value<T>(); }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T zx() const { return zero_value<T>(); }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T zy() const { return zero_value<T>(); }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T zz() const { return m_scale; }
};
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
typename std::enable_if<is_scalar<T>, scaled_identity3x3<T>>::type
operator*(T const& a, identity3x3_type) {
return scaled_identity3x3<T>(a);
}
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
typename std::enable_if<is_scalar<T>, scaled_identity3x3<T>>::type
operator*(identity3x3_type, T const& a) {
return scaled_identity3x3<T>(a);
}
template <class A, class B>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
typename std::enable_if<is_scalar<A>, scaled_identity3x3<decltype(A() * B())>>::type
operator*(
A const& a,
scaled_identity3x3<B> const& b)
{
return scaled_identity3x3<decltype(a * b.scale())>(a * b.scale());
}
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
scaled_identity3x3<T>
operator-(scaled_identity3x3<T> const& a)
{
return scaled_identity3x3<T>(-a.scale());
}
}