summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-01-09 17:14:02 +0100
committerStanislaw Halik <sthalik@misaki.pl>2018-01-10 03:18:58 +0100
commit7d101a1c2827b5e7a373fb0d0a68099fb692e55a (patch)
tree3489a2988806a02a9ef31760116de104f94582c6 /compat
parent674c8a9f1a42b36940551a6ebaf953ad96d379d0 (diff)
many: spring cleanup
Diffstat (limited to 'compat')
-rw-r--r--compat/macros.hpp10
-rw-r--r--compat/simple-mat.hpp57
2 files changed, 35 insertions, 32 deletions
diff --git a/compat/macros.hpp b/compat/macros.hpp
index 8f807bf0..ed0bd8da 100644
--- a/compat/macros.hpp
+++ b/compat/macros.hpp
@@ -45,18 +45,24 @@
#ifdef Q_CREATOR_RUN
# define warn_result_unused
-#elif defined(_MSC_VER)
+#elif defined _MSC_VER
# define warn_result_unused _Check_return_
#else
# define warn_result_unused __attribute__((warn_unused_result))
#endif
-#if defined(__GNUG__)
+#if defined __GNUG__
# define unused(t, i) t __attribute__((unused)) i
#else
# define unused(t, i) t
#endif
+#if defined _MSC_VER
+# define aligned_struct(x) struct __declspec(align(x))
+#else
+# define aligned_struct(x) struct __attribute__((__aligned__(x)))
+#endif
+
#if defined __GNUC__
# define likely(x) __builtin_expect(!!(x),1)
# define unlikely(x) __builtin_expect(!!(x),0)
diff --git a/compat/simple-mat.hpp b/compat/simple-mat.hpp
index a806448b..c8c9f48b 100644
--- a/compat/simple-mat.hpp
+++ b/compat/simple-mat.hpp
@@ -21,11 +21,18 @@ namespace simple_mat_detail {
{
enum { value = i == j };
};
- template<int i, int j, int min>
+ template<int i, int j, int min, int max>
struct maybe_add_swizzle
{
- enum { value = (i == 1 || j == 1) && (i >= min || j >= min) };
+ enum { value = (i == 1 || j == 1) && (i >= min || j >= min) && (i <= max || j <= max) };
};
+
+ template<int j, int i>
+ struct is_vector
+ {
+ enum { value = j == 1 || i == 1 };
+ };
+
template<int i1, int j1, int i2, int j2>
struct is_vector_pair
{
@@ -58,18 +65,6 @@ class Mat
public:
template<int Q = w_> std::enable_if_t<equals<Q, 1, 0>::value, num>
- constexpr inline operator()(int i) const& { return data[i][0]; }
-
- template<int P = h_> std::enable_if_t<equals<P, 1, 1>::value, num>
- constexpr inline operator()(int i) const& { return data[0][i]; }
-
- template<int Q = w_> std::enable_if_t<equals<Q, 1, 2>::value, num&>
- constexpr inline operator()(int i) & { return data[i][0]; }
-
- template<int P = h_> std::enable_if_t<equals<P, 1, 3>::value, num&>
- constexpr inline operator()(int i) & { return data[0][i]; }
-
- template<int Q = w_> std::enable_if_t<equals<Q, 1, 0>::value, num>
constexpr inline operator()(unsigned i) const& { return data[i][0]; }
template<int P = h_> std::enable_if_t<equals<P, 1, 1>::value, num>
@@ -83,35 +78,37 @@ public:
#define OPENTRACK_ASSERT_SWIZZLE static_assert(P == h_ && Q == w_, "")
- template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 1>::value, num>
+ // const variants
+ template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 1, 4>::value, num>
constexpr inline x() const& { OPENTRACK_ASSERT_SWIZZLE; return operator()(0); }
- template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 2>::value, num>
+ template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 2, 4>::value, num>
constexpr inline y() const& { OPENTRACK_ASSERT_SWIZZLE; return operator()(1); }
- template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 3>::value, num>
+ template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 3, 4>::value, num>
constexpr inline z() const& { OPENTRACK_ASSERT_SWIZZLE; return operator()(2); }
- template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 4>::value, num>
+ template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 4, 4>::value, num>
constexpr inline w() const& { OPENTRACK_ASSERT_SWIZZLE; return operator()(3); }
- template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 1>::value, num&>
+ // mutable variants
+ template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 1, 4>::value, num&>
constexpr inline x() & { OPENTRACK_ASSERT_SWIZZLE; return operator()(0); }
- template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 2>::value, num&>
+ template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 2, 4>::value, num&>
constexpr inline y() & { OPENTRACK_ASSERT_SWIZZLE; return operator()(1); }
- template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 3>::value, num&>
+ template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 3, 4>::value, num&>
constexpr inline z() & { OPENTRACK_ASSERT_SWIZZLE; return operator()(2); }
- template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 4>::value, num&>
+ template<int P = h_, int Q = w_> std::enable_if_t<maybe_add_swizzle<P, Q, 4, 4>::value, num&>
constexpr inline w() & { OPENTRACK_ASSERT_SWIZZLE; return operator()(3); }
// parameters w_ and h_ are rebound so that SFINAE occurs
// removing them causes a compile-time error -sh 20150811
- template<int R, int S, int P = h_, int Q = w_>
- std::enable_if_t<is_vector_pair<R, S, P, Q>::value, num>
+ template<int P = h_, int Q = w_>
+ std::enable_if_t<is_vector<P, Q>::value, num>
norm() const
{
static_assert(P == h_ && Q == w_, "");
@@ -167,7 +164,7 @@ public:
return ret;
}
- constexpr Mat<num, h_, w_> operator+(const num& other) const
+ constexpr Mat<num, h_, w_> operator+(const num other) const
{
Mat<num, h_, w_> ret;
for (int j = 0; j < h_; j++)
@@ -176,7 +173,7 @@ public:
return ret;
}
- constexpr Mat<num, h_, w_> operator-(const num& other) const
+ constexpr Mat<num, h_, w_> operator-(const num other) const
{
Mat<num, h_, w_> ret;
for (int j = 0; j < h_; j++)
@@ -210,11 +207,11 @@ public:
return ret;
}
- constexpr inline num operator()(int j, int i) const& { return data[j][i]; }
- constexpr inline num& operator()(int j, int i) & { return data[j][i]; }
+ template<typename t, typename u>
+ constexpr inline num operator()(t j, u i) const& { return data[(int) j][(int) i]; }
- constexpr inline num operator()(unsigned j, unsigned i) const& { return data[j][i]; }
- constexpr inline num& operator()(unsigned j, unsigned i) & { return data[j][i]; }
+ template<typename t, typename u>
+ constexpr inline num& operator()(t j, u i) & { return data[(int) j][(int) i]; }
#ifdef __GNUG__
# pragma GCC diagnostic push