New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/vectors

Package Overview
Dependencies
Maintainers
1
Versions
299
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/vectors - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

13

CHANGELOG.md

@@ -6,2 +6,15 @@ # Change Log

<a name="0.2.0"></a>
# [0.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/vectors@0.1.3...@thi.ng/vectors@0.2.0) (2018-08-02)
### Features
* **vectors:** add gvec size checks, add IEquiv & Iterable impls ([2a13f28](https://github.com/thi-ng/umbrella/commit/2a13f28))
* **vectors:** add toCylindrical3() / fromCylindrical3() ([74f939c](https://github.com/thi-ng/umbrella/commit/74f939c))
* **vectors:** make Vec2/3/4 array-like, add IEquiv impls, add tests ([3039a35](https://github.com/thi-ng/umbrella/commit/3039a35))
<a name="0.1.3"></a>

@@ -8,0 +21,0 @@ ## [0.1.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/vectors@0.1.2...@thi.ng/vectors@0.1.3) (2018-08-01)

6

common.d.ts
import { Vec, VecOp } from "./api";
export declare const x: (v: ArrayLike<number>, i?: number, _?: any) => number;
export declare const x: (v: ArrayLike<number>, i?: number, _?: number) => number;
export declare const y: (v: ArrayLike<number>, i?: number, s?: number) => number;

@@ -45,2 +45,4 @@ export declare const z: (v: ArrayLike<number>, i?: number, s?: number) => number;

export declare const transformVectors2: (fn: VecOp, a: Vec, b: ArrayLike<number>, n: number, ia: number, ib: number, csa: number, csb: number, esa: number, esb: number) => Vec;
export declare const eqDelta: (a: Vec, b: Vec, n: number, eps?: number, ia?: number, ib?: number, sa?: number, sb?: number) => boolean;
export declare const equiv: (a: ArrayLike<number>, b: ArrayLike<number>, n: number, ia?: number, ib?: number, sa?: number, sb?: number) => boolean;
export declare const eqDelta: (a: ArrayLike<number>, b: ArrayLike<number>, n: number, eps?: number, ia?: number, ib?: number, sa?: number, sb?: number) => boolean;
export declare const declareIndices: (proto: any, indices: number[]) => void;

@@ -34,4 +34,4 @@ "use strict";

exports.transformVectors1 = (fn, a, b, num, ia, ib, csa, csb, esa) => {
for (let i = ia; num > 0; num--, i += esa) {
fn(a, b, i, ib, csa, csb);
for (; num > 0; num--, ia += esa) {
fn(a, b, ia, ib, csa, csb);
}

@@ -53,11 +53,17 @@ return a;

exports.transformVectors2 = (fn, a, b, n, ia, ib, csa, csb, esa, esb) => {
for (let i = ia, j = ib; n > 0; n--, i += esa, j += esb) {
fn(a, b, i, j, csa, csb);
for (; n > 0; n--, ia += esa, ib += esb) {
fn(a, b, ia, ib, csa, csb);
}
return a;
};
exports.equiv = (a, b, n, ia = 0, ib = 0, sa = 1, sb = 1) => {
for (; n > 0; n--, ia += sa, ib += sb) {
if (a[ia] !== b[ib]) {
return false;
}
}
return true;
};
exports.eqDelta = (a, b, n, eps = math_1.EPS, ia = 0, ib = 0, sa = 1, sb = 1) => {
if (a === b)
return true;
for (; --n >= 0; ia += sa, ib += sb) {
for (; n > 0; n--, ia += sa, ib += sb) {
if (!math_1.eqDelta1(a[ia], b[ib], eps)) {

@@ -69,1 +75,8 @@ return false;

};
exports.declareIndices = (proto, indices) => indices.forEach((i) => {
Object.defineProperty(proto, i, {
get: function () { return this.buf[this.i + i * this.s]; },
set: function (n) { this.buf[this.i + i * this.s] = n; },
enumerable: true,
});
});

@@ -1,2 +0,2 @@

import { ICopy, IEqualsDelta } from "@thi.ng/api/api";
import { ICopy, IEqualsDelta, IEquiv, ILength } from "@thi.ng/api/api";
import { IVec, Vec } from "./api";

@@ -42,3 +42,4 @@ export declare const opg1: (fn: (x: number) => number, a: Vec, num?: number, i?: number, s?: number) => Vec;

export declare const smoothStep: (a: Vec, b: ArrayLike<number>, c: ArrayLike<number>, num?: number, ia?: number, ib?: number, ic?: number, sa?: number, sb?: number, sc?: number) => Vec;
export declare class GVec implements ICopy<GVec>, IEqualsDelta<GVec>, IVec {
export declare const gvec: (...coords: number[]) => GVec;
export declare class GVec implements ICopy<GVec>, IEqualsDelta<GVec>, IEquiv, ILength, Iterable<number>, IVec {
buf: Vec;

@@ -49,3 +50,6 @@ n: number;

constructor(buf: Vec, n?: number, i?: number, s?: number);
[Symbol.iterator](): IterableIterator<number>;
readonly length: number;
copy(): GVec;
equiv(v: any): boolean;
eqDelta(v: GVec, eps?: number): boolean;

@@ -63,5 +67,5 @@ set(v: GVec): this;

madd(b: Readonly<GVec>, c: Readonly<GVec>): this;
maddN(b: Readonly<GVec>, n: number): this;
maddN(v: Readonly<GVec>, n: number): this;
mix(b: Readonly<GVec>, c: Readonly<GVec>): this;
mixN(b: Readonly<GVec>, n: number): this;
mixN(v: Readonly<GVec>, n: number): this;
magSq(): number;

@@ -86,2 +90,3 @@ mag(): number;

toString(): string;
protected ensureSize(v: Readonly<GVec>): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const is_arraylike_1 = require("@thi.ng/checks/is-arraylike");
const illegal_arguments_1 = require("@thi.ng/errors/illegal-arguments");
const common_1 = require("./common");

@@ -85,2 +87,3 @@ const math_1 = require("./math");

exports.smoothStep = (a, b, c, num = a.length, ia = 0, ib = 0, ic = 0, sa = 1, sb = 1, sc = 1) => exports.opg3((x, e1, e2) => math_1.smoothStep1(e1, e2, x), a, b, c, num, ia, ib, ic, sa, sb, sc);
exports.gvec = (...coords) => new GVec(coords, coords.length);
class GVec {

@@ -93,5 +96,20 @@ constructor(buf, n = buf.length, i = 0, s = 1) {

}
*[Symbol.iterator]() {
for (let i = this.i, n = this.n; n > 0; n--, i += this.s) {
yield this.buf[i];
}
}
get length() {
return this.n;
}
copy() {
return new GVec(exports.get(this.buf, this.n, this.i, this.s), this.n);
}
equiv(v) {
return v instanceof GVec && v.n === this.n ?
common_1.equiv(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s) :
is_arraylike_1.isArrayLike(v) && v.length === this.n ?
common_1.equiv(this.buf, v, this.n, this.i, 0, this.s, 1) :
false;
}
eqDelta(v, eps = math_1.EPS) {

@@ -101,2 +119,3 @@ return this.n === v.n && common_1.eqDelta(this.buf, v.buf, this.n, eps, this.i, v.i, this.s, v.s);

set(v) {
this.ensureSize(v);
exports.set(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s);

@@ -110,2 +129,3 @@ return this;

add(v) {
this.ensureSize(v);
exports.add(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s);

@@ -115,2 +135,3 @@ return this;

sub(v) {
this.ensureSize(v);
exports.sub(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s);

@@ -120,2 +141,3 @@ return this;

mul(v) {
this.ensureSize(v);
exports.mul(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s);

@@ -125,2 +147,3 @@ return this;

div(v) {
this.ensureSize(v);
exports.div(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s);

@@ -146,15 +169,21 @@ return this;

madd(b, c) {
this.ensureSize(b);
this.ensureSize(c);
exports.madd(this.buf, b.buf, c.buf, this.n, this.i, b.i, c.i, this.s, b.s, c.s);
return this;
}
maddN(b, n) {
exports.maddN(this.buf, b.buf, n, this.n, this.i, b.i, this.s, b.s);
maddN(v, n) {
this.ensureSize(v);
exports.maddN(this.buf, v.buf, n, this.n, this.i, v.i, this.s, v.s);
return this;
}
mix(b, c) {
this.ensureSize(b);
this.ensureSize(c);
exports.mix(this.buf, b.buf, c.buf, this.n, this.i, b.i, c.i, this.s, b.s, c.s);
return this;
}
mixN(b, n) {
exports.mixN(this.buf, b.buf, n, this.n, this.i, b.i, this.s, b.s);
mixN(v, n) {
this.ensureSize(v);
exports.mixN(this.buf, v.buf, n, this.n, this.i, v.i, this.s, v.s);
return this;

@@ -173,2 +202,3 @@ }

dot(v) {
this.ensureSize(v);
return exports.dot(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s);

@@ -205,2 +235,3 @@ }

pow(v) {
this.ensureSize(v);
exports.pow(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s);

@@ -214,2 +245,3 @@ return this;

min(v) {
this.ensureSize(v);
exports.min(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s);

@@ -219,2 +251,3 @@ return this;

max(v) {
this.ensureSize(v);
exports.max(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s);

@@ -224,2 +257,4 @@ return this;

clamp(min, max) {
this.ensureSize(min);
this.ensureSize(max);
exports.clamp(this.buf, min.buf, max.buf, this.n, this.i, min.i, max.i, this.s, min.s, max.s);

@@ -229,2 +264,3 @@ return this;

step(e) {
this.ensureSize(e);
exports.step(this.buf, e.buf, this.n, this.i, e.i, this.s, e.s);

@@ -234,2 +270,4 @@ return this;

smoothStep(e1, e2) {
this.ensureSize(e1);
this.ensureSize(e2);
exports.smoothStep(this.buf, e1.buf, e2.buf, this.n, this.i, e1.i, e2.i, this.s, e1.s, e2.s);

@@ -241,3 +279,6 @@ return this;

}
ensureSize(v) {
this.n !== v.n && illegal_arguments_1.illegalArgs(`vector size: ${v.n} (needed ${this.n})`);
}
}
exports.GVec = GVec;
{
"name": "@thi.ng/vectors",
"version": "0.1.3",
"version": "0.2.0",
"description": "Vector algebra for fixed & variable sizes, memory mapped, flexible layouts",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -43,2 +43,33 @@ # @thi.ng/vectors

#### Vector classes
All of the vector operations listed below are also available via class
wrappers of strided buffer views. These vector classes (`Vec2/3/4`) are
array-like themselves and provide array index and `.x`, `.y`, `.z`, `.w`
property accessors (including `.length`). The `GVec` class wrapper only
provides `.length` read access. All classes are also iterable.
```ts
buf = [0, 1, 0, 2, 0, 3];
// create Vec3 view from index 1, w/ stride 2
a = new v.Vec3(buf, 1, 2);
a[0] *= 10;
a[1] *= 100;
a[2] *= 1000;
a.x // 10
a.y // 200
a.z // 3000
a.length // 3
// iterable
[...a]
// [ 10, 200, 3000 ]
buf
// [ 0, 10, 0, 200, 0, 3000 ]
```
#### Supported operations

@@ -49,2 +80,3 @@

arbitrary sizes, `add2` for 2D vectors, `add3` for 3D, `add4` for 4D...
**Class wrapper methods use the non-suffixed naming.**

@@ -58,60 +90,64 @@ All vector operations (regardless of size) operate on any array-like

| Operation | GVec | Vec2 | Vec3 | Vec4 |
|---------------------------------|--------------|------------------|------------------|------------------|
| Get vector (dense copy) | `get` | `get2` | `get3` | `get4` |
| Set vector components (vector) | `set` | `set2` | `set3` | `set4` |
| Set vector components (uniform) | `setN` | `setN2` | `setN3` | `setN4` |
| Set vector components (scalars) | | `setS2` | `setS3` | `setS4` |
| Swizzle vector components | | `swizzle2` | `swizzle3` | `swizzle4` |
| Equality (w/ epsilon) | `eqDelta` | `eqDelta2` | `eqDelta3` | `eqDelta4` |
| Vector addition | `add` | `add2` | `add3` | `add4` |
| Vector subtraction | `sub` | `sub2` | `sub3` | `sub4` |
| Vector multiplication | `mul` | `mul2` | `mul3` | `mul4` |
| Vector division | `div` | `div2` | `div3` | `div4` |
| Uniform scalar addition | `addN` | `addN2` | `addN3` | `addN4` |
| Uniform scalar subtraction | `subN` | `subN2` | `subN3` | `subN4` |
| Uniform scalar multiply | `mulN` | `mulN2` | `mulN3` | `mulN4` |
| Uniform scalar multiply | `divN` | `divN2` | `divN3` | `divN4` |
| Vector negation | `neg` | `neg2` | `neg3` | `neg4` |
| Multiply-add vectors | `madd` | `madd2` | `madd3` | `madd4` |
| Multiply-add scalar | `maddN` | `maddN2` | `maddN3` | `maddN4` |
| Linear interpolation (vector) | `mix` | `mix2` | `mix3` | `mix4` |
| Linear interpolation (uniform) | `mixN` | `mixN2` | `mixN3` | `mixN4` |
| Dot product | `dot` | `dot2` | `dot3` | `dot4` |
| Cross product | | `cross2` | `cross3` | |
| Magnitude | `mag` | `mag2` | `mag3` | `mag4` |
| Magnitude (squared) | `magSq` | `magSq2` | `magSq3` | `magSq4` |
| Normalize (w/ opt length) | `normalize` | `normalize2` | `normalize3` | `normalize4` |
| Limit to length | | `limit2` | `limit3` | `limit4` |
| Distance | `dist` | `dist2` | `dist3` | `dist4` |
| Distance (squared) | `distSq` | `distSq2` | `distSq3` | `distSq4` |
| Manhattan distance | | `distManhattan2` | `distManhattan3` | `distManhattan4` |
| Chebyshev distance | | `distChebyshev2` | `distChebyshev3` | `distChebyshev4` |
| Reflection | | `reflect2` | `reflect3` | `reflect4` |
| RotationX | | | `rotateX3` | |
| RotationY | | | `rotateY3` | |
| RotationZ | | `rotate2` | `rotateZ3` | |
| Heading XY | | `heading2` | `headingXY3` | |
| Heading XZ | | | `headingXZ3` | |
| Heading YZ | | | `headingYZ3` | |
| Cartesian -> Polar | | `toPolar2` | `toSpherical3` | |
| Polar -> Cartesian | | `toCartesian2` | `toCartesian3` | |
| Minor axis | | `minorAxis2` | `minorAxis3` | `minorAxis4` |
| Major axis | | `majorAxis2` | `majorAxis3` | `majorAxis4` |
| Minimum | `min` | `min2` | `min3` | `min4` |
| Maximum | `max` | `max2` | `max3` | `max4` |
| Range clamping | `clamp` | `clamp2` | `clamp3` | `clamp4` |
| Step (like GLSL) | `step` | `step2` | `step3` | `step4` |
| SmoothStep (like GLSL) | `smoothStep` | `smoothStep2` | `smoothStep3` | `smoothStep4` |
| Absolute value | `abs` | `abs2` | `abs3` | `abs4` |
| Sign (w/ opt epsilon) | `sign` | `sign2` | `sign3` | `sign4` |
| Round down | `floor` | `floor2` | `floor3` | `floor4` |
| Round up | `ceil` | `ceil2` | `ceil3` | `ceil4` |
| Square root | `sqrt` | `sqrt2` | `sqrt3` | `sqrt4` |
| Power (vector) | `pow` | `pow2` | `pow3` | `pow4` |
| Power (uniform) | `powN` | `powN2` | `powN3` | `powN4` |
| Operation | Generic | 2D | 3D | 4D |
|---------------------------------|--------------|------------------|--------------------|------------------|
| Get vector (dense copy) | `get` | `get2` | `get3` | `get4` |
| Set vector components (vector) | `set` | `set2` | `set3` | `set4` |
| Set vector components (uniform) | `setN` | `setN2` | `setN3` | `setN4` |
| Set vector components (scalars) | | `setS2` | `setS3` | `setS4` |
| Swizzle vector components | | `swizzle2` | `swizzle3` | `swizzle4` |
| Equality (w/ epsilon) | `eqDelta` | `eqDelta2` | `eqDelta3` | `eqDelta4` |
| Vector addition | `add` | `add2` | `add3` | `add4` |
| Vector subtraction | `sub` | `sub2` | `sub3` | `sub4` |
| Vector multiplication | `mul` | `mul2` | `mul3` | `mul4` |
| Vector division | `div` | `div2` | `div3` | `div4` |
| Uniform scalar addition | `addN` | `addN2` | `addN3` | `addN4` |
| Uniform scalar subtraction | `subN` | `subN2` | `subN3` | `subN4` |
| Uniform scalar multiply | `mulN` | `mulN2` | `mulN3` | `mulN4` |
| Uniform scalar multiply | `divN` | `divN2` | `divN3` | `divN4` |
| Vector negation | `neg` | `neg2` | `neg3` | `neg4` |
| Multiply-add vectors | `madd` | `madd2` | `madd3` | `madd4` |
| Multiply-add scalar | `maddN` | `maddN2` | `maddN3` | `maddN4` |
| Linear interpolation (vector) | `mix` | `mix2` | `mix3` | `mix4` |
| Linear interpolation (uniform) | `mixN` | `mixN2` | `mixN3` | `mixN4` |
| Dot product | `dot` | `dot2` | `dot3` | `dot4` |
| Cross product | | `cross2` | `cross3` | |
| Magnitude | `mag` | `mag2` | `mag3` | `mag4` |
| Magnitude (squared) | `magSq` | `magSq2` | `magSq3` | `magSq4` |
| Normalize (w/ opt length) | `normalize` | `normalize2` | `normalize3` | `normalize4` |
| Limit to length | | `limit2` | `limit3` | `limit4` |
| Distance | `dist` | `dist2` | `dist3` | `dist4` |
| Distance (squared) | `distSq` | `distSq2` | `distSq3` | `distSq4` |
| Manhattan distance | | `distManhattan2` | `distManhattan3` | `distManhattan4` |
| Chebyshev distance | | `distChebyshev2` | `distChebyshev3` | `distChebyshev4` |
| Reflection | | `reflect2` | `reflect3` | `reflect4` |
| RotationX | | | `rotateX3` | |
| RotationY | | | `rotateY3` | |
| RotationZ | | `rotate2` | `rotateZ3` | |
| Heading XY | | `heading2` | `headingXY3` | |
| Heading XZ | | | `headingXZ3` | |
| Heading YZ | | | `headingYZ3` | |
| Cartesian -> Polar | | `toPolar2` | `toSpherical3` | |
| Polar -> Cartesian | | `toCartesian2` | `toCartesian3` | |
| Cartesian -> Cylindrical | | | `toCylindrical3` | |
| Cylindrical -> Cartesian | | | `fromCylindrical3` | |
| Minor axis | | `minorAxis2` | `minorAxis3` | `minorAxis4` |
| Major axis | | `majorAxis2` | `majorAxis3` | `majorAxis4` |
| Minimum | `min` | `min2` | `min3` | `min4` |
| Maximum | `max` | `max2` | `max3` | `max4` |
| Range clamping | `clamp` | `clamp2` | `clamp3` | `clamp4` |
| Step (like GLSL) | `step` | `step2` | `step3` | `step4` |
| SmoothStep (like GLSL) | `smoothStep` | `smoothStep2` | `smoothStep3` | `smoothStep4` |
| Absolute value | `abs` | `abs2` | `abs3` | `abs4` |
| Sign (w/ opt epsilon) | `sign` | `sign2` | `sign3` | `sign4` |
| Round down | `floor` | `floor2` | `floor3` | `floor4` |
| Round up | `ceil` | `ceil2` | `ceil3` | `ceil4` |
| Square root | `sqrt` | `sqrt2` | `sqrt3` | `sqrt4` |
| Power (vector) | `pow` | `pow2` | `pow3` | `pow4` |
| Power (uniform) | `powN` | `powN2` | `powN3` | `powN4` |
### Matrices
All matrix types are in WebGL layout (column major) and densely packed (stride always 1).
All matrix types are in WebGL layout (column major) and densely packed
(stride always 1). **As with vectors, class wrapper methods use the
non-suffixed naming.**

@@ -122,3 +158,3 @@ - [Mat23](https://github.com/thi-ng/umbrella/tree/master/packages/vectors/src/mat23.ts)

| Operation | Mat23 | Mat33 | Mat44 |
| Operation | 2x3 | 3x3 | 4x4 |
|-------------------------------------|-------------------------|---------------|---------------------|

@@ -125,0 +161,0 @@ | Set identity | `identity23` | `identity33` | `identity44` |

@@ -1,2 +0,2 @@

import { ICopy, IEqualsDelta } from "@thi.ng/api/api";
import { ICopy, IEqualsDelta, IEquiv, ILength } from "@thi.ng/api/api";
import { IVec, Vec } from "./api";

@@ -12,2 +12,3 @@ export declare const ZERO2: ReadonlyArray<number>;

export declare const swizzle2: (a: Vec, b: Vec, x: number, y: number, ia?: number, ib?: number, sa?: number, sb?: number) => Vec;
export declare const equiv2: (a: ArrayLike<number>, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => boolean;
export declare const eqDelta2: (a: ArrayLike<number>, b: ArrayLike<number>, eps?: number, ia?: number, ib?: number, sa?: number, sb?: number) => boolean;

@@ -59,3 +60,3 @@ export declare const add2: (a: Vec, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => Vec;

export declare const vec2: (x?: number, y?: number) => Vec2;
export declare class Vec2 implements ICopy<Vec2>, IEqualsDelta<Vec2>, IVec {
export declare class Vec2 implements ICopy<Vec2>, IEqualsDelta<Vec2>, IEquiv, ILength, Iterable<number>, IVec {
/**

@@ -81,7 +82,11 @@ * Returns array of memory mapped `Vec2` instances using given

s: number;
[0]: number;
[1]: number;
constructor(buf: Vec, index?: number, stride?: number);
[Symbol.iterator](): IterableIterator<number>;
readonly length: number;
x: number;
y: number;
copy(): Vec2;
equiv(v: any): boolean;
eqDelta(v: Readonly<Vec2>, eps?: number): boolean;

@@ -88,0 +93,0 @@ set(v: Readonly<Vec2>): this;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const is_arraylike_1 = require("@thi.ng/checks/is-arraylike");
const common_1 = require("./common");
const math_1 = require("./math");

@@ -21,2 +23,4 @@ exports.ZERO2 = Object.freeze([0, 0]);

};
exports.equiv2 = (a, b, ia = 0, ib = 0, sa = 1, sb = 1) => a[ia] === b[ib] &&
a[ia + sa] === b[ib + sb];
exports.eqDelta2 = (a, b, eps = math_1.EPS, ia = 0, ib = 0, sa = 1, sb = 1) => math_1.eqDelta1(a[ia], b[ib], eps) &&

@@ -142,2 +146,5 @@ math_1.eqDelta1(a[ia + sa], b[ib + sb], eps);

}
get length() {
return 2;
}
get x() {

@@ -158,2 +165,9 @@ return this.buf[this.i];

}
equiv(v) {
return v instanceof Vec2 ?
exports.equiv2(this.buf, v.buf, this.i, v.i, this.s, v.s) :
is_arraylike_1.isArrayLike(v) && v.length === 2 ?
exports.equiv2(this.buf, v, this.i, 0, this.s, 1) :
false;
}
eqDelta(v, eps = math_1.EPS) {

@@ -350,1 +364,2 @@ return exports.eqDelta2(this.buf, v.buf, eps, this.i, v.i, this.s, v.s);

exports.Vec2 = Vec2;
common_1.declareIndices(Vec2.prototype, [0, 1]);

@@ -1,2 +0,2 @@

import { ICopy, IEqualsDelta } from "@thi.ng/api/api";
import { ICopy, IEqualsDelta, IEquiv, ILength } from "@thi.ng/api/api";
import { IVec, Vec } from "./api";

@@ -12,2 +12,3 @@ export declare const ZERO3: ReadonlyArray<number>;

export declare const swizzle3: (a: Vec, b: Vec, x: number, y: number, z: number, ia?: number, ib?: number, sa?: number, sb?: number) => Vec;
export declare const equiv3: (a: ArrayLike<number>, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => boolean;
export declare const eqDelta3: (a: ArrayLike<number>, b: ArrayLike<number>, eps?: number, ia?: number, ib?: number, sa?: number, sb?: number) => boolean;

@@ -61,6 +62,8 @@ export declare const add3: (a: Vec, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => Vec;

export declare const toCartesian3: (a: Vec, b?: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => Vec;
export declare const toCylindrical3: (a: Vec, ia?: number, sa?: number) => Vec;
export declare const fromCylindrical3: (a: Vec, b?: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => Vec;
export declare const minorAxis3: (a: Vec, ia?: number, sa?: number) => 2 | 1 | 0;
export declare const majorAxis3: (a: Vec, ia?: number, sa?: number) => 2 | 1 | 0;
export declare const vec3: (x?: number, y?: number, z?: number) => Vec3;
export declare class Vec3 implements ICopy<Vec3>, IEqualsDelta<Vec3>, IVec {
export declare class Vec3 implements ICopy<Vec3>, IEqualsDelta<Vec3>, IEquiv, ILength, Iterable<number>, IVec {
/**

@@ -87,4 +90,8 @@ * Returns array of memory mapped `Vec3` instances using given

s: number;
[0]: number;
[1]: number;
[2]: number;
constructor(buf: Vec, index?: number, stride?: number);
[Symbol.iterator](): IterableIterator<number>;
readonly length: number;
x: number;

@@ -94,2 +101,3 @@ y: number;

copy(): Vec3;
equiv(v: any): boolean;
eqDelta(v: Readonly<Vec3>, eps?: number): boolean;

@@ -149,3 +157,5 @@ set(v: Readonly<Vec3>): this;

toCartesian(o?: Readonly<Vec3>): this;
toCylindrical(): this;
fromCylindrical(o?: Readonly<Vec3>): this;
toString(): string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const is_arraylike_1 = require("@thi.ng/checks/is-arraylike");
const common_1 = require("./common");
const math_1 = require("./math");

@@ -34,2 +36,5 @@ const vec2_1 = require("./vec2");

};
exports.equiv3 = (a, b, ia = 0, ib = 0, sa = 1, sb = 1) => a[ia] === b[ib] &&
a[ia + sa] === b[ib + sb] &&
a[ia + 2 * sa] === b[ib + 2 * sb];
exports.eqDelta3 = (a, b, eps = math_1.EPS, ia = 0, ib = 0, sa = 1, sb = 1) => math_1.eqDelta1(a[ia], b[ib], eps) &&

@@ -160,2 +165,8 @@ math_1.eqDelta1(a[ia + sa], b[ib + sb], eps) &&

};
exports.toCylindrical3 = vec2_1.toPolar2;
exports.fromCylindrical3 = (a, b = exports.ZERO3, ia = 0, ib = 0, sa = 1, sb = 1) => {
vec2_1.toCartesian2(a, b, ia, ib, sa, sb);
a[ia + 2 * sa] += b[ib + 2 * sb];
return a;
};
exports.minorAxis3 = (a, ia = 0, sa = 1) => math_1.min3id(Math.abs(a[ia]), Math.abs(a[ia + sa]), Math.abs(a[ia + 2 * sa]));

@@ -200,2 +211,5 @@ exports.majorAxis3 = (a, ia = 0, sa = 1) => math_1.max3id(Math.abs(a[ia]), Math.abs(a[ia + sa]), Math.abs(a[ia + 2 * sa]));

}
get length() {
return 3;
}
get x() {

@@ -222,2 +236,9 @@ return this.buf[this.i];

}
equiv(v) {
return v instanceof Vec3 ?
exports.equiv3(this.buf, v.buf, this.i, v.i, this.s, v.s) :
is_arraylike_1.isArrayLike(v) && v.length === 3 ?
exports.equiv3(this.buf, v, this.i, 0, this.s, 1) :
false;
}
eqDelta(v, eps = math_1.EPS) {

@@ -425,2 +446,10 @@ return exports.eqDelta3(this.buf, v.buf, eps, this.i, v.i, this.s, v.s);

}
toCylindrical() {
exports.toCylindrical3(this.buf, this.i, this.s);
return this;
}
fromCylindrical(o = Vec3.ZERO) {
exports.fromCylindrical3(this.buf, o.buf, this.i, o.i, this.s, o.s);
return this;
}
toString() {

@@ -433,1 +462,2 @@ return `[${this.buf[this.i]}, ${this.buf[this.i + this.s]}, ${this.buf[this.i + 2 * this.s]}]`;

exports.Vec3 = Vec3;
common_1.declareIndices(Vec3.prototype, [0, 1, 2]);

@@ -1,2 +0,2 @@

import { ICopy, IEqualsDelta } from "@thi.ng/api/api";
import { ICopy, IEqualsDelta, IEquiv, ILength } from "@thi.ng/api/api";
import { IVec, Vec } from "./api";

@@ -12,2 +12,3 @@ export declare const ZERO4: ReadonlyArray<number>;

export declare const swizzle4: (a: Vec, b: Vec, x: number, y: number, z: number, w: number, ia?: number, ib?: number, sa?: number, sb?: number) => Vec;
export declare const equiv4: (a: ArrayLike<number>, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => boolean;
export declare const eqDelta4: (a: ArrayLike<number>, b: ArrayLike<number>, eps?: number, ia?: number, ib?: number, sa?: number, sb?: number) => boolean;

@@ -54,3 +55,3 @@ export declare const add4: (a: Vec, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => Vec;

export declare const vec4: (x?: number, y?: number, z?: number, w?: number) => Vec4;
export declare class Vec4 implements ICopy<Vec4>, IEqualsDelta<Vec4>, IVec {
export declare class Vec4 implements ICopy<Vec4>, IEqualsDelta<Vec4>, IEquiv, ILength, Iterable<number>, IVec {
/**

@@ -76,4 +77,9 @@ * Returns array of memory mapped `Vec4` instances using given

s: number;
[0]: number;
[1]: number;
[2]: number;
[3]: number;
constructor(buf: Vec, index?: number, stride?: number);
[Symbol.iterator](): IterableIterator<number>;
readonly length: number;
x: number;

@@ -84,2 +90,3 @@ y: number;

copy(): Vec4;
equiv(v: any): boolean;
eqDelta(v: Readonly<Vec4>, eps?: number): boolean;

@@ -86,0 +93,0 @@ set(v: Readonly<Vec4>): this;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const is_arraylike_1 = require("@thi.ng/checks/is-arraylike");
const common_1 = require("./common");
const math_1 = require("./math");

@@ -43,2 +45,6 @@ exports.ZERO4 = Object.freeze([0, 0, 0, 0]);

};
exports.equiv4 = (a, b, ia = 0, ib = 0, sa = 1, sb = 1) => a[ia] === b[ib] &&
a[ia + sa] === b[ib + sb] &&
a[ia + 2 * sa] === b[ib + 2 * sb] &&
a[ia + 3 * sa] === b[ib + 3 * sb];
exports.eqDelta4 = (a, b, eps = math_1.EPS, ia = 0, ib = 0, sa = 1, sb = 1) => math_1.eqDelta1(a[ia], b[ib], eps) &&

@@ -188,2 +194,5 @@ math_1.eqDelta1(a[ia + sa], b[ib + sb], eps) &&

}
get length() {
return 4;
}
get x() {

@@ -216,2 +225,9 @@ return this.buf[this.i];

}
equiv(v) {
return v instanceof Vec4 ?
exports.equiv4(this.buf, v.buf, this.i, v.i, this.s, v.s) :
is_arraylike_1.isArrayLike(v) && v.length === 4 ?
exports.equiv4(this.buf, v, this.i, 0, this.s, 1) :
false;
}
eqDelta(v, eps = math_1.EPS) {

@@ -390,1 +406,2 @@ return exports.eqDelta4(this.buf, v.buf, eps, this.i, v.i, this.s, v.s);

exports.Vec4 = Vec4;
common_1.declareIndices(Vec4.prototype, [0, 1, 2, 3]);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc