Skip to content

Commit

Permalink
updated Vec3 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacey committed Oct 6, 2023
1 parent 3a9259d commit 81cc2b4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 172 deletions.
11 changes: 10 additions & 1 deletion include/ngl/NGLassert.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/
#ifndef NGLASSERT_H_
#define NGLASSERT_H_

#include <exception>
#include <string_view>
//----------------------------------------------------------------------------------------------------------------------
/// @file NGLassert.h
/// @brief re impliment asserts so we don't exit on failure
Expand Down Expand Up @@ -54,6 +55,14 @@

#endif // #if defined(NGL_DEBUG)

class NGLIndexOutOfBounds : public std::exception {
public:
const char * what () const noexcept override {
return "Index out of bounds ";
}
};


#endif // __NGLASSERT_H__


Expand Down
167 changes: 0 additions & 167 deletions include/ngl/ShaderLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,173 +240,6 @@ class NGL_DLLEXPORT ShaderLib
/// @brief debug print any registered uniforms
//----------------------------------------------------------------------------------------------------------------------
static void printRegisteredUniforms(std::string_view _shader) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the float value of the parameter to set
/// @param[in] _v1 the float value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
// static bool setUniform(std::string_view _paramName, Real _v0, Real _v1) noexcept;
//static bool getUniform(std::string_view _paramName, Real &o_v0, Real &o_v1) noexcept;
//static bool getUniform(std::string_view _paramName, Vec2 &o_v3) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the float value of the parameter to set
/// @param[in] _v1 the float value of the parameter to set
/// @param[in] _v2 the float value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, Real _v0, Real _v1, Real _v2) noexcept;
//static bool getUniform(std::string_view _paramName, Real &o_v0, Real &o_v1, Real &o_v2) noexcept;
//static bool getUniform(std::string_view _paramName, Vec3 &o_v) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the float value of the parameter to set
/// @param[in] _v1 the float value of the parameter to set
/// @param[in] _v2 the float value of the parameter to set
/// @param[in] _v3 the float value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, Real _v0, Real _v1, Real _v2, Real _v3) noexcept;
//static bool getUniform(std::string_view _paramName, Real &o_v0, Real &o_v1, Real &o_v2, Real &o_v3) noexcept;
//static bool getUniform(std::string_view _paramName, Vec4 &o_v) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the int value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, GLint _v0) noexcept;
//static bool getUniform(std::string_view _paramName, GLint &o_v0) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the int value of the parameter to set
/// @param[in] _v1 the int value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, GLint _v0, GLint _v1) noexcept;
//static bool getUniform(std::string_view _paramName, GLint &o_v0,GLint &o_v1) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the int value of the parameter to set
/// @param[in] _v1 the int value of the parameter to set
/// @param[in] _v2 the int value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, GLint _v0, GLint _v1, GLint _v2) noexcept;
//static bool getUniform(std::string_view _paramName, GLint &o_v0,GLint &o_v1,GLint &o_v2) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the int value of the parameter to set
/// @param[in] _v1 the int value of the parameter to set
/// @param[in] _v2 the int value of the parameter to set
/// @param[in] _v3 the int value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, GLint _v0, GLint _v1, GLint _v2, GLint _v3) noexcept;
//static bool getUniform(std::string_view _paramName, GLint &o_v0,GLint &o_v1,GLint &o_v2,GLint &o_v3) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the Vec3 value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, Vec2 _v0) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the Vec3 value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, Vec3 _v0) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the Vec4 value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, Vec4 _v0) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the Mat2 value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, Mat2 _v0) noexcept;
//static bool getUniform(std::string_view _paramName, Mat2 &_v0) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the Mat3 value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, Mat3 _v0) noexcept;
//static bool getUniform(std::string_view _paramName, Mat3 &_v0) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the Mat4 value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, Mat4 _v0) noexcept;
//static bool getUniform(std::string_view _paramName, Mat4 &_v0) noexcept;

// // compatability functions to make it easier to use GLM
// static bool setUniformMatrix2fv(std::string_view _paramName, const GLfloat *_value, MatrixTranspose _transpose = MatrixTranspose::TransposeOff) noexcept;
// static bool setUniformMatrix4fv(std::string_view _paramName, const GLfloat *_value, MatrixTranspose _transpose = MatrixTranspose::TransposeOff) noexcept;
// static bool setUniformMatrix3fv(std::string_view _paramName, const GLfloat *_value, MatrixTranspose _transpose = MatrixTranspose::TransposeOff) noexcept;

#ifdef USEGLM
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the Vec3 value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, glm::vec2 _v0) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the Vec3 value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, glm::vec3 _v0) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the Vec4 value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
///static bool setUniform(std::string_view _paramName, glm::vec4 _v0) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the Mat3 value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, glm::mat2 _v0) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the Mat3 value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, glm::mat3 _v0) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief overloaded method to set shader Uniforms the shader
/// must be the currently active shader of else this will fail
/// @param[in] _paramName the name of the Uniform to set
/// @param[in] _v0 the Mat4 value of the parameter to set
//----------------------------------------------------------------------------------------------------------------------
//static bool setUniform(std::string_view _paramName, glm::mat4 _v0) noexcept;

#endif

//----------------------------------------------------------------------------------------------------------------------
/// @brief method to return a shader ID
Expand Down
3 changes: 1 addition & 2 deletions include/ngl/Vec2.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ class NGL_DLLEXPORT Vec2
//----------------------------------------------------------------------------------------------------------------------
Real &operator[](const size_t &_i) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief [] index operator to access the index component of the Vec2
/// @brief const [] index operator to access the index component of the Vec2
/// @returns this[x] as a Real
//----------------------------------------------------------------------------------------------------------------------

const Real &operator[](const size_t &_i) const noexcept
{
return m_openGL[_i];
Expand Down
2 changes: 1 addition & 1 deletion include/ngl/Vec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class NGL_DLLEXPORT Vec3
//----------------------------------------------------------------------------------------------------------------------
Real &operator[](const size_t &_i) noexcept;
//----------------------------------------------------------------------------------------------------------------------
/// @brief [] index operator to access the index component of the Vec3
/// @brief [] const index operator to access the index component of the Vec3
/// @returns this[x] as a Real
//----------------------------------------------------------------------------------------------------------------------
const Real &operator[](const size_t &_i) const noexcept
Expand Down
1 change: 0 additions & 1 deletion src/Vec3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ void Vec3::null() noexcept

Real &Vec3::operator[](const size_t &_i) noexcept
{
NGL_ASSERT(_i <= 3)
return (&m_x)[_i];
}

Expand Down
20 changes: 20 additions & 0 deletions tests/Vec3Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ TEST(Vec3, normalize)
test.normalize();
ngl::Vec3 result(0.912266f, 0.0204544f, 0.409088f);
ASSERT_TRUE(test == result);
auto zero=ngl::Vec3::zero();
zero.normalize();
ASSERT_TRUE(std::isnan(zero.m_x));
ASSERT_TRUE(std::isnan(zero.m_y));
ASSERT_TRUE(std::isnan(zero.m_z));

}

TEST(Vec3, Inner)
Expand Down Expand Up @@ -288,6 +294,12 @@ TEST(Vec3, divideFloatEqual)
EXPECT_FLOAT_EQ(a.m_x, 0.5f);
EXPECT_FLOAT_EQ(a.m_y, 1.0f);
EXPECT_FLOAT_EQ(a.m_z, 1.5f);
a/=0.0f;
EXPECT_TRUE(std::isinf(a.m_x));
EXPECT_TRUE(std::isinf(a.m_y));
EXPECT_TRUE(std::isinf(a.m_z));


}

TEST(Vec3, divideFloat)
Expand All @@ -297,6 +309,10 @@ TEST(Vec3, divideFloat)
EXPECT_FLOAT_EQ(b.m_x, 0.5f);
EXPECT_FLOAT_EQ(b.m_y, 1.0f);
EXPECT_FLOAT_EQ(b.m_z, 1.5f);
auto c=a/0.0f;
EXPECT_TRUE(std::isinf(c.m_x));
EXPECT_TRUE(std::isinf(c.m_y));
EXPECT_TRUE(std::isinf(c.m_z));
}

TEST(Vec3, divideVec)
Expand All @@ -307,6 +323,10 @@ TEST(Vec3, divideVec)
EXPECT_FLOAT_EQ(c.m_x, 0.5f);
EXPECT_FLOAT_EQ(c.m_y, 1.0f);
EXPECT_FLOAT_EQ(c.m_z, 1.5f);
ngl::Vec3 d=a/ngl::Vec3::zero();
EXPECT_TRUE(std::isinf(d.m_x));
EXPECT_TRUE(std::isinf(d.m_y));
EXPECT_TRUE(std::isinf(d.m_z));
}

TEST(Vec3, divideEqualVec)
Expand Down

0 comments on commit 81cc2b4

Please sign in to comment.