From 2676e03f2fb6a5b6d254f83157fb3363427eb865 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Fri, 1 Jun 2018 10:52:54 -0700 Subject: [PATCH] added more vec2/3/4 methods --- src/mol-math/linear-algebra/3d/vec2.ts | 36 ++++++++++++++++++ src/mol-math/linear-algebra/3d/vec3.ts | 40 ++++++++++++++++++++ src/mol-math/linear-algebra/3d/vec4.ts | 52 ++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) diff --git a/src/mol-math/linear-algebra/3d/vec2.ts b/src/mol-math/linear-algebra/3d/vec2.ts index e02c793e1..a87e6fcef 100644 --- a/src/mol-math/linear-algebra/3d/vec2.ts +++ b/src/mol-math/linear-algebra/3d/vec2.ts @@ -93,6 +93,33 @@ namespace Vec2 { return out; } + /** + * Math.round the components of a Vec2 + */ + export function round(out: Vec2, a: Vec2) { + out[0] = Math.round(a[0]); + out[1] = Math.round(a[1]); + return out; + } + + /** + * Math.ceil the components of a Vec2 + */ + export function ceil(out: Vec2, a: Vec2) { + out[0] = Math.ceil(a[0]); + out[1] = Math.ceil(a[1]); + return out; + } + + /** + * Math.floor the components of a Vec2 + */ + export function floor(out: Vec2, a: Vec2) { + out[0] = Math.floor(a[0]); + out[1] = Math.floor(a[1]); + return out; + } + export function distance(a: Vec2, b: Vec2) { const x = b[0] - a[0], y = b[1] - a[1]; @@ -116,6 +143,15 @@ namespace Vec2 { y = a[1]; return x * x + y * y; } + + /** + * Returns the inverse of the components of a Vec2 + */ + export function inverse(out: Vec2, a: Vec2) { + out[0] = 1.0 / a[0]; + out[1] = 1.0 / a[1]; + return out; + } } export default Vec2 \ No newline at end of file diff --git a/src/mol-math/linear-algebra/3d/vec3.ts b/src/mol-math/linear-algebra/3d/vec3.ts index bc44e7e6e..fc7c22999 100644 --- a/src/mol-math/linear-algebra/3d/vec3.ts +++ b/src/mol-math/linear-algebra/3d/vec3.ts @@ -130,6 +130,36 @@ namespace Vec3 { return out; } + /** + * Math.round the components of a Vec3 + */ + export function round(out: Vec3, a: Vec3) { + out[0] = Math.round(a[0]); + out[1] = Math.round(a[1]); + out[2] = Math.round(a[2]); + return out; + } + + /** + * Math.ceil the components of a Vec3 + */ + export function ceil(out: Vec3, a: Vec3) { + out[0] = Math.ceil(a[0]); + out[1] = Math.ceil(a[1]); + out[2] = Math.ceil(a[2]); + return out; + } + + /** + * Math.floor the components of a Vec3 + */ + export function floor(out: Vec3, a: Vec3) { + out[0] = Math.floor(a[0]); + out[1] = Math.floor(a[1]); + out[2] = Math.floor(a[2]); + return out; + } + export function distance(a: Vec3, b: Vec3) { const x = b[0] - a[0], y = b[1] - a[1], @@ -162,6 +192,16 @@ namespace Vec3 { return Vec3.scale(out, Vec3.normalize(out, a), l) } + /** + * Returns the inverse of the components of a Vec3 + */ + export function inverse(out: Vec3, a: Vec3) { + out[0] = 1.0 / a[0]; + out[1] = 1.0 / a[1]; + out[2] = 1.0 / a[2]; + return out; + } + export function normalize(out: Vec3, a: Vec3) { const x = a[0], y = a[1], diff --git a/src/mol-math/linear-algebra/3d/vec4.ts b/src/mol-math/linear-algebra/3d/vec4.ts index dfb565c7e..00d682a16 100644 --- a/src/mol-math/linear-algebra/3d/vec4.ts +++ b/src/mol-math/linear-algebra/3d/vec4.ts @@ -108,6 +108,47 @@ namespace Vec4 { return Math.sqrt(x * x + y * y + z * z + w * w); } + export function scale(out: Vec4, a: Vec4, b: number) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + out[4] = a[4] * b; + return out; + } + + /** + * Math.round the components of a Vec4 + */ + export function round(out: Vec4, a: Vec4) { + out[0] = Math.round(a[0]); + out[1] = Math.round(a[1]); + out[2] = Math.round(a[2]); + out[3] = Math.round(a[3]); + return out; + } + + /** + * Math.ceil the components of a Vec4 + */ + export function ceil(out: Vec4, a: Vec4) { + out[0] = Math.ceil(a[0]); + out[1] = Math.ceil(a[1]); + out[2] = Math.ceil(a[2]); + out[3] = Math.ceil(a[3]); + return out; + } + + /** + * Math.floor the components of a Vec3 + */ + export function floor(out: Vec4, a: Vec4) { + out[0] = Math.floor(a[0]); + out[1] = Math.floor(a[1]); + out[2] = Math.floor(a[2]); + out[3] = Math.floor(a[3]); + return out; + } + export function squaredDistance(a: Vec4, b: Vec4) { const x = b[0] - a[0], y = b[1] - a[1], @@ -144,6 +185,17 @@ namespace Vec4 { export function dot(a: Vec4, b: Vec4) { return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; } + + /** + * Returns the inverse of the components of a Vec4 + */ + export function inverse(out: Vec4, a: Vec4) { + out[0] = 1.0 / a[0]; + out[1] = 1.0 / a[1]; + out[2] = 1.0 / a[2]; + out[3] = 1.0 / a[3]; + return out; + } } export default Vec4 \ No newline at end of file -- GitLab