diff --git a/src/mol-math/linear-algebra/3d/quat.ts b/src/mol-math/linear-algebra/3d/quat.ts index 2642c145c4b437c92f35a76d86177c9c0c3ff04d..569dc63735aae842b58d80837d1e3721c8fc9e81 100644 --- a/src/mol-math/linear-algebra/3d/quat.ts +++ b/src/mol-math/linear-algebra/3d/quat.ts @@ -435,6 +435,10 @@ namespace Quat { return normalize(out, Quat.fromMat3(out, axesTmpMat)); } + + export function toString(a: Quat, precision?: number) { + return `[${a[0].toPrecision(precision)} ${a[1].toPrecision(precision)} ${a[2].toPrecision(precision)} ${a[3].toPrecision(precision)}]`; + } } export default Quat \ No newline at end of file diff --git a/src/mol-math/linear-algebra/3d/vec2.ts b/src/mol-math/linear-algebra/3d/vec2.ts index 3a5785dcffcf41bef5268369fc4ee6014c5c17a3..d1bd980551e856fc5f5e0c699636146776a7eac1 100644 --- a/src/mol-math/linear-algebra/3d/vec2.ts +++ b/src/mol-math/linear-algebra/3d/vec2.ts @@ -166,6 +166,10 @@ namespace Vec2 { export function areEqual(a: Vec2, b: Vec2) { return a[0] === b[0] && a[1] === b[1]; } + + export function toString(a: Vec2, precision?: number) { + return `[${a[0].toPrecision(precision)} ${a[1].toPrecision(precision)}}]`; + } } 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 a8bae39359b0be356ffce17e05559bf11a693280..b50d947b165eb1a9cb7b887b520a9cac304f7b19 100644 --- a/src/mol-math/linear-algebra/3d/vec3.ts +++ b/src/mol-math/linear-algebra/3d/vec3.ts @@ -19,7 +19,7 @@ import Mat4 from './mat4'; import { Quat, Mat3, EPSILON } from '../3d'; -import { spline as _spline, clamp } from '../../interpolate' +import { spline as _spline, quadraticBezier as _quadraticBezier, clamp } from '../../interpolate' import { NumberArray } from '../../../mol-util/type-helpers'; interface Vec3 extends Array<number> { [d: number]: number, '@type': 'vec3', length: 3 } @@ -344,6 +344,14 @@ namespace Vec3 { return out; } + export function quadraticBezier(out: Vec3, a: Vec3, b: Vec3, c: Vec3, t: number) { + out[0] = _quadraticBezier(a[0], b[0], c[0], t); + out[1] = _quadraticBezier(a[1], b[1], c[1], t); + out[2] = _quadraticBezier(a[2], b[2], c[2], t); + + return out; + } + /** * Performs a spline interpolation with two control points and a tension parameter */ @@ -525,8 +533,8 @@ namespace Vec3 { return normalize(out, cross(out, triangleNormalTmpAB, triangleNormalTmpAC)); } - export function toString(a: Vec3) { - return `[${a[0]} ${a[1]} ${a[2]}]`; + export function toString(a: Vec3, precision?: number) { + return `[${a[0].toPrecision(precision)} ${a[1].toPrecision(precision)} ${a[2].toPrecision(precision)}]`; } } diff --git a/src/mol-math/linear-algebra/3d/vec4.ts b/src/mol-math/linear-algebra/3d/vec4.ts index 80672cf6e9cd84d77f09d92e93517410a9c3dd46..753356f0c80ef3650fc3f108404a782a87b447f4 100644 --- a/src/mol-math/linear-algebra/3d/vec4.ts +++ b/src/mol-math/linear-algebra/3d/vec4.ts @@ -225,6 +225,10 @@ namespace Vec4 { Math.abs(a2 - b2) <= EPSILON.Value * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON.Value * Math.max(1.0, Math.abs(a3), Math.abs(b3))); } + + export function toString(a: Vec4, precision?: number) { + return `[${a[0].toPrecision(precision)} ${a[1].toPrecision(precision)} ${a[2].toPrecision(precision)} ${a[3].toPrecision(precision)}]`; + } } export default Vec4 \ No newline at end of file