Skip to content
Snippets Groups Projects
Commit beb4351d authored by giagitom's avatar giagitom
Browse files

Add check to avoid non-finite origin vector

parent 0e32e0a7
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,10 @@ namespace Vec3 { ...@@ -48,6 +48,10 @@ namespace Vec3 {
return out; return out;
} }
export function hasUndetermined(a: Vec3): boolean {
return isFinite(a[0]) && isFinite(a[1]) && isFinite(a[2]);
}
export function hasNaN(a: Vec3) { export function hasNaN(a: Vec3) {
return isNaN(a[0]) || isNaN(a[1]) || isNaN(a[2]); return isNaN(a[0]) || isNaN(a[1]) || isNaN(a[2]);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
* *
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author Gianluca Tomasello <giagitom@gmail.com>
*/ */
import { Matrix } from './matrix'; import { Matrix } from './matrix';
...@@ -123,12 +124,17 @@ namespace PrincipalAxes { ...@@ -123,12 +124,17 @@ namespace PrincipalAxes {
const dirB = Vec3.setMagnitude(Vec3(), a.dirB, (d2a + d2b) / 2); const dirB = Vec3.setMagnitude(Vec3(), a.dirB, (d2a + d2b) / 2);
const dirC = Vec3.setMagnitude(Vec3(), a.dirC, (d3a + d3b) / 2); const dirC = Vec3.setMagnitude(Vec3(), a.dirC, (d3a + d3b) / 2);
const okDirA = Vec3.hasUndetermined(dirA);
const okDirB = Vec3.hasUndetermined(dirB);
const okDirC = Vec3.hasUndetermined(dirC);
const origin = Vec3(); const origin = Vec3();
const addCornerHelper = function (d1: number, d2: number, d3: number) { const addCornerHelper = function (d1: number, d2: number, d3: number) {
Vec3.copy(tmpBoxVec, center); Vec3.copy(tmpBoxVec, center);
Vec3.scaleAndAdd(tmpBoxVec, tmpBoxVec, a.dirA, d1);
Vec3.scaleAndAdd(tmpBoxVec, tmpBoxVec, a.dirB, d2); if (okDirA) Vec3.scaleAndAdd(tmpBoxVec, tmpBoxVec, a.dirA, d1);
Vec3.scaleAndAdd(tmpBoxVec, tmpBoxVec, a.dirC, d3); if (okDirB) Vec3.scaleAndAdd(tmpBoxVec, tmpBoxVec, a.dirB, d2);
if (okDirC) Vec3.scaleAndAdd(tmpBoxVec, tmpBoxVec, a.dirC, d3);
Vec3.add(origin, origin, tmpBoxVec); Vec3.add(origin, origin, tmpBoxVec);
}; };
addCornerHelper(d1a, d2a, d3a); addCornerHelper(d1a, d2a, d3a);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment