void length() { using T = typename Vec::Scalar; U size = Vec::SIZE; Vec vec; T res = 0; for(U i = 0; i < size; i++) { T x = i * 666; vec[i] = x; res += x * x; } res = sqrt(res); ANKI_TEST_EXPECT_EQ(vec.getLength(), res); if(Vec::IS_INTEGER) { ANKI_TEST_EXPECT_EQ(vec.getNormalized(), vec / res); } else { auto a = vec / res; auto b = vec.getNormalized(); for(U i = 0; i < size; i++) { ANKI_TEST_EXPECT_NEAR(a[i], b[i], 0.0001); } } }
template<class Vec> void testNormalize() { Vec vec; for (unsigned int i = 0; i < vec.getDimension(); i++) vec[i] = numbers[i]; // getNormalized auto temp = vec.getNormalized(); ASSERT(dbgl::isSimilar(temp.getLength(), 1.0f)); // normalize vec.normalize(); ASSERT(dbgl::isSimilar(vec.getLength(), 1.0f)); }
template<class Vec> void testLength() { Vec vec; for (unsigned int i = 0; i < vec.getDimension(); i++) vec[i] = numbers[i]; // getSquaredLength() auto sqLen = 0.0; for (unsigned int i = 0; i < vec.getDimension(); i++) sqLen += vec[i] * vec[i]; ASSERT(dbgl::isSimilar(vec.getSquaredLength(), (float )sqLen)); // getLength() ASSERT(dbgl::isSimilar(vec.getLength(), (float )std::sqrt(sqLen))); }