From e01cc2723faba1bb0fbdd6d2d9b76d285d021ed4 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Tue, 3 Sep 2024 17:32:22 +0200 Subject: [PATCH] common: precision increase while matrix inversion A numerically motivated limit on the matrix determinant set at 1e-6 was not sufficient. The limit has been increased by checkoing whether 1/det is still a number. --- src/common/tvgMath.cpp | 5 ++--- src/common/tvgMath.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/common/tvgMath.cpp b/src/common/tvgMath.cpp index a913daab..3b56b78b 100644 --- a/src/common/tvgMath.cpp +++ b/src/common/tvgMath.cpp @@ -43,9 +43,8 @@ bool mathInverse(const Matrix* m, Matrix* out) m->e12 * (m->e21 * m->e33 - m->e23 * m->e31) + m->e13 * (m->e21 * m->e32 - m->e22 * m->e31); - if (mathZero(det)) return false; - - auto invDet = 1 / det; + auto invDet = 1.0f / det; + if (!std::isfinite(invDet)) return false; out->e11 = (m->e22 * m->e33 - m->e32 * m->e23) * invDet; out->e12 = (m->e13 * m->e32 - m->e12 * m->e33) * invDet; diff --git a/src/common/tvgMath.h b/src/common/tvgMath.h index bb6d5d2c..50786754 100644 --- a/src/common/tvgMath.h +++ b/src/common/tvgMath.h @@ -26,7 +26,7 @@ #define _USE_MATH_DEFINES #include -#include +#include #include "tvgCommon.h" #define MATH_PI 3.14159265358979323846f