@thi.ng/vectors
Advanced tools
Comparing version 0.4.0 to 0.5.0
24
api.d.ts
@@ -6,7 +6,29 @@ import { NumericArray } from "@thi.ng/api/api"; | ||
export declare type ReadonlyMat = ArrayLike<number>; | ||
export declare type VecOp = (a: Vec, b: ReadonlyVec, ia: number, ib: number, sa: number, sb: number) => Vec; | ||
/** | ||
* A vector operation involving only a single vector. The vector might | ||
* be modified. | ||
*/ | ||
export declare type VecOp1<T> = (v: Vec, i: number, s?: number) => T; | ||
/** | ||
* A vector operation involving two vectors. The first vector might be | ||
* modified. | ||
*/ | ||
export declare type VecOp2<T> = (a: Vec, b: ReadonlyVec, ia: number, ib: number, sa?: number, sb?: number) => T; | ||
/** | ||
* A readonly vector operation involving only a single vector. | ||
*/ | ||
export declare type ReadonlyVecOp1<T> = (v: ReadonlyVec, i: number, s?: number) => T; | ||
/** | ||
* A readonly vector operation involving two vectors. | ||
*/ | ||
export declare type ReadonlyVecOp2<T> = (a: ReadonlyVec, b: ReadonlyVec, ia: number, ib: number, sa?: number, sb?: number) => T; | ||
export interface IVec { | ||
buf: Vec; | ||
length: number; | ||
i: number; | ||
s: number; | ||
} | ||
export declare const MIN4: ReadonlyArray<number>; | ||
export declare const MAX4: ReadonlyArray<number>; | ||
export declare const ONE4: ReadonlyArray<number>; | ||
export declare const ZERO4: ReadonlyArray<number>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const min = Number.NEGATIVE_INFINITY; | ||
const max = Number.POSITIVE_INFINITY; | ||
exports.MIN4 = Object.freeze([min, min, min, min]); | ||
exports.MAX4 = Object.freeze([max, max, max, max]); | ||
exports.ONE4 = Object.freeze([1, 1, 1, 1]); | ||
exports.ZERO4 = Object.freeze([0, 0, 0, 0]); |
@@ -6,2 +6,14 @@ # Change Log | ||
<a name="0.5.0"></a> | ||
# [0.5.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/vectors@0.4.0...@thi.ng/vectors@0.5.0) (2018-08-30) | ||
### Features | ||
* **vectors:** consolidate vector consts, add toJSON() impls ([bdb5d37](https://github.com/thi-ng/umbrella/commit/bdb5d37)) | ||
* **vectors:** update types, update GVec, add maths fns, swap impls ([d5cec94](https://github.com/thi-ng/umbrella/commit/d5cec94)) | ||
<a name="0.4.0"></a> | ||
@@ -8,0 +20,0 @@ # [0.4.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/vectors@0.3.0...@thi.ng/vectors@0.4.0) (2018-08-28) |
@@ -1,2 +0,2 @@ | ||
import { VecOp } from "./api"; | ||
import { VecOp2 } from "./api"; | ||
export declare const x: (v: ArrayLike<number>, i?: number, _?: number) => number; | ||
@@ -31,3 +31,3 @@ export declare const y: (v: ArrayLike<number>, i?: number, s?: number) => number; | ||
*/ | ||
export declare const transformVectors1: (fn: VecOp, a: import("@thi.ng/api/api").NumericArray, b: ArrayLike<number>, num: number, ia: number, ib: number, csa: number, csb: number, esa: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const transformVectors1: (fn: VecOp2<any>, a: import("@thi.ng/api/api").NumericArray, b: ArrayLike<number>, num: number, ia: number, ib: number, csa: number, csb: number, esa: number) => import("@thi.ng/api/api").NumericArray; | ||
/** | ||
@@ -45,5 +45,5 @@ * @param fn | ||
*/ | ||
export declare const transformVectors2: (fn: VecOp, a: import("@thi.ng/api/api").NumericArray, b: ArrayLike<number>, n: number, ia: number, ib: number, csa: number, csb: number, esa: number, esb: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const transformVectors2: (fn: VecOp2<any>, a: import("@thi.ng/api/api").NumericArray, b: ArrayLike<number>, n: number, ia: number, ib: number, csa: number, csb: number, esa: number, esb: number) => import("@thi.ng/api/api").NumericArray; | ||
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; |
@@ -73,8 +73,17 @@ "use strict"; | ||
}; | ||
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, | ||
exports.declareIndices = (proto, indices) => { | ||
const get = (i) => function () { return this.buf[this.i + i * this.s]; }; | ||
const set = (i) => function (n) { this.buf[this.i + i * this.s] = n; }; | ||
indices.forEach((i) => { | ||
Object.defineProperty(proto, i, { | ||
get: get(i), | ||
set: set(i), | ||
enumerable: true, | ||
}); | ||
Object.defineProperty(proto, "xyzw"[i], { | ||
get: get(i), | ||
set: set(i), | ||
enumerable: true, | ||
}); | ||
}); | ||
}); | ||
}; |
@@ -32,2 +32,3 @@ import { ICopy, IEqualsDelta, IEquiv, ILength } from "@thi.ng/api/api"; | ||
export declare const ceil: (a: import("@thi.ng/api/api").NumericArray, num?: number, i?: number, s?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const fract: (a: import("@thi.ng/api/api").NumericArray, num?: number, i?: number, s?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const sin: (a: import("@thi.ng/api/api").NumericArray, num?: number, i?: number, s?: number) => import("@thi.ng/api/api").NumericArray; | ||
@@ -52,2 +53,4 @@ export declare const cos: (a: import("@thi.ng/api/api").NumericArray, num?: number, i?: number, s?: number) => import("@thi.ng/api/api").NumericArray; | ||
readonly length: number; | ||
getAt(i: number, safe?: boolean): number; | ||
setAt(i: number, x: number, safe?: boolean): void; | ||
copy(): GVec; | ||
@@ -77,2 +80,3 @@ equiv(v: any): boolean; | ||
ceil(): this; | ||
fract(): this; | ||
floor(): this; | ||
@@ -90,3 +94,5 @@ sin(): this; | ||
toString(): string; | ||
toJSON(): import("@thi.ng/api/api").NumericArray; | ||
protected ensureSize(v: Readonly<GVec>): void; | ||
protected ensureIndex(i: number): void; | ||
} |
21
gvec.js
@@ -77,2 +77,3 @@ "use strict"; | ||
exports.ceil = (a, num = a.length, i = 0, s = 1) => exports.opg1(Math.ceil, a, num, i, s); | ||
exports.fract = (a, num = a.length, i = 0, s = 1) => exports.opg1(math_1.fract1, a, num, i, s); | ||
exports.sin = (a, num = a.length, i = 0, s = 1) => exports.opg1(Math.sin, a, num, i, s); | ||
@@ -104,4 +105,12 @@ exports.cos = (a, num = a.length, i = 0, s = 1) => exports.opg1(Math.cos, a, num, i, s); | ||
} | ||
getAt(i, safe = true) { | ||
safe && this.ensureIndex(i); | ||
return this.buf[this.i + i * this.s]; | ||
} | ||
setAt(i, x, safe = true) { | ||
safe && this.ensureIndex(i); | ||
this.buf[this.i + i * this.s] = x; | ||
} | ||
copy() { | ||
return new GVec(exports.get(this.buf, this.n, this.i, this.s), this.n); | ||
return new GVec(exports.get(this.buf, this.n, this.i, this.s)); | ||
} | ||
@@ -211,2 +220,6 @@ equiv(v) { | ||
} | ||
fract() { | ||
exports.fract(this.buf, this.n, this.i, this.s); | ||
return this; | ||
} | ||
floor() { | ||
@@ -267,6 +280,12 @@ exports.floor(this.buf, this.n, this.i, this.s); | ||
} | ||
toJSON() { | ||
return exports.get(this.buf, this.n, this.i, this.s); | ||
} | ||
ensureSize(v) { | ||
this.n !== v.n && illegal_arguments_1.illegalArgs(`vector size: ${v.n} (needed ${this.n})`); | ||
} | ||
ensureIndex(i) { | ||
(i < 0 && i >= this.n) && illegal_arguments_1.illegalArgs(`index out of bounds: ${i}`); | ||
} | ||
} | ||
exports.GVec = GVec; |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./api")); | ||
__export(require("./common")); | ||
@@ -8,0 +9,0 @@ __export(require("./mat23")); |
@@ -56,3 +56,3 @@ import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; | ||
i: number; | ||
constructor(buf: Mat, i?: number); | ||
constructor(buf?: Mat, i?: number); | ||
copy(): Mat23; | ||
@@ -68,2 +68,3 @@ eqDelta(m: Mat23, eps?: number): boolean; | ||
toString(): string; | ||
toJSON(): import("@thi.ng/api/api").NumericArray; | ||
} |
@@ -111,3 +111,3 @@ "use strict"; | ||
constructor(buf, i = 0) { | ||
this.buf = buf; | ||
this.buf = buf || (new Array(6).fill(0)); | ||
this.i = i; | ||
@@ -153,3 +153,6 @@ } | ||
} | ||
toJSON() { | ||
return exports.get23(this.buf, this.i); | ||
} | ||
} | ||
exports.Mat23 = Mat23; |
@@ -50,3 +50,3 @@ import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; | ||
i: number; | ||
constructor(buf: Mat, i?: number); | ||
constructor(buf?: Mat, i?: number); | ||
copy(): Mat33; | ||
@@ -63,2 +63,3 @@ eqDelta(m: Mat33, eps?: number): boolean; | ||
toString(): string; | ||
toJSON(): import("@thi.ng/api/api").NumericArray; | ||
} |
@@ -134,3 +134,3 @@ "use strict"; | ||
constructor(buf, i = 0) { | ||
this.buf = buf; | ||
this.buf = buf || (new Array(9).fill(0)); | ||
this.i = i; | ||
@@ -180,3 +180,6 @@ } | ||
} | ||
toJSON() { | ||
return exports.get33(this.buf, this.i); | ||
} | ||
} | ||
exports.Mat33 = Mat33; |
@@ -61,3 +61,3 @@ import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; | ||
i: number; | ||
constructor(buf: Mat, i?: number); | ||
constructor(buf?: Mat, i?: number); | ||
copy(): Mat44; | ||
@@ -77,2 +77,3 @@ eqDelta(m: Mat44, eps?: number): boolean; | ||
toString(): string; | ||
toJSON(): import("@thi.ng/api/api").NumericArray; | ||
} |
@@ -242,3 +242,3 @@ "use strict"; | ||
constructor(buf, i = 0) { | ||
this.buf = buf; | ||
this.buf = buf || (new Array(16).fill(0)); | ||
this.i = i; | ||
@@ -302,3 +302,6 @@ } | ||
} | ||
toJSON() { | ||
return exports.get44(this.buf, this.i); | ||
} | ||
} | ||
exports.Mat44 = Mat44; |
@@ -8,4 +8,4 @@ export declare const PI: number; | ||
export declare let EPS: number; | ||
export declare const absDiff: (x: number, y: number) => number; | ||
export declare const atan2Abs: (y: number, x: number) => number; | ||
export declare const absDiff1: (x: number, y: number) => number; | ||
export declare const atan2Abs1: (y: number, x: number) => number; | ||
/** | ||
@@ -55,20 +55,26 @@ * Converts angle to degrees. | ||
export declare const smoothStep1: (edge: number, edge2: number, x: number) => number; | ||
export declare const expStep1: (x: number, k: number, n: number) => number; | ||
export declare const gain1: (x: number, k: number) => number; | ||
export declare const min2id: (a: any, b: any) => 1 | 0; | ||
export declare const min3id: (a: any, b: any, c: any) => 2 | 1 | 0; | ||
export declare const min4id: (a: any, b: any, c: any, d: any) => 2 | 1 | 0 | 3; | ||
export declare const min3id: (a: any, b: any, c: any) => 1 | 0 | 2; | ||
export declare const min4id: (a: any, b: any, c: any, d: any) => 1 | 0 | 2 | 3; | ||
export declare const max2id: (a: any, b: any) => 1 | 0; | ||
export declare const max3id: (a: any, b: any, c: any) => 2 | 1 | 0; | ||
export declare const max4id: (a: any, b: any, c: any, d: any) => 2 | 1 | 0 | 3; | ||
export declare const max3id: (a: any, b: any, c: any) => 1 | 0 | 2; | ||
export declare const max4id: (a: any, b: any, c: any, d: any) => 1 | 0 | 2 | 3; | ||
export declare const smin1: (a: number, b: number, k: number) => number; | ||
export declare const smax1: (a: number, b: number, k: number) => number; | ||
/** | ||
* Clamps value `x` to given closed interval. | ||
* | ||
* @param x value to clamp | ||
* @param min lower bound | ||
* @param max upper bound | ||
*/ | ||
* Clamps value `x` to given closed interval. | ||
* | ||
* @param x value to clamp | ||
* @param min lower bound | ||
* @param max upper bound | ||
*/ | ||
export declare const clamp1: (x: number, min: number, max: number) => number; | ||
export declare const mix1: (a: number, b: number, t: number) => number; | ||
export declare const norm1: (x: number, a: number, b: number) => number; | ||
export declare const fit1: (x: number, a: number, b: number, c: number, d: number) => number; | ||
export declare const fitClamped1: (x: number, a: number, b: number, c: number, d: number) => number; | ||
export declare const sign1: (x: number, eps?: number) => 1 | 0 | -1; | ||
export declare const fract1: (x: number) => number; | ||
export declare const trunc1: (x: number) => number; | ||
@@ -83,3 +89,3 @@ export declare const roundTo1: (x: number, prec?: number) => number; | ||
*/ | ||
export declare const inRange: (x: number, min: number, max: number) => boolean; | ||
export declare const inRange1: (x: number, min: number, max: number) => boolean; | ||
/** | ||
@@ -92,2 +98,3 @@ * Returns true iff `x` is in open interval `(min .. max)` | ||
*/ | ||
export declare const inOpenRange: (x: number, min: number, max: number) => boolean; | ||
export declare const inOpenRange1: (x: number, min: number, max: number) => boolean; | ||
export declare const hash1: (x: number) => number; |
29
math.js
@@ -10,4 +10,4 @@ "use strict"; | ||
exports.EPS = 1e-6; | ||
exports.absDiff = (x, y) => Math.abs(x - y); | ||
exports.atan2Abs = (y, x) => { | ||
exports.absDiff1 = (x, y) => Math.abs(x - y); | ||
exports.atan2Abs1 = (y, x) => { | ||
const theta = Math.atan2(y, x); | ||
@@ -66,2 +66,6 @@ return theta < 0 ? exports.TAU + theta : theta; | ||
}; | ||
exports.expStep1 = (x, k, n) => Math.exp(-k * Math.pow(x, n)); | ||
exports.gain1 = (x, k) => x < 0.5 ? | ||
0.5 * Math.pow(2 * x, k) : | ||
1 - 0.5 * Math.pow(2 - 2 * x, k); | ||
exports.min2id = (a, b) => a <= b ? 0 : 1; | ||
@@ -89,14 +93,18 @@ exports.min3id = (a, b, c) => (a <= b) ? | ||
(c >= d ? 2 : 3)); | ||
exports.smin1 = (a, b, k) => -Math.log(Math.exp(-k * a) + Math.exp(-k * b)) / k; | ||
exports.smax1 = (a, b, k) => Math.log(Math.exp(a) + Math.exp(b)) / k; | ||
/** | ||
* Clamps value `x` to given closed interval. | ||
* | ||
* @param x value to clamp | ||
* @param min lower bound | ||
* @param max upper bound | ||
*/ | ||
* Clamps value `x` to given closed interval. | ||
* | ||
* @param x value to clamp | ||
* @param min lower bound | ||
* @param max upper bound | ||
*/ | ||
exports.clamp1 = (x, min, max) => x < min ? min : x > max ? max : x; | ||
exports.mix1 = (a, b, t) => a + (b - a) * t; | ||
exports.norm1 = (x, a, b) => (x - a) / (b - a); | ||
exports.fit1 = (x, a, b, c, d) => c + (d - c) * (x - a) / (b - a); | ||
exports.fitClamped1 = (x, a, b, c, d) => c + (d - c) * exports.clamp1((x - a) / (b - a), 0, 1); | ||
exports.sign1 = (x, eps = exports.EPS) => x > eps ? 1 : x < -eps ? -1 : 0; | ||
exports.fract1 = (x) => x - Math.floor(x); | ||
exports.trunc1 = (x) => x < 0 ? Math.ceil(x) : Math.floor(x); | ||
@@ -111,3 +119,3 @@ exports.roundTo1 = (x, prec = 1) => Math.round(x / prec) * prec; | ||
*/ | ||
exports.inRange = (x, min, max) => x >= min && x <= max; | ||
exports.inRange1 = (x, min, max) => x >= min && x <= max; | ||
/** | ||
@@ -120,2 +128,3 @@ * Returns true iff `x` is in open interval `(min .. max)` | ||
*/ | ||
exports.inOpenRange = (x, min, max) => x > min && x < max; | ||
exports.inOpenRange1 = (x, min, max) => x > min && x < max; | ||
exports.hash1 = (x) => exports.fract1(Math.sin(x) * 758.5453); |
{ | ||
"name": "@thi.ng/vectors", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Vector algebra for fixed & variable sizes, memory mapped, flexible layouts", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -49,3 +49,4 @@ # @thi.ng/vectors | ||
property accessors (including `.length`). The `GVec` class wrapper only | ||
provides `.length` read access. All classes are also iterable. | ||
provides `.length` read access and element access via `getAt()` and | ||
`setAt()`. All classes are iterable. | ||
@@ -96,2 +97,3 @@ ```ts | ||
| Swizzle vector components | | `swizzle2` | `swizzle3` | `swizzle4` | | ||
| Swap vectors | | `swap2` | `swap3` | `swap4` | | ||
| Equality (w/ epsilon) | `eqDelta` | `eqDelta2` | `eqDelta3` | `eqDelta4` | | ||
@@ -98,0 +100,0 @@ | Vector addition | `add` | `add2` | `add3` | `add4` | |
import { ICopy, IEqualsDelta, IEquiv, ILength } from "@thi.ng/api/api"; | ||
import { IVec, Vec } from "./api"; | ||
export declare const ZERO2: ReadonlyArray<number>; | ||
export declare const ONE2: ReadonlyArray<number>; | ||
export declare const op2: (fn: (x: number) => number, a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
@@ -11,3 +9,4 @@ export declare const op22: (fn: (a: number, b: number) => number, a: import("@thi.ng/api/api").NumericArray, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const setS2: (a: import("@thi.ng/api/api").NumericArray, x: number, y: number, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const swizzle2: (a: import("@thi.ng/api/api").NumericArray, b: import("@thi.ng/api/api").NumericArray, x: number, y: number, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const swizzle2: (a: import("@thi.ng/api/api").NumericArray, b: ArrayLike<number>, x: number, y: number, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const swap2: (a: import("@thi.ng/api/api").NumericArray, b: import("@thi.ng/api/api").NumericArray, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const equiv2: (a: ArrayLike<number>, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => boolean; | ||
@@ -28,2 +27,3 @@ export declare const eqDelta2: (a: ArrayLike<number>, b: ArrayLike<number>, eps?: number, ia?: number, ib?: number, sa?: number, sb?: number) => boolean; | ||
export declare const ceil2: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const fract2: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const sin2: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
@@ -80,7 +80,11 @@ export declare const cos2: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
static mapBuffer(buf: Vec, n: number, start?: number, cstride?: number, estride?: number): Vec2[]; | ||
static ZERO: Readonly<Vec2>; | ||
static ONE: Readonly<Vec2>; | ||
static readonly ZERO: Readonly<Vec2>; | ||
static readonly ONE: Readonly<Vec2>; | ||
static readonly MIN: Readonly<Vec2>; | ||
static readonly MAX: Readonly<Vec2>; | ||
buf: Vec; | ||
i: number; | ||
s: number; | ||
x: number; | ||
y: number; | ||
[0]: number; | ||
@@ -90,5 +94,4 @@ [1]: number; | ||
[Symbol.iterator](): IterableIterator<number>; | ||
array(): import("@thi.ng/api/api").NumericArray; | ||
readonly length: number; | ||
x: number; | ||
y: number; | ||
copy(): Vec2; | ||
@@ -101,2 +104,3 @@ equiv(v: any): boolean; | ||
swizzle(v: IVec, x: number, y: number): this; | ||
swap(v: Vec2): this; | ||
add(v: Readonly<Vec2>): this; | ||
@@ -115,2 +119,3 @@ sub(v: Readonly<Vec2>): this; | ||
ceil(): this; | ||
fract(): this; | ||
sqrt(): this; | ||
@@ -151,2 +156,3 @@ pow(v: Readonly<Vec2>): this; | ||
toString(): string; | ||
toJSON(): import("@thi.ng/api/api").NumericArray; | ||
} |
56
vec2.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const is_arraylike_1 = require("@thi.ng/checks/is-arraylike"); | ||
const api_1 = require("./api"); | ||
const common_1 = require("./common"); | ||
const math_1 = require("./math"); | ||
exports.ZERO2 = Object.freeze([0, 0]); | ||
exports.ONE2 = Object.freeze([1, 1]); | ||
exports.op2 = (fn, a, ia = 0, sa = 1) => (a[ia] = fn(a[ia]), a[ia + sa] = fn(a[ia + sa]), a); | ||
@@ -23,2 +22,13 @@ exports.op22 = (fn, a, b, ia = 0, ib = 0, sa = 1, sb = 1) => (a[ia] = fn(a[ia], b[ib]), | ||
}; | ||
exports.swap2 = (a, b, ia = 0, ib = 0, sa = 1, sb = 1) => { | ||
let t = a[ia]; | ||
a[ia] = b[ib]; | ||
b[ib] = t; | ||
ia += sa; | ||
ib += sb; | ||
t = a[ia]; | ||
a[ia] = b[ib]; | ||
b[ib] = t; | ||
return a; | ||
}; | ||
exports.equiv2 = (a, b, ia = 0, ib = 0, sa = 1, sb = 1) => a[ia] === b[ib] && | ||
@@ -41,2 +51,3 @@ a[ia + sa] === b[ib + sb]; | ||
exports.ceil2 = (a, ia = 0, sa = 1) => exports.op2(Math.ceil, a, ia, sa); | ||
exports.fract2 = (a, ia = 0, sa = 1) => exports.op2(math_1.fract1, a, ia, sa); | ||
exports.sin2 = (a, ia = 0, sa = 1) => exports.op2(Math.sin, a, ia, sa); | ||
@@ -110,3 +121,3 @@ exports.cos2 = (a, ia = 0, sa = 1) => exports.op2(Math.cos, a, ia, sa); | ||
}; | ||
exports.heading2 = (a, ia = 0, sa = 1) => math_1.atan2Abs(a[ia + sa], a[ia]); | ||
exports.heading2 = (a, ia = 0, sa = 1) => math_1.atan2Abs1(a[ia + sa], a[ia]); | ||
exports.angleBetween2 = (a, b, normalize = false, ia = 0, ib = 0, sa = 1, sb = 1) => normalize ? | ||
@@ -121,5 +132,5 @@ exports.angleBetween2(exports.get2(a, ia, sa), exports.get2(b, ib, sb)) : | ||
const x = a[ia], y = a[ia + sa]; | ||
return exports.setS2(a, Math.sqrt(x * x + y * y), math_1.atan2Abs(y, x), ia, sa); | ||
return exports.setS2(a, Math.sqrt(x * x + y * y), math_1.atan2Abs1(y, x), ia, sa); | ||
}; | ||
exports.toCartesian2 = (a, b = exports.ZERO2, ia = 0, ib = 0, sa = 1, sb = 1) => { | ||
exports.toCartesian2 = (a, b = api_1.ZERO4, ia = 0, ib = 0, sa = 1, sb = 1) => { | ||
const r = a[ia], theta = a[ia + sa]; | ||
@@ -160,20 +171,10 @@ return exports.setS2(a, r * Math.cos(theta) + b[ib], r * Math.sin(theta) + b[ib + sb], ia, sa); | ||
*[Symbol.iterator]() { | ||
yield this.x; | ||
yield this.y; | ||
yield* this.array(); | ||
} | ||
array() { | ||
return exports.get2(this.buf, this.i, this.s); | ||
} | ||
get length() { | ||
return 2; | ||
} | ||
get x() { | ||
return this.buf[this.i]; | ||
} | ||
set x(x) { | ||
this.buf[this.i] = x; | ||
} | ||
get y() { | ||
return this.buf[this.i + this.s]; | ||
} | ||
set y(y) { | ||
this.buf[this.i + this.s] = y; | ||
} | ||
copy() { | ||
@@ -208,2 +209,6 @@ return new Vec2(exports.get2(this.buf, this.i, this.s)); | ||
} | ||
swap(v) { | ||
exports.swap2(this.buf, v.buf, this.i, v.i, this.s, v.s); | ||
return this; | ||
} | ||
add(v) { | ||
@@ -261,2 +266,6 @@ exports.add2(this.buf, v.buf, this.i, v.i, this.s, v.s); | ||
} | ||
fract() { | ||
exports.fract2(this.buf, this.i, this.s); | ||
return this; | ||
} | ||
sqrt() { | ||
@@ -388,6 +397,11 @@ exports.sqrt2(this.buf, this.i, this.s); | ||
} | ||
toJSON() { | ||
return this.array(); | ||
} | ||
} | ||
Vec2.ZERO = Object.freeze(new Vec2(exports.ZERO2)); | ||
Vec2.ONE = Object.freeze(new Vec2(exports.ONE2)); | ||
Vec2.ZERO = Object.freeze(new Vec2(api_1.ZERO4)); | ||
Vec2.ONE = Object.freeze(new Vec2(api_1.ONE4)); | ||
Vec2.MIN = Object.freeze(new Vec2(api_1.MIN4)); | ||
Vec2.MAX = Object.freeze(new Vec2(api_1.MAX4)); | ||
exports.Vec2 = Vec2; | ||
common_1.declareIndices(Vec2.prototype, [0, 1]); |
import { ICopy, IEqualsDelta, IEquiv, ILength } from "@thi.ng/api/api"; | ||
import { IVec, Vec } from "./api"; | ||
export declare const ZERO3: ReadonlyArray<number>; | ||
export declare const ONE3: ReadonlyArray<number>; | ||
export declare const op3: (fn: (x: number) => number, a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
@@ -11,3 +9,4 @@ export declare const op32: (fn: (a: number, b: number) => number, a: import("@thi.ng/api/api").NumericArray, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const setS3: (a: import("@thi.ng/api/api").NumericArray, x: number, y: number, z: number, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const swizzle3: (a: import("@thi.ng/api/api").NumericArray, b: import("@thi.ng/api/api").NumericArray, x: number, y: number, z: number, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const swizzle3: (a: import("@thi.ng/api/api").NumericArray, b: ArrayLike<number>, x: number, y: number, z: number, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const swap3: (a: import("@thi.ng/api/api").NumericArray, b: import("@thi.ng/api/api").NumericArray, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const equiv3: (a: ArrayLike<number>, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => boolean; | ||
@@ -28,2 +27,3 @@ export declare const eqDelta3: (a: ArrayLike<number>, b: ArrayLike<number>, eps?: number, ia?: number, ib?: number, sa?: number, sb?: number) => boolean; | ||
export declare const ceil3: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const fract3: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const sin3: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
@@ -67,4 +67,4 @@ export declare const cos3: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const fromCylindrical3: (a: import("@thi.ng/api/api").NumericArray, b?: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const minorAxis3: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => 2 | 1 | 0; | ||
export declare const majorAxis3: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => 2 | 1 | 0; | ||
export declare const minorAxis3: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => 1 | 0 | 2; | ||
export declare const majorAxis3: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => 1 | 0 | 2; | ||
export declare const vec3: (x?: number, y?: number, z?: number) => Vec3; | ||
@@ -88,7 +88,12 @@ export declare class Vec3 implements ICopy<Vec3>, IEqualsDelta<Vec3>, IEquiv, ILength, Iterable<number>, IVec { | ||
static orthoNormal3(a: Readonly<Vec3>, b: Readonly<Vec3>, c: Readonly<Vec3>): Vec3; | ||
static ZERO: Readonly<Vec3>; | ||
static ONE: Readonly<Vec3>; | ||
static readonly ZERO: Readonly<Vec3>; | ||
static readonly ONE: Readonly<Vec3>; | ||
static readonly MIN: Readonly<Vec3>; | ||
static readonly MAX: Readonly<Vec3>; | ||
buf: Vec; | ||
i: number; | ||
s: number; | ||
x: number; | ||
y: number; | ||
z: number; | ||
[0]: number; | ||
@@ -99,6 +104,4 @@ [1]: number; | ||
[Symbol.iterator](): IterableIterator<number>; | ||
array(): import("@thi.ng/api/api").NumericArray; | ||
readonly length: number; | ||
x: number; | ||
y: number; | ||
z: number; | ||
copy(): Vec3; | ||
@@ -111,2 +114,3 @@ equiv(v: any): boolean; | ||
swizzle(v: IVec, x: number, y: number, z: number): this; | ||
swap(v: Vec3): this; | ||
add(v: Readonly<Vec3>): this; | ||
@@ -125,2 +129,3 @@ sub(v: Readonly<Vec3>): this; | ||
ceil(): this; | ||
fract(): this; | ||
sqrt(): this; | ||
@@ -138,4 +143,4 @@ pow(v: Readonly<Vec3>): this; | ||
clamp(min: Readonly<Vec3>, max: Readonly<Vec3>): this; | ||
minorAxis(): 2 | 1 | 0; | ||
majorAxis(): 2 | 1 | 0; | ||
minorAxis(): 1 | 0 | 2; | ||
majorAxis(): 1 | 0 | 2; | ||
step(e: Readonly<Vec3>): this; | ||
@@ -168,2 +173,3 @@ smoothStep(e1: Readonly<Vec3>, e2: Readonly<Vec3>): this; | ||
toString(): string; | ||
toJSON(): import("@thi.ng/api/api").NumericArray; | ||
} |
72
vec3.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const is_arraylike_1 = require("@thi.ng/checks/is-arraylike"); | ||
const api_1 = require("./api"); | ||
const common_1 = require("./common"); | ||
const math_1 = require("./math"); | ||
const vec2_1 = require("./vec2"); | ||
exports.ZERO3 = Object.freeze([0, 0, 0]); | ||
exports.ONE3 = Object.freeze([1, 1, 1]); | ||
exports.op3 = (fn, a, ia = 0, sa = 1) => (a[ia] = fn(a[ia]), | ||
@@ -36,2 +35,18 @@ a[ia + sa] = fn(a[ia + sa]), | ||
}; | ||
exports.swap3 = (a, b, ia = 0, ib = 0, sa = 1, sb = 1) => { | ||
let t = a[ia]; | ||
a[ia] = b[ib]; | ||
b[ib] = t; | ||
ia += sa; | ||
ib += sb; | ||
t = a[ia]; | ||
a[ia] = b[ib]; | ||
b[ib] = t; | ||
ia += sa; | ||
ib += sb; | ||
t = a[ia]; | ||
a[ia] = b[ib]; | ||
b[ib] = t; | ||
return a; | ||
}; | ||
exports.equiv3 = (a, b, ia = 0, ib = 0, sa = 1, sb = 1) => a[ia] === b[ib] && | ||
@@ -68,2 +83,3 @@ a[ia + sa] === b[ib + sb] && | ||
exports.ceil3 = (a, ia = 0, sa = 1) => exports.op3(Math.ceil, a, ia, sa); | ||
exports.fract3 = (a, ia = 0, sa = 1) => exports.op3(math_1.fract1, a, ia, sa); | ||
exports.sin3 = (a, ia = 0, sa = 1) => exports.op3(Math.sin, a, ia, sa); | ||
@@ -171,4 +187,4 @@ exports.cos3 = (a, ia = 0, sa = 1) => exports.op3(Math.cos, a, ia, sa); | ||
exports.headingXY3 = vec2_1.heading2; | ||
exports.headingXZ3 = (a, ia = 0, sa = 1) => math_1.atan2Abs(a[ia + 2 * sa], a[ia]); | ||
exports.headingYZ3 = (a, ia = 0, sa = 1) => math_1.atan2Abs(a[ia + 2 * sa], a[ia + sa]); | ||
exports.headingXZ3 = (a, ia = 0, sa = 1) => math_1.atan2Abs1(a[ia + 2 * sa], a[ia]); | ||
exports.headingYZ3 = (a, ia = 0, sa = 1) => math_1.atan2Abs1(a[ia + 2 * sa], a[ia + sa]); | ||
exports.angleBetween3 = (a, b, normalize = false, ia = 0, ib = 0, sa = 1, sb = 1) => normalize ? | ||
@@ -182,5 +198,5 @@ exports.angleBetween3(exports.get3(a, ia, sa), exports.get3(b, ib, sb)) : | ||
const r = Math.sqrt(x * x + y * y + z * z); | ||
return exports.setS3(a, r, Math.asin(z / r), math_1.atan2Abs(y, x), ia, sa); | ||
return exports.setS3(a, r, Math.asin(z / r), math_1.atan2Abs1(y, x), ia, sa); | ||
}; | ||
exports.toCartesian3 = (a, b = exports.ZERO3, ia = 0, ib = 0, sa = 1, sb = 1) => { | ||
exports.toCartesian3 = (a, b = api_1.ZERO4, ia = 0, ib = 0, sa = 1, sb = 1) => { | ||
const r = a[ia]; | ||
@@ -193,3 +209,3 @@ const theta = a[ia + sa]; | ||
exports.toCylindrical3 = vec2_1.toPolar2; | ||
exports.fromCylindrical3 = (a, b = exports.ZERO3, ia = 0, ib = 0, sa = 1, sb = 1) => { | ||
exports.fromCylindrical3 = (a, b = api_1.ZERO4, ia = 0, ib = 0, sa = 1, sb = 1) => { | ||
vec2_1.toCartesian2(a, b, ia, ib, sa, sb); | ||
@@ -234,27 +250,10 @@ a[ia + 2 * sa] += b[ib + 2 * sb]; | ||
*[Symbol.iterator]() { | ||
yield this.x; | ||
yield this.y; | ||
yield this.z; | ||
yield* this.array(); | ||
} | ||
array() { | ||
return exports.get3(this.buf, this.i, this.s); | ||
} | ||
get length() { | ||
return 3; | ||
} | ||
get x() { | ||
return this.buf[this.i]; | ||
} | ||
set x(x) { | ||
this.buf[this.i] = x; | ||
} | ||
get y() { | ||
return this.buf[this.i + this.s]; | ||
} | ||
set y(y) { | ||
this.buf[this.i + this.s] = y; | ||
} | ||
get z() { | ||
return this.buf[this.i + 2 * this.s]; | ||
} | ||
set z(z) { | ||
this.buf[this.i + 2 * this.s] = z; | ||
} | ||
copy() { | ||
@@ -289,2 +288,6 @@ return new Vec3(exports.get3(this.buf, this.i, this.s)); | ||
} | ||
swap(v) { | ||
exports.swap3(this.buf, v.buf, this.i, v.i, this.s, v.s); | ||
return this; | ||
} | ||
add(v) { | ||
@@ -342,2 +345,6 @@ exports.add3(this.buf, v.buf, this.i, v.i, this.s, v.s); | ||
} | ||
fract() { | ||
exports.fract3(this.buf, this.i, this.s); | ||
return this; | ||
} | ||
sqrt() { | ||
@@ -492,6 +499,11 @@ exports.sqrt3(this.buf, this.i, this.s); | ||
} | ||
toJSON() { | ||
return this.array(); | ||
} | ||
} | ||
Vec3.ZERO = Object.freeze(new Vec3(exports.ZERO3)); | ||
Vec3.ONE = Object.freeze(new Vec3(exports.ONE3)); | ||
Vec3.ZERO = Object.freeze(new Vec3(api_1.ZERO4)); | ||
Vec3.ONE = Object.freeze(new Vec3(api_1.ONE4)); | ||
Vec3.MIN = Object.freeze(new Vec3(api_1.MIN4)); | ||
Vec3.MAX = Object.freeze(new Vec3(api_1.MAX4)); | ||
exports.Vec3 = Vec3; | ||
common_1.declareIndices(Vec3.prototype, [0, 1, 2]); |
import { ICopy, IEqualsDelta, IEquiv, ILength } from "@thi.ng/api/api"; | ||
import { IVec, Vec } from "./api"; | ||
export declare const ZERO4: ReadonlyArray<number>; | ||
export declare const ONE4: ReadonlyArray<number>; | ||
export declare const op4: (fn: (x: number) => number, a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
@@ -11,3 +9,4 @@ export declare const op42: (fn: (a: number, b: number) => number, a: import("@thi.ng/api/api").NumericArray, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const setS4: (a: import("@thi.ng/api/api").NumericArray, x: number, y: number, z: number, w: number, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const swizzle4: (a: import("@thi.ng/api/api").NumericArray, b: import("@thi.ng/api/api").NumericArray, x: number, y: number, z: number, w: number, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const swizzle4: (a: import("@thi.ng/api/api").NumericArray, b: ArrayLike<number>, x: number, y: number, z: number, w: number, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const swap4: (a: import("@thi.ng/api/api").NumericArray, b: import("@thi.ng/api/api").NumericArray, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const equiv4: (a: ArrayLike<number>, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => boolean; | ||
@@ -28,2 +27,3 @@ export declare const eqDelta4: (a: ArrayLike<number>, b: ArrayLike<number>, eps?: number, ia?: number, ib?: number, sa?: number, sb?: number) => boolean; | ||
export declare const ceil4: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const fract4: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const sin4: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
@@ -53,4 +53,4 @@ export declare const cos4: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const reflect4: (a: import("@thi.ng/api/api").NumericArray, b: ArrayLike<number>, ia?: number, ib?: number, sa?: number, sb?: number) => import("@thi.ng/api/api").NumericArray; | ||
export declare const minorAxis4: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => 2 | 1 | 0 | 3; | ||
export declare const majorAxis4: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => 2 | 1 | 0 | 3; | ||
export declare const minorAxis4: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => 1 | 0 | 2 | 3; | ||
export declare const majorAxis4: (a: import("@thi.ng/api/api").NumericArray, ia?: number, sa?: number) => 1 | 0 | 2 | 3; | ||
export declare const vec4: (x?: number, y?: number, z?: number, w?: number) => Vec4; | ||
@@ -73,7 +73,13 @@ export declare class Vec4 implements ICopy<Vec4>, IEqualsDelta<Vec4>, IEquiv, ILength, Iterable<number>, IVec { | ||
static mapBuffer(buf: Vec, n: number, start?: number, cstride?: number, estride?: number): Vec4[]; | ||
static ZERO: Readonly<Vec4>; | ||
static ONE: Readonly<Vec4>; | ||
static readonly ZERO: Readonly<Vec4>; | ||
static readonly ONE: Readonly<Vec4>; | ||
static readonly MIN: Readonly<Vec4>; | ||
static readonly MAX: Readonly<Vec4>; | ||
buf: Vec; | ||
i: number; | ||
s: number; | ||
x: number; | ||
y: number; | ||
z: number; | ||
w: number; | ||
[0]: number; | ||
@@ -85,7 +91,4 @@ [1]: number; | ||
[Symbol.iterator](): IterableIterator<number>; | ||
array(): import("@thi.ng/api/api").NumericArray; | ||
readonly length: number; | ||
x: number; | ||
y: number; | ||
z: number; | ||
w: number; | ||
copy(): Vec4; | ||
@@ -98,2 +101,3 @@ equiv(v: any): boolean; | ||
swizzle(v: IVec, x: number, y: number, z: number, w: number): this; | ||
swap(v: Vec4): this; | ||
add(v: Readonly<Vec4>): this; | ||
@@ -112,2 +116,3 @@ sub(v: Readonly<Vec4>): this; | ||
ceil(): this; | ||
fract(): this; | ||
sqrt(): this; | ||
@@ -125,4 +130,4 @@ pow(v: Readonly<Vec4>): this; | ||
clamp(min: Readonly<Vec4>, max: Readonly<Vec4>): this; | ||
minorAxis(): 2 | 1 | 0 | 3; | ||
majorAxis(): 2 | 1 | 0 | 3; | ||
minorAxis(): 1 | 0 | 2 | 3; | ||
majorAxis(): 1 | 0 | 2 | 3; | ||
step(e: Readonly<Vec4>): this; | ||
@@ -141,2 +146,3 @@ smoothStep(e1: Readonly<Vec4>, e2: Readonly<Vec4>): this; | ||
toString(): string; | ||
toJSON(): import("@thi.ng/api/api").NumericArray; | ||
} |
74
vec4.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const is_arraylike_1 = require("@thi.ng/checks/is-arraylike"); | ||
const api_1 = require("./api"); | ||
const common_1 = require("./common"); | ||
const math_1 = require("./math"); | ||
exports.ZERO4 = Object.freeze([0, 0, 0, 0]); | ||
exports.ONE4 = Object.freeze([1, 1, 1, 1]); | ||
exports.op4 = (fn, a, ia = 0, sa = 1) => (a[ia] = fn(a[ia]), | ||
@@ -45,2 +44,23 @@ a[ia + sa] = fn(a[ia + sa]), | ||
}; | ||
exports.swap4 = (a, b, ia = 0, ib = 0, sa = 1, sb = 1) => { | ||
let t = a[ia]; | ||
a[ia] = b[ib]; | ||
b[ib] = t; | ||
ia += sa; | ||
ib += sb; | ||
t = a[ia]; | ||
a[ia] = b[ib]; | ||
b[ib] = t; | ||
ia += sa; | ||
ib += sb; | ||
t = a[ia]; | ||
a[ia] = b[ib]; | ||
b[ib] = t; | ||
ia += sa; | ||
ib += sb; | ||
t = a[ia]; | ||
a[ia] = b[ib]; | ||
b[ib] = t; | ||
return a; | ||
}; | ||
exports.equiv4 = (a, b, ia = 0, ib = 0, sa = 1, sb = 1) => a[ia] === b[ib] && | ||
@@ -83,2 +103,3 @@ a[ia + sa] === b[ib + sb] && | ||
exports.ceil4 = (a, ia = 0, sa = 1) => exports.op4(Math.ceil, a, ia, sa); | ||
exports.fract4 = (a, ia = 0, sa = 1) => exports.op4(math_1.fract1, a, ia, sa); | ||
exports.sin4 = (a, ia = 0, sa = 1) => exports.op4(Math.sin, a, ia, sa); | ||
@@ -190,34 +211,10 @@ exports.cos4 = (a, ia = 0, sa = 1) => exports.op4(Math.cos, a, ia, sa); | ||
*[Symbol.iterator]() { | ||
yield this.x; | ||
yield this.y; | ||
yield this.z; | ||
yield this.w; | ||
yield* this.array(); | ||
} | ||
array() { | ||
return exports.get4(this.buf, this.i, this.s); | ||
} | ||
get length() { | ||
return 4; | ||
} | ||
get x() { | ||
return this.buf[this.i]; | ||
} | ||
set x(x) { | ||
this.buf[this.i] = x; | ||
} | ||
get y() { | ||
return this.buf[this.i + this.s]; | ||
} | ||
set y(y) { | ||
this.buf[this.i + this.s] = y; | ||
} | ||
get z() { | ||
return this.buf[this.i + 2 * this.s]; | ||
} | ||
set z(z) { | ||
this.buf[this.i + 2 * this.s] = z; | ||
} | ||
get w() { | ||
return this.buf[this.i + 3 * this.s]; | ||
} | ||
set w(w) { | ||
this.buf[this.i + 3 * this.s] = w; | ||
} | ||
copy() { | ||
@@ -252,2 +249,6 @@ return new Vec4(exports.get4(this.buf, this.i, this.s)); | ||
} | ||
swap(v) { | ||
exports.swap4(this.buf, v.buf, this.i, v.i, this.s, v.s); | ||
return this; | ||
} | ||
add(v) { | ||
@@ -305,2 +306,6 @@ exports.add4(this.buf, v.buf, this.i, v.i, this.s, v.s); | ||
} | ||
fract() { | ||
exports.fract4(this.buf, this.i, this.s); | ||
return this; | ||
} | ||
sqrt() { | ||
@@ -404,6 +409,11 @@ exports.sqrt4(this.buf, this.i, this.s); | ||
} | ||
toJSON() { | ||
return this.array(); | ||
} | ||
} | ||
Vec4.ZERO = Object.freeze(new Vec4(exports.ZERO4)); | ||
Vec4.ONE = Object.freeze(new Vec4(exports.ONE4)); | ||
Vec4.ZERO = Object.freeze(new Vec4(api_1.ZERO4)); | ||
Vec4.ONE = Object.freeze(new Vec4(api_1.ONE4)); | ||
Vec4.MIN = Object.freeze(new Vec4(api_1.MIN4)); | ||
Vec4.MAX = Object.freeze(new Vec4(api_1.MAX4)); | ||
exports.Vec4 = Vec4; | ||
common_1.declareIndices(Vec4.prototype, [0, 1, 2, 3]); |
194783
3431
317