diff options
Diffstat (limited to 'include/jau/math')
-rw-r--r-- | include/jau/math/geom/frustum.hpp | 2 | ||||
-rw-r--r-- | include/jau/math/mat4f.hpp | 4 | ||||
-rw-r--r-- | include/jau/math/math_error.hpp | 105 | ||||
-rw-r--r-- | include/jau/math/util/pmvmat4f.hpp | 12 |
4 files changed, 84 insertions, 39 deletions
diff --git a/include/jau/math/geom/frustum.hpp b/include/jau/math/geom/frustum.hpp index d6452fa..e516efb 100644 --- a/include/jau/math/geom/frustum.hpp +++ b/include/jau/math/geom/frustum.hpp @@ -127,7 +127,7 @@ class Frustum { : fovhv(fovhv_), zNear(zNear_), zFar(zFar_) { if( zNear <= 0.0f || zFar <= zNear ) { - throw IllegalArgumentException("Requirements zNear > 0 and zFar > zNear, but zNear "+std::to_string(zNear)+", zFar "+std::to_string(zFar), E_FILE_LINE); + throw IllegalArgumentError("Requirements zNear > 0 and zFar > zNear, but zNear "+std::to_string(zNear)+", zFar "+std::to_string(zFar), E_FILE_LINE); } } diff --git a/include/jau/math/mat4f.hpp b/include/jau/math/mat4f.hpp index a0bc107..f016f3a 100644 --- a/include/jau/math/mat4f.hpp +++ b/include/jau/math/mat4f.hpp @@ -1203,10 +1203,10 @@ class alignas(Value_type) Matrix4 { const value_type bottom, const value_type top, const value_type zNear, const value_type zFar) { if( zNear <= zero || zFar <= zNear ) { - throw jau::IllegalArgumentException("Requirements zNear > 0 and zFar > zNear, but zNear "+std::to_string(zNear)+", zFar "+std::to_string(zFar), E_FILE_LINE); + throw jau::IllegalArgumentError("Requirements zNear > 0 and zFar > zNear, but zNear "+std::to_string(zNear)+", zFar "+std::to_string(zFar), E_FILE_LINE); } if( left == right || top == bottom) { - throw jau::IllegalArgumentException("GL_INVALID_VALUE: top,bottom and left,right must not be equal", E_FILE_LINE); + throw jau::IllegalArgumentError("GL_INVALID_VALUE: top,bottom and left,right must not be equal", E_FILE_LINE); } { // m00 = m11 = m22 = m33 = 1f; diff --git a/include/jau/math/math_error.hpp b/include/jau/math/math_error.hpp index fdd496f..4ecf3f5 100644 --- a/include/jau/math/math_error.hpp +++ b/include/jau/math/math_error.hpp @@ -43,62 +43,107 @@ namespace jau::math { */ /** Error types as specified by [C++ Math Error Handling](https://en.cppreference.com/w/cpp/numeric/math/math_errhandling) */ - enum class math_error_t { - /** See FE_INVALID */ + enum class math_error_t : uint16_t { + /** no math error */ + none = 0, + /** See FE_INVALID, i.e. MathDomainError, std::domain_error : std::logic_error */ invalid, - /** See FE_DIVBYZERO */ + /** See FE_DIVBYZERO, i.e. MathDivByZeroError, std::domain_error : std::logic_error*/ div_by_zero, - /** See FE_OVERFLOW */ + /** See FE_OVERFLOW, i.e. MathOverflowError, std::overflow_error : std::runtime_error */ overflow, - /** See FE_UNDERFLOW */ + /** See FE_UNDERFLOW, i.e. MathUnderflowError, std::underflow_error : std::runtime_error */ underflow, - /** See FE_INEXACT */ - inexact + /** See FE_INEXACT, i.e. MathInexactError, std::runtime_error */ + inexact, + /** undefined math error */ + undefined = 1U << 15, }; /** Returns std::string representation of math_error_t */ std::string to_string(const math_error_t v) noexcept; - class MathError : public RuntimeException { + class MathErrorBase : public ExceptionBase { private: math_error_t m_error; - public: - MathError(math_error_t err, std::string const& m, const char* file, int line) noexcept - : RuntimeException("MathError("+to_string(err)+")", m, file, line), m_error(err) {} - - math_error_t error() const noexcept; + protected: + MathErrorBase(math_error_t err, std::string const& m, const char* file, int line) noexcept + : ExceptionBase("MathError("+to_string(err)+")", m, file, line), m_error(err) {} + + public: + math_error_t error() const noexcept; }; - /** math_error_t::invalid */ - class MathDomainError : public MathError { + class MathRuntimeErrorBase : public MathErrorBase { + protected: + MathRuntimeErrorBase(math_error_t err, std::string const& m, const char* file, int line) noexcept + : MathErrorBase(err, m, file, line) {} + }; + + class MathError : public MathErrorBase, public std::exception { public: - MathDomainError(std::string const& m, const char* file, int line) noexcept - : MathError(math_error_t::invalid, m, file, line) {} + MathError(math_error_t err, std::string const& m, const char* file, int line) noexcept + : MathErrorBase(err, m, file, line), exception() {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; - /** math_error_t::div_by_zero, i.e. pole error */ - class MathDivByZeroError : public MathError { + + /** math_error_t::inexact */ + class MathInexactError : public MathRuntimeErrorBase, public std::runtime_error { public: - MathDivByZeroError(std::string const& m, const char* file, int line) noexcept - : MathError(math_error_t::div_by_zero, m, file, line) {} + MathInexactError(std::string const& m, const char* file, int line) noexcept + : MathRuntimeErrorBase(math_error_t::inexact, m, file, line), runtime_error(whole_message()) {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; + /** math_error_t::overflow */ - class MathOverflowError : public MathError { + class MathOverflowError : public MathRuntimeErrorBase, public std::overflow_error { public: MathOverflowError(std::string const& m, const char* file, int line) noexcept - : MathError(math_error_t::overflow, m, file, line) {} + : MathRuntimeErrorBase(math_error_t::overflow, m, file, line), overflow_error(whole_message()) {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; + /** math_error_t::underflow */ - class MathUnderflowError : public MathError { + class MathUnderflowError : public MathRuntimeErrorBase, public std::underflow_error { public: MathUnderflowError(std::string const& m, const char* file, int line) noexcept - : MathError(math_error_t::underflow, m, file, line) {} + : MathRuntimeErrorBase(math_error_t::underflow, m, file, line), underflow_error(whole_message()) {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; - /** math_error_t::inexact */ - class MathInexactError : public MathError { + + /** math_error_t::invalid */ + class MathDomainError : public MathErrorBase, public std::domain_error { + protected: + MathDomainError(math_error_t err, std::string const& m, const char* file, int line) noexcept + : MathErrorBase(err, m, file, line), domain_error(whole_message()) {} + public: - MathInexactError(std::string const& m, const char* file, int line) noexcept - : MathError(math_error_t::inexact, m, file, line) {} + MathDomainError(std::string const& m, const char* file, int line) noexcept + : MathErrorBase(math_error_t::invalid, m, file, line), domain_error(whole_message()) {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; - + + /** math_error_t::div_by_zero, i.e. pole error */ + class MathDivByZeroError : public MathDomainError { + public: + MathDivByZeroError(std::string const& m, const char* file, int line) noexcept + : MathDomainError(math_error_t::div_by_zero, m, file, line) {} + }; + /**@}*/ } // namespace jau diff --git a/include/jau/math/util/pmvmat4f.hpp b/include/jau/math/util/pmvmat4f.hpp index 3073ea3..f4cc846 100644 --- a/include/jau/math/util/pmvmat4f.hpp +++ b/include/jau/math/util/pmvmat4f.hpp @@ -329,7 +329,7 @@ class PMVMatrix4 { */ Mat4& getMvi() { if( 0 == ( INVERSE_MODELVIEW & requestBits ) ) { // FIXME - throw jau::IllegalArgumentException("Not requested in ctor", E_FILE_LINE); + throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE); } updateImpl(false); return matMvi; @@ -344,7 +344,7 @@ class PMVMatrix4 { */ SyncMat4& getSyncMvi() { if( 0 == ( INVERSE_MODELVIEW & requestBits ) ) { // FIXME - throw jau::IllegalArgumentException("Not requested in ctor", E_FILE_LINE); + throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE); } return syncMvi; } @@ -358,7 +358,7 @@ class PMVMatrix4 { */ Mat4& getMvit() { if( 0 == ( INVERSE_TRANSPOSED_MODELVIEW & requestBits ) ) { // FIXME - throw jau::IllegalArgumentException("Not requested in ctor", E_FILE_LINE); + throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE); } updateImpl(false); return matMvit; @@ -373,7 +373,7 @@ class PMVMatrix4 { */ SyncMat4& getSyncMvit() { if( 0 == ( INVERSE_TRANSPOSED_MODELVIEW & requestBits ) ) { // FIXME - throw jau::IllegalArgumentException("Not requested in ctor", E_FILE_LINE); + throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE); } return syncMvit; } @@ -387,7 +387,7 @@ class PMVMatrix4 { */ SyncMats4f& getSyncPMvMvi() { if( 0 == ( INVERSE_MODELVIEW & requestBits ) ) { // FIXME - throw jau::IllegalArgumentException("Not requested in ctor", E_FILE_LINE); + throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE); } return syncP_Mv_Mvi; } @@ -401,7 +401,7 @@ class PMVMatrix4 { */ SyncMats4f& getSyncPMvMviMvit() { if( 0 == ( INVERSE_TRANSPOSED_MODELVIEW & requestBits ) ) { // FIXME - throw jau::IllegalArgumentException("Not requested in ctor", E_FILE_LINE); + throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE); } return syncP_Mv_Mvi_Mvit; } |