Skip to content

Commit

Permalink
fix: Avoid NaN inverse of singular matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Nov 2, 2024
1 parent be76628 commit 5d32996
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/engine/Math/affine-matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ export class AffineMatrix {
// We don't actually use the 3rd or 4th dimension

const det = this.determinant();
const inverseDet = 1 / det; // TODO zero check, or throw custom error for degenerate matrix
let inverseDet = det; // default to a zero matrix if we have a singular matrix
if (det !== 0) {
inverseDet = 1 / det;
}
const a = this.data[0];
const b = this.data[2];
const c = this.data[1];
Expand Down

0 comments on commit 5d32996

Please sign in to comment.