Pārlūkot izejas kodu

math: some new operators for generic vectors, plus unit tests.

undefined
Sam Hocevar pirms 10 gadiem
vecāks
revīzija
079ee8dcbf
2 mainītis faili ar 36 papildinājumiem un 0 dzēšanām
  1. +24
    -0
      src/lol/math/vector.h
  2. +12
    -0
      test/unit/vector.cpp

+ 24
- 0
src/lol/math/vector.h Parādīt failu

@@ -111,6 +111,30 @@ struct vec_t<T, N, FULL_SWIZZLE>
typedef T element;
typedef vec_t<T,N> type;

/* Default constructor, copy constructor, and destructor */
inline constexpr vec_t() {}
inline vec_t(vec_t<T,N> const &v)
{
for (int i = 0; i < N; ++i)
m_data[i] = v.m_data[i];
}
inline ~vec_t() {}

/* Explicit constructor for type conversion */
template<typename U>
explicit inline vec_t(vec_t<U, N> const &v)
{
for (int i = 0; i < N; ++i)
m_data[i] = (T)v.m_data[i];
}

/* Various explicit constructors */
explicit inline vec_t(T X)
{
for (int i = 0; i < N; ++i)
m_data[i] = X;
}

inline T& operator[](size_t n) { return m_data[n]; }
inline T const& operator[](size_t n) const { return m_data[n]; }



+ 12
- 0
test/unit/vector.cpp Parādīt failu

@@ -225,6 +225,18 @@ LOLUNIT_FIXTURE(VectorTest)
LOLUNIT_ASSERT_DOUBLES_EQUAL(length(orthonormal(b)), 1.f, 1e-6f);
LOLUNIT_ASSERT_DOUBLES_EQUAL(length(orthonormal(c)), 1.f, 1e-6f);
}

LOLUNIT_TEST(LargeVectors)
{
vec_t<int, 50> v0(0);
vec_t<int, 50> v1(1);
vec_t<int, 50> v2(2);
vec_t<int, 50> v3(3);

auto va = v0 + v3;
auto vb = v1 + v2;
LOLUNIT_ASSERT(va == vb);
}
};

} /* namespace lol */


Notiek ielāde…
Atcelt
Saglabāt