9template<std::
floating_po
int T>
12 return std::abs(x - y) < T(1.0e-5);
14template<
int N, std::
floating_po
int T>
17 return length2(x - y) < T(1.0e-4);
43 SECTION(
"default constructor") {
71 SECTION(
"broadcast constructor") {
99 SECTION(
"per-element constructor") {
127 SECTION(
"construct from smaller vectors/scalar") {
212 v4[0] = 9;
v4[2] = 8;
218 i4[0] = 9;
i4[2] = 8;
252 v[0] = 9;
CHECK(v != w);
253 w = v;
CHECK(v == w);
258 v[1] = 9;
CHECK(v != w);
259 w = v;
CHECK(v == w);
264 v[2] = 8;
CHECK(v != w);
265 w = v;
CHECK(v == w);
270 v[1] = 8;
CHECK(v != w);
271 w = v;
CHECK(v == w);
276 v[3] = 0;
CHECK(v != w);
277 w = v;
CHECK(v == w);
282 v[0] = 1;
CHECK(v != w);
283 w = v;
CHECK(v == w);
352TEST_CASE(
"gl_vec: component-wise vector multiplication")
385TEST_CASE(
"gl_vec: reciprocal (only floating point)")
391TEST_CASE(
"gl_vec: component-wise division (only floating point)")
410 CHECK(
min(
vec4(1, -2, 5, -7),
vec4(0, 2, -4, -3)) ==
vec4(0, -2, -4, -7));
411 CHECK(
min(
ivec4(1, -2, 5, -7),
ivec4(0, 2, -4, -3)) ==
ivec4(0, -2, -4, -7));
415 CHECK(
max(
vec4(1, -2, 5, -7),
vec4(0, 2, -4, -3)) ==
vec4(1, 2, 5, -3));
416 CHECK(
max(
ivec4(1, -2, 5, -7),
ivec4(0, 2, -4, -3)) ==
ivec4(1, 2, 5, -3));
428 CHECK(
clamp(
vec3(2, 3, 4),
vec3(0, 4, -4),
vec3(4, 7, 0)) ==
vec3(2, 4, 0));
429 CHECK(
clamp(
ivec3(2, 3, 4),
ivec3(0, 4, -4),
ivec3(4, 7, 0)) ==
ivec3(2, 4, 0));
430 CHECK(
clamp(
vec4(4, 2, 7, 1),
vec4(0, 3, 2, 1),
vec4(4, 6, 8, 3)) ==
vec4(4, 3, 7, 1));
431 CHECK(
clamp(
ivec4(4, 2, 7, 1),
ivec4(0, 3, 2, 1),
ivec4(4, 6, 8, 3)) ==
ivec4(4, 3, 7, 1));
461TEST_CASE(
"gl_vec: cross product (only for vectors of length 3)")
467TEST_CASE(
"gl_vec: vector length squared (2-norm squared)")
474TEST_CASE(
"gl_vec: vector length (2-norm), (only floating point)")
480TEST_CASE(
"gl_vec: vector normalization, only floating point")
506 CHECK(
sizeof(v2) == 2 *
sizeof(
int));
531 ivec3 v3(10, 20, 30);
532 CHECK(
sizeof(v3) == 3 *
sizeof(
int));
550 CHECK(
sizeof(
v4) == 4 *
sizeof(
int));
576void test_constr(
vec4& z)
580void test_constr(
float x,
vec4& z)
584void test_constr(
float a,
float b,
float c,
float d,
vec4& z)
586 z =
vec4(a, b, c, d);
589void test_change0(
float x,
vec4& z)
593void test_change2(
float x,
vec4& z)
598void test_extract0(
const vec4& x,
float& z)
602void test_extract2(
const vec4& x,
float& z)
607bool test_equal(
const vec4& x,
const vec4& y)
611bool test_not_equal(
const vec4& x,
const vec4& y)
620void test_add(
vec4& x,
const vec4& y)
625void test_negate(
const vec4& x,
vec4& y)
634void test_mul(
float x,
const vec4& y,
vec4& z)
643void test_div(
float x,
const vec4& y,
vec4& z)
647void test_div(
const vec4& x,
float y,
vec4& z)
652void test_sum(
const vec4& x,
float& y)
656void test_sum_broadcast(
const vec4& x,
vec4& y)
661void test_dot(
const vec4& x,
const vec4& y,
float& z)
665void test_dot_broadcast(
const vec4& x,
const vec4& y,
vec4& z)
670void test_length2(
const vec4& x,
float& y)
675void test_length(
const vec4& x,
float& y)
680void test_normalize(
const vec4& x,
vec4& y)
685void test_recip(
const vec4& x,
vec4& y)
691void test_constr(
vec3& z)
695void test_constr(
float x,
vec3& z)
699void test_constr(
float a,
float b,
float c,
vec3& z)
708void test_change0(
float x,
vec3& z)
712void test_change2(
float x,
vec3& z)
717void test_extract0(
const vec3& x,
float& z)
721void test_extract2(
const vec3& x,
float& z)
726bool test_equal(
const vec3& x,
const vec3& y)
730bool test_not_equal(
const vec3& x,
const vec3& y)
739void test_add(
vec3& x,
const vec3& y)
744void test_negate(
const vec3& x,
vec3& y)
753void test_mul(
float x,
const vec3& y,
vec3& z)
762void test_div(
float x,
const vec3& y,
vec3& z)
766void test_div(
const vec3& x,
float y,
vec3& z)
791void test_clamp(
const vec3& x,
float y,
float z,
vec3& w)
796void test_clamp(
const vec4& x,
float y,
float z,
vec4& w)
801void test_clamp(
const vec4& x,
vec4& y)
803 y =
clamp(x, 0.0f, 1.0f);
806void test_sum(
const vec3& x,
float& y)
811void test_dot(
const vec3& x,
const vec3& y,
float& z)
816void test_length2(
const vec3& x,
float& y)
821void test_length(
const vec3& x,
float& y)
826void test_normalize(
const vec3& x,
vec3& y)
imat4 k4(ivec4(1, 2, 3, 4), ivec4(3, 4, 0, 6), ivec4(5, 6, 7, 8), ivec4(7, 8, 9, 0))
imat4 i4(ivec4(1, 2, 3, 4), ivec4(3, 4, 5, 6), ivec4(5, 6, 7, 8), ivec4(7, 8, 9, 0))
imat4 j4(ivec4(1, 0, 3, 4), ivec4(3, 4, 5, 6), ivec4(5, 6, 7, 8), ivec4(7, 8, 9, 0))
imat3 j3(ivec3(1, 2, 3), ivec3(4, 5, 6), ivec3(7, 0, 9))
imat3 i3(ivec3(1, 2, 3), ivec3(4, 5, 6), ivec3(7, 8, 9))
CHECK(vec2(1, 2) !=vec2(1, 4))
TEST_CASE("gl_vec: rsqrt")
constexpr T min_component(const vecN< N, T > &x)
constexpr T dot(const vecN< N, T > &x, const vecN< N, T > &y)
constexpr vecN< 3, T > cross(const vecN< 3, T > &a, const vecN< 3, T > &b)
constexpr vecN< N, int > trunc(const vecN< N, T > &x)
T length(const vecN< N, T > &x)
vecN< N, int > round(const vecN< N, T > &x)
constexpr T length2(const vecN< N, T > &x)
constexpr vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
constexpr vecN< N, T > dot_broadcast(const vecN< N, T > &x, const vecN< N, T > &y)
constexpr vecN< N, T > sum_broadcast(const vecN< N, T > &x)
constexpr T sum(const vecN< N, T > &x)
vecN< N, T > normalize(const vecN< N, T > &x)
constexpr vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
constexpr vecN< N, T > clamp(const vecN< N, T > &x, const vecN< N, T > &minVal, const vecN< N, T > &maxVal)