openMSX
Functions | Variables
gl_vec.cc File Reference
#include "catch.hpp"
#include "gl_vec.hh"
#include "Math.hh"
#include <concepts>
Include dependency graph for gl_vec.cc:

Go to the source code of this file.

Functions

template<std::floating_point T>
bool approxEq (T x, T y)
 
template<int N, std::floating_point T>
bool approxEq (const vecN< N, T > &x, const vecN< N, T > &y)
 
 TEST_CASE ("gl_vec: rsqrt")
 
 TEST_CASE ("gl_vec: radians, degrees")
 
 TEST_CASE ("gl_vec: constructors")
 
 TEST_CASE ("gl_vec: modify elements")
 
 CHECK (vec2(1, 2) !=vec2(1, 4))
 
 CHECK (ivec2(1, 2)==ivec2(1, 2))
 
 CHECK (ivec2(1, 2) !=ivec2(1, 4))
 
 CHECK (vec3(1, 2, 3)==vec3(1, 2, 3))
 
 CHECK (vec3(1, 2, 3) !=vec3(1, 2, 4))
 
 CHECK (ivec3(1, 2, 3)==ivec3(1, 2, 3))
 
 CHECK (ivec3(1, 2, 3) !=ivec3(1, 2, 4))
 
 CHECK (vec4(1, 2, 3, 4)==vec4(1, 2, 3, 4))
 
 CHECK (vec4(1, 2, 3, 4) !=vec4(1, 2, 4, 4))
 
 CHECK (ivec4(1, 2, 3, 4)==ivec4(1, 2, 3, 4))
 
 CHECK (ivec4(1, 2, 3, 4) !=ivec4(1, 2, 4, 4))
 
 TEST_CASE ("gl_vec: copy constructor, assignment")
 
 TEST_CASE ("gl_vec: construct from larger vector")
 
 TEST_CASE ("gl_vec: vector add")
 
 TEST_CASE ("gl_vec: vector subtract")
 
 TEST_CASE ("gl_vec: vector negate")
 
 TEST_CASE ("gl_vec: component-wise vector multiplication")
 
 CHECK (approxEq(recip(vec4(4, 2, 0.5, 1)), vec4(0.25, 0.5, 2, 1)))
 
 CHECK ((v3/2.0f)==vec3(0, 0.5f, -2))
 
 CHECK ((6.0f/w3)==vec3(-6, -3, 3))
 
 CHECK ((v3/w3)==vec3(0, -0.5f, -2))
 
 CHECK (approxEq((v4/-2.0f), vec4(-1, -0.5f, 2, 1.5f)))
 
 CHECK (approxEq((6.0f/w4), vec4(-6, 3, 3, -1)))
 
 CHECK (approxEq((v4/w4), vec4(-2, 0.5f, -2, 0.5f)))
 
 TEST_CASE ("gl_vec: component-wise min/max")
 
 TEST_CASE ("gl_vec: minimum component within a vector")
 
 TEST_CASE ("gl_vec: clamp")
 
 TEST_CASE ("gl_vec: sum of vector components")
 
 TEST_CASE ("gl_vec: dot product")
 
 CHECK (cross(ivec3(4, -3, 2), ivec3(-1, 3, 2))==ivec3(-12, -10, 9))
 
 CHECK (length2(ivec3(4, -3, 2))==29)
 
 CHECK (length2(vec4(4, -3, 2, -1))==30.0f)
 
 CHECK (length2(ivec4(4, -3, 2, -1))==30)
 
 TEST_CASE ("gl_vec: vector length (2-norm), (only floating point)")
 
 TEST_CASE ("gl_vec: vector normalization, only floating point")
 
 TEST_CASE ("gl_vec: round")
 
 TEST_CASE ("gl_vec: trunc")
 
 TEST_CASE ("gl_vec: named elements")
 

Variables

vec3 w3 (-1, -2, 2)
 
vec4 v4 (2, 1, -4, -3)
 
vec4 w4 (-1, 2, 2, -6)
 

Function Documentation

◆ approxEq() [1/2]

template<int N, std::floating_point T>
bool approxEq ( const vecN< N, T > &  x,
const vecN< N, T > &  y 
)

Definition at line 15 of file gl_vec.cc.

References gl::length2().

◆ approxEq() [2/2]

template<std::floating_point T>
bool approxEq ( x,
y 
)

Definition at line 10 of file gl_vec.cc.

Referenced by TEST_CASE().

◆ CHECK() [1/22]

CHECK ( (6.0f/w3 = =vec3(-6, -3, 3))

◆ CHECK() [2/22]

CHECK ( (v3/2.0f)  = =vec3(0, 0.5f, -2))

◆ CHECK() [3/22]

CHECK ( (v3/w3 = =vec3(0, -0.5f, -2))

◆ CHECK() [4/22]

CHECK ( approxEq((6.0f/w4), vec4(-6, 3, 3, -1))  )

◆ CHECK() [5/22]

CHECK ( approxEq((v4/-2.0f), vec4(-1, -0.5f, 2, 1.5f))  )

◆ CHECK() [6/22]

CHECK ( approxEq((v4/w4), vec4(-2, 0.5f, -2, 0.5f))  )

◆ CHECK() [7/22]

CHECK ( approxEq(recip(vec4(4, 2, 0.5, 1)), vec4(0.25, 0.5, 2, 1))  )

◆ CHECK() [8/22]

CHECK ( cross(ivec3(4, -3, 2), ivec3(-1, 3, 2))  = =ivec3(-12, -10, 9))

◆ CHECK() [9/22]

CHECK ( ivec2(1, 2) !  = ivec2(1, 4))

◆ CHECK() [10/22]

CHECK ( ivec2(1, 2)  = =ivec2(1, 2))

◆ CHECK() [11/22]

CHECK ( ivec3(1, 2, 3) !  = ivec3(1, 2, 4))

◆ CHECK() [12/22]

CHECK ( ivec3(1, 2, 3)  = =ivec3(1, 2, 3))

◆ CHECK() [13/22]

CHECK ( ivec4(1, 2, 3, 4) !  = ivec4(1, 2, 4, 4))

◆ CHECK() [14/22]

CHECK ( ivec4(1, 2, 3, 4)  = =ivec4(1, 2, 3, 4))

◆ CHECK() [15/22]

CHECK ( length2(ivec3(4, -3, 2))  = =29)

◆ CHECK() [16/22]

CHECK ( length2(ivec4(4, -3, 2, -1))  = =30)

◆ CHECK() [17/22]

CHECK ( length2(vec4(4, -3, 2, -1))  = =30.0f)

◆ CHECK() [18/22]

CHECK ( vec2(1, 2) !  = vec2(1, 4))

◆ CHECK() [19/22]

CHECK ( vec3(1, 2, 3) !  = vec3(1, 2, 4))

◆ CHECK() [20/22]

CHECK ( vec3(1, 2, 3)  = =vec3(1, 2, 3))

◆ CHECK() [21/22]

CHECK ( vec4(1, 2, 3, 4) !  = vec4(1, 2, 4, 4))

◆ CHECK() [22/22]

CHECK ( vec4(1, 2, 3, 4)  = =vec4(1, 2, 3, 4))

◆ TEST_CASE() [1/20]

TEST_CASE ( "gl_vec: clamp"  )

Definition at line 427 of file gl_vec.cc.

References CHECK(), and gl::clamp().

◆ TEST_CASE() [2/20]

TEST_CASE ( "gl_vec: component-wise min/max"  )

Definition at line 406 of file gl_vec.cc.

References CHECK(), gl::max(), and gl::min().

◆ TEST_CASE() [3/20]

TEST_CASE ( "gl_vec: component-wise vector multiplication"  )

Definition at line 352 of file gl_vec.cc.

References CHECK(), i3, i4, j3, j4, v4, w3, and w4.

◆ TEST_CASE() [4/20]

TEST_CASE ( "gl_vec: construct from larger vector"  )

Definition at line 287 of file gl_vec.cc.

References CHECK(), i3, i4, and v4.

◆ TEST_CASE() [5/20]

TEST_CASE ( "gl_vec: constructors"  )

Definition at line 41 of file gl_vec.cc.

References CHECK(), i3, i4, j4, k4, v4, and w4.

◆ TEST_CASE() [6/20]

TEST_CASE ( "gl_vec: copy  constructor,
assignment"   
)

Definition at line 247 of file gl_vec.cc.

References CHECK().

◆ TEST_CASE() [7/20]

TEST_CASE ( "gl_vec: dot product"  )

Definition at line 450 of file gl_vec.cc.

References CHECK(), gl::dot(), and gl::dot_broadcast().

◆ TEST_CASE() [8/20]

TEST_CASE ( "gl_vec: minimum component within a vector"  )

Definition at line 419 of file gl_vec.cc.

References CHECK(), and gl::min_component().

◆ TEST_CASE() [9/20]

TEST_CASE ( "gl_vec: modify elements"  )

Definition at line 183 of file gl_vec.cc.

References CHECK(), i3, i4, and v4.

◆ TEST_CASE() [10/20]

TEST_CASE ( "gl_vec: named elements"  )

Definition at line 502 of file gl_vec.cc.

References CHECK(), and v4.

◆ TEST_CASE() [11/20]

TEST_CASE ( "gl_vec:  radians,
degrees"   
)

Definition at line 27 of file gl_vec.cc.

References approxEq(), CHECK(), gl::degrees(), Math::pi, and gl::radians().

◆ TEST_CASE() [12/20]

TEST_CASE ( "gl_vec: round"  )

Definition at line 486 of file gl_vec.cc.

References CHECK(), and gl::round().

◆ TEST_CASE() [13/20]

TEST_CASE ( "gl_vec: rsqrt"  )

Definition at line 21 of file gl_vec.cc.

References CHECK(), and gl::rsqrt().

◆ TEST_CASE() [14/20]

TEST_CASE ( "gl_vec: sum of vector components"  )

Definition at line 439 of file gl_vec.cc.

References CHECK(), gl::sum(), and gl::sum_broadcast().

◆ TEST_CASE() [15/20]

TEST_CASE ( "gl_vec: trunc"  )

Definition at line 494 of file gl_vec.cc.

References CHECK(), and gl::trunc().

◆ TEST_CASE() [16/20]

TEST_CASE ( "gl_vec: vector add"  )

Definition at line 306 of file gl_vec.cc.

References CHECK(), i3, i4, and v4.

◆ TEST_CASE() [17/20]

TEST_CASE ( "gl_vec: vector length   2-norm,
(only floating point)"   
)

Definition at line 474 of file gl_vec.cc.

References CHECK(), and gl::length().

◆ TEST_CASE() [18/20]

TEST_CASE ( "gl_vec: vector negate"  )

Definition at line 344 of file gl_vec.cc.

References CHECK().

◆ TEST_CASE() [19/20]

TEST_CASE ( "gl_vec: vector  normalization,
only floating point"   
)

Definition at line 480 of file gl_vec.cc.

References CHECK(), and gl::normalize().

◆ TEST_CASE() [20/20]

TEST_CASE ( "gl_vec: vector subtract"  )

Definition at line 325 of file gl_vec.cc.

References CHECK(), i3, i4, and v4.

Variable Documentation

◆ v4

vec4 v4(2, 1, -4, -3) ( ,
,
4,
3 
)

◆ w3

vec3 w3(-1, -2, 2) ( 1,
2,
 
)

◆ w4

vec4 w4(-1, 2, 2, -6) ( 1,
,
,
6 
)