From dc2b0bf3e6d58af3b0172dec63f134407d0d2477 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Wed, 28 Nov 2018 11:45:33 -0800 Subject: [PATCH] added hasNaN methods to vec, mat, quat --- src/mol-math/linear-algebra/3d/mat3.ts | 5 +++++ src/mol-math/linear-algebra/3d/mat4.ts | 5 +++++ src/mol-math/linear-algebra/3d/quat.ts | 4 ++++ src/mol-math/linear-algebra/3d/vec2.ts | 4 ++++ src/mol-math/linear-algebra/3d/vec3.ts | 4 ++++ src/mol-math/linear-algebra/3d/vec4.ts | 4 ++++ 6 files changed, 26 insertions(+) diff --git a/src/mol-math/linear-algebra/3d/mat3.ts b/src/mol-math/linear-algebra/3d/mat3.ts index c8a24df0e..f18d68fb2 100644 --- a/src/mol-math/linear-algebra/3d/mat3.ts +++ b/src/mol-math/linear-algebra/3d/mat3.ts @@ -97,6 +97,11 @@ namespace Mat3 { return out; } + export function hasNaN(m: Mat3) { + for (let i = 0; i < 9; i++) if (isNaN(m[i])) return true + return false + } + /** * Creates a new Mat3 initialized with values from an existing matrix */ diff --git a/src/mol-math/linear-algebra/3d/mat4.ts b/src/mol-math/linear-algebra/3d/mat4.ts index 24cee288c..d6ac448ac 100644 --- a/src/mol-math/linear-algebra/3d/mat4.ts +++ b/src/mol-math/linear-algebra/3d/mat4.ts @@ -102,6 +102,11 @@ namespace Mat4 { return areEqual(m, _id, typeof eps === 'undefined' ? EPSILON.Value : eps); } + export function hasNaN(m: Mat4) { + for (let i = 0; i < 16; i++) if (isNaN(m[i])) return true + return false + } + export function areEqual(a: Mat4, b: Mat4, eps: number) { for (let i = 0; i < 16; i++) { if (Math.abs(a[i] - b[i]) > eps) return false; diff --git a/src/mol-math/linear-algebra/3d/quat.ts b/src/mol-math/linear-algebra/3d/quat.ts index 119126fc2..8c85b36c0 100644 --- a/src/mol-math/linear-algebra/3d/quat.ts +++ b/src/mol-math/linear-algebra/3d/quat.ts @@ -53,6 +53,10 @@ namespace Quat { out[3] = 1; } + export function hasNaN(q: Quat) { + return isNaN(q[0]) || isNaN(q[1]) || isNaN(q[2]) || isNaN(q[3]) + } + export function create(x: number, y: number, z: number, w: number) { const out = identity(); out[0] = x; diff --git a/src/mol-math/linear-algebra/3d/vec2.ts b/src/mol-math/linear-algebra/3d/vec2.ts index b19586a14..34bdb70bf 100644 --- a/src/mol-math/linear-algebra/3d/vec2.ts +++ b/src/mol-math/linear-algebra/3d/vec2.ts @@ -40,6 +40,10 @@ namespace Vec2 { return out; } + export function hasNaN(a: Vec2) { + return isNaN(a[0]) || isNaN(a[1]) + } + export function toArray(a: Vec2, out: Helpers.NumberArray, offset: number) { out[offset + 0] = a[0]; out[offset + 1] = a[1]; diff --git a/src/mol-math/linear-algebra/3d/vec3.ts b/src/mol-math/linear-algebra/3d/vec3.ts index 852537d35..55e6f7662 100644 --- a/src/mol-math/linear-algebra/3d/vec3.ts +++ b/src/mol-math/linear-algebra/3d/vec3.ts @@ -38,6 +38,10 @@ namespace Vec3 { return out; } + export function hasNaN(a: Vec3) { + return isNaN(a[0]) || isNaN(a[1]) || isNaN(a[2]) + } + export function fromObj(v: { x: number, y: number, z: number }): Vec3 { return create(v.x, v.y, v.z); } diff --git a/src/mol-math/linear-algebra/3d/vec4.ts b/src/mol-math/linear-algebra/3d/vec4.ts index db4f29c33..e54d6d497 100644 --- a/src/mol-math/linear-algebra/3d/vec4.ts +++ b/src/mol-math/linear-algebra/3d/vec4.ts @@ -48,6 +48,10 @@ namespace Vec4 { return out; } + export function hasNaN(a: Vec4) { + return isNaN(a[0]) || isNaN(a[1]) || isNaN(a[2]) || isNaN(a[3]) + } + export function toArray(a: Vec4, out: Helpers.NumberArray, offset: number) { out[offset + 0] = a[0]; out[offset + 1] = a[1]; -- GitLab