summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2022-01-11 00:50:17 +0100
committerLinus Groh <mail@linusgroh.de>2022-01-11 23:47:42 +0100
commita4a666152b50ee4b489f0fba56c2cef082a9157d (patch)
treeb060d53e20f17f27b00c266e97499d2ed3b0cc74 /Userland/Libraries/LibGfx
parent03c1f1780da91273333f76208cf0eb0027f1f0c2 (diff)
downloadserenity-a4a666152b50ee4b489f0fba56c2cef082a9157d.zip
LibGfx+LibGL: Do not crash if matrix inverse does not exist
Allow `Matrix::inverse()` to return an error and deal with those in LibGL. Also use this opportunity to more efficiently calculate the transpose of the model view matrix for the normal transformation.
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r--Userland/Libraries/LibGfx/Matrix.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/Userland/Libraries/LibGfx/Matrix.h b/Userland/Libraries/LibGfx/Matrix.h
index 427c43b8b9..33f9536ce2 100644
--- a/Userland/Libraries/LibGfx/Matrix.h
+++ b/Userland/Libraries/LibGfx/Matrix.h
@@ -6,6 +6,7 @@
#pragma once
+#include <AK/Error.h>
#include <AK/Types.h>
#include <initializer_list>
@@ -85,9 +86,8 @@ public:
{
Matrix division;
for (size_t i = 0; i < N; ++i) {
- for (size_t j = 0; j < N; ++j) {
+ for (size_t j = 0; j < N; ++j)
division.m_elements[i][j] = m_elements[i][j] / divisor;
- }
}
return division;
}
@@ -159,10 +159,11 @@ public:
return result;
}
- [[nodiscard]] constexpr Matrix inverse() const
+ [[nodiscard]] constexpr ErrorOr<Matrix> inverse() const
{
auto det = determinant();
- VERIFY(det != 0);
+ if (det == 0)
+ return Error::from_string_literal("inverse of matrix does not exist"sv);
return adjugate() / det;
}
@@ -170,9 +171,8 @@ public:
{
Matrix result;
for (size_t i = 0; i < N; ++i) {
- for (size_t j = 0; j < N; ++j) {
+ for (size_t j = 0; j < N; ++j)
result.m_elements[i][j] = m_elements[j][i];
- }
}
return result;
}