From d9507181103bd9d3ee42f8e00e3a01f4d6003c1c Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Tue, 10 Sep 2019 10:50:34 -0700 Subject: [PATCH] linalg: return out array for .toArray, create symmetric mat3 --- src/mol-math/linear-algebra/3d/mat3.ts | 39 ++++++++++++++++++++++++++ src/mol-math/linear-algebra/3d/mat4.ts | 1 + src/mol-math/linear-algebra/3d/quat.ts | 1 + src/mol-math/linear-algebra/3d/vec2.ts | 1 + src/mol-math/linear-algebra/3d/vec3.ts | 1 + src/mol-math/linear-algebra/3d/vec4.ts | 1 + 6 files changed, 44 insertions(+) diff --git a/src/mol-math/linear-algebra/3d/mat3.ts b/src/mol-math/linear-algebra/3d/mat3.ts index d37d4c18c..8e29f2477 100644 --- a/src/mol-math/linear-algebra/3d/mat3.ts +++ b/src/mol-math/linear-algebra/3d/mat3.ts @@ -72,6 +72,7 @@ namespace Mat3 { out[offset + 6] = a[6]; out[offset + 7] = a[7]; out[offset + 8] = a[8]; + return out; } export function fromArray(a: Mat3, array: NumberArray, offset: number) { @@ -220,6 +221,44 @@ namespace Mat3 { return out; } + export function symmtricFromUpper(out: Mat3, a: Mat3) { + if (out === a) { + out[3] = a[1]; + out[6] = a[2]; + out[7] = a[5]; + } else { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[1]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[2]; + out[7] = a[5]; + out[8] = a[8]; + } + return out; + } + + export function symmtricFromLower(out: Mat3, a: Mat3) { + if (out === a) { + out[1] = a[3]; + out[2] = a[6]; + out[5] = a[7]; + } else { + out[0] = a[0]; + out[1] = a[3]; + out[2] = a[6]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[7]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + } + return out; + } + export function determinant(a: Mat3) { const a00 = a[0], a01 = a[1], a02 = a[2]; const a10 = a[3], a11 = a[4], a12 = a[5]; diff --git a/src/mol-math/linear-algebra/3d/mat4.ts b/src/mol-math/linear-algebra/3d/mat4.ts index e98d98361..546b2d806 100644 --- a/src/mol-math/linear-algebra/3d/mat4.ts +++ b/src/mol-math/linear-algebra/3d/mat4.ts @@ -141,6 +141,7 @@ namespace Mat4 { out[offset + 13] = a[13]; out[offset + 14] = a[14]; out[offset + 15] = a[15]; + return out; } export function fromArray(a: Mat4, array: NumberArray, offset: number) { diff --git a/src/mol-math/linear-algebra/3d/quat.ts b/src/mol-math/linear-algebra/3d/quat.ts index 50e12f11a..3b9844d0f 100644 --- a/src/mol-math/linear-algebra/3d/quat.ts +++ b/src/mol-math/linear-algebra/3d/quat.ts @@ -318,6 +318,7 @@ namespace Quat { out[offset + 1] = a[1]; out[offset + 2] = a[2]; out[offset + 3] = a[3]; + return out; } export function fromArray(a: Quat, array: NumberArray, offset: number) { diff --git a/src/mol-math/linear-algebra/3d/vec2.ts b/src/mol-math/linear-algebra/3d/vec2.ts index d1bd98055..16d922951 100644 --- a/src/mol-math/linear-algebra/3d/vec2.ts +++ b/src/mol-math/linear-algebra/3d/vec2.ts @@ -53,6 +53,7 @@ namespace Vec2 { export function toArray(a: Vec2, out: NumberArray, offset: number) { out[offset + 0] = a[0]; out[offset + 1] = a[1]; + return out; } export function fromArray(a: Vec2, array: NumberArray, offset: number) { diff --git a/src/mol-math/linear-algebra/3d/vec3.ts b/src/mol-math/linear-algebra/3d/vec3.ts index 08afca353..51b7a7624 100644 --- a/src/mol-math/linear-algebra/3d/vec3.ts +++ b/src/mol-math/linear-algebra/3d/vec3.ts @@ -73,6 +73,7 @@ namespace Vec3 { out[offset + 0] = v[0] out[offset + 1] = v[1] out[offset + 2] = v[2] + return out } export function create(x: number, y: number, z: number): Vec3 { diff --git a/src/mol-math/linear-algebra/3d/vec4.ts b/src/mol-math/linear-algebra/3d/vec4.ts index ab4eb2dba..32f5ddfbc 100644 --- a/src/mol-math/linear-algebra/3d/vec4.ts +++ b/src/mol-math/linear-algebra/3d/vec4.ts @@ -62,6 +62,7 @@ namespace Vec4 { out[offset + 1] = a[1]; out[offset + 2] = a[2]; out[offset + 3] = a[3]; + return out; } export function fromArray(a: Vec4, array: NumberArray, offset: number) { -- GitLab