@thi.ng/vectors
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -6,2 +6,20 @@ # Change Log | ||
<a name="1.1.0"></a> | ||
# [1.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/vectors@1.0.0...@thi.ng/vectors@1.1.0) (2018-09-10) | ||
### Bug Fixes | ||
* **vectors:** GVec.copy() / get() ([ae261ab](https://github.com/thi-ng/umbrella/commit/ae261ab)) | ||
* **vectors:** Mat23/33/44 toString() impls ([07d1ccf](https://github.com/thi-ng/umbrella/commit/07d1ccf)) | ||
### Features | ||
* **vectors:** add matrix index & property accessors ([3dd0072](https://github.com/thi-ng/umbrella/commit/3dd0072)) | ||
<a name="1.0.0"></a> | ||
@@ -8,0 +26,0 @@ # [1.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/vectors@0.6.0...@thi.ng/vectors@1.0.0) (2018-09-05) |
@@ -1,2 +0,2 @@ | ||
import { ReadonlyVec, VecOp2, VecOp2o, ReadonlyVecOp1 } from "./api"; | ||
import { ReadonlyVec, ReadonlyVecOp1, Vec, VecOp2, VecOp2o } from "./api"; | ||
export declare const x: ReadonlyVecOp1<number>; | ||
@@ -6,2 +6,3 @@ export declare const y: ReadonlyVecOp1<number>; | ||
export declare const w: ReadonlyVecOp1<number>; | ||
export declare function $iter(buf: Vec, n: number, i?: number, s?: number): IterableIterator<number>; | ||
/** | ||
@@ -119,7 +120,8 @@ * Applies vector op `fn` to all raw vectors in array `a`, using the | ||
/** | ||
* Helper function to create property accessors for Vec2/3/4. | ||
* Helper function to create vector/matrix index & property accessors. | ||
* | ||
* @param proto | ||
* @param indices | ||
* @param props | ||
*/ | ||
export declare const declareIndices: (proto: any, indices: number[]) => void; | ||
export declare const declareIndices: (proto: any, props: string[]) => void; |
@@ -8,2 +8,8 @@ "use strict"; | ||
exports.w = (v, i = 0, s = 1) => v[i + 3 * s]; | ||
function* $iter(buf, n, i = 0, s = 1) { | ||
for (; n > 0; n--, i += s) { | ||
yield buf[i]; | ||
} | ||
} | ||
exports.$iter = $iter; | ||
/** | ||
@@ -155,11 +161,12 @@ * Applies vector op `fn` to all raw vectors in array `a`, using the | ||
/** | ||
* Helper function to create property accessors for Vec2/3/4. | ||
* Helper function to create vector/matrix index & property accessors. | ||
* | ||
* @param proto | ||
* @param indices | ||
* @param props | ||
*/ | ||
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) => { | ||
exports.declareIndices = (proto, props) => { | ||
const get = (i) => function () { return this.buf[this.i + i * (this.s || 1)]; }; | ||
const set = (i) => function (n) { this.buf[this.i + i * (this.s || 1)] = n; }; | ||
props.forEach((id, i) => { | ||
Object.defineProperty(proto, i, { | ||
@@ -170,3 +177,3 @@ get: get(i), | ||
}); | ||
Object.defineProperty(proto, "xyzw"[i], { | ||
Object.defineProperty(proto, id, { | ||
get: get(i), | ||
@@ -173,0 +180,0 @@ set: set(i), |
@@ -25,3 +25,3 @@ "use strict"; | ||
}; | ||
exports.get = (a, num = a.length, i = 0, s = 1) => exports.set(new (a.constructor)(num), a, 0, i, 1, s); | ||
exports.get = (a, num = a.length, i = 0, s = 1) => exports.set(new (a.constructor)(num), a, num, 0, i, 1, s); | ||
exports.set = (a, b, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => { | ||
@@ -112,6 +112,4 @@ while (--num >= 0) { | ||
} | ||
*[Symbol.iterator]() { | ||
for (let i = this.i, n = this.n; n > 0; n--, i += this.s) { | ||
yield this.buf[i]; | ||
} | ||
[Symbol.iterator]() { | ||
return common_1.$iter(this.buf, this.n, this.i, this.s); | ||
} | ||
@@ -118,0 +116,0 @@ get length() { |
@@ -57,3 +57,12 @@ import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; | ||
i: number; | ||
m00: number; | ||
m01: number; | ||
m10: number; | ||
m11: number; | ||
m20: number; | ||
m21: number; | ||
[id: number]: number; | ||
constructor(buf?: Mat, i?: number); | ||
[Symbol.iterator](): IterableIterator<number>; | ||
readonly length: number; | ||
copy(): Mat23; | ||
@@ -60,0 +69,0 @@ eqDelta(m: Mat23, eps?: number): boolean; |
12
mat23.js
@@ -119,2 +119,8 @@ "use strict"; | ||
} | ||
[Symbol.iterator]() { | ||
return common_1.$iter(this.buf, 6, this.i); | ||
} | ||
get length() { | ||
return 6; | ||
} | ||
copy() { | ||
@@ -154,5 +160,4 @@ return new Mat23(exports.get23(this.buf, this.i)); | ||
toString() { | ||
const i = this.i; | ||
const b = [...this.buf.slice(i, i + 6)].map((x) => x.toFixed(4)); | ||
return `${b[i]} ${b[i + 2]} ${b[i + 4]}\n${b[i + 1]} ${b[i + 3]} ${b[i + 5]}`; | ||
const b = exports.get23(this.buf, this.i).map((x) => x.toFixed(4)); | ||
return `${b[0]} ${b[2]} ${b[4]}\n${b[1]} ${b[3]} ${b[5]}`; | ||
} | ||
@@ -164,1 +169,2 @@ toJSON() { | ||
exports.Mat23 = Mat23; | ||
common_1.declareIndices(Mat23.prototype, ["m00", "m01", "m10", "m11", "m20", "m21"]); |
@@ -51,3 +51,15 @@ import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; | ||
i: number; | ||
m00: number; | ||
m01: number; | ||
m02: number; | ||
m10: number; | ||
m11: number; | ||
m12: number; | ||
m20: number; | ||
m21: number; | ||
m22: number; | ||
[id: number]: number; | ||
constructor(buf?: Mat, i?: number); | ||
[Symbol.iterator](): IterableIterator<number>; | ||
readonly length: number; | ||
copy(): Mat33; | ||
@@ -54,0 +66,0 @@ eqDelta(m: Mat33, eps?: number): boolean; |
16
mat33.js
@@ -142,2 +142,8 @@ "use strict"; | ||
} | ||
[Symbol.iterator]() { | ||
return common_1.$iter(this.buf, 9, this.i); | ||
} | ||
get length() { | ||
return 9; | ||
} | ||
copy() { | ||
@@ -181,7 +187,6 @@ return new Mat33(exports.get33(this.buf, this.i)); | ||
toString() { | ||
const i = this.i; | ||
const b = [...this.buf.slice(i, i + 9)].map((x) => x.toFixed(4)); | ||
return `${b[i]} ${b[i + 3]} ${b[i + 6]} | ||
${b[i + 1]} ${b[i + 4]} ${b[i + 7]} | ||
${b[i + 2]} ${b[i + 5]} ${b[i + 8]}`; | ||
const b = exports.get33(this.buf, this.i).map((x) => x.toFixed(4)); | ||
return `${b[0]} ${b[3]} ${b[6]} | ||
${b[1]} ${b[4]} ${b[7]} | ||
${b[2]} ${b[5]} ${b[8]}`; | ||
} | ||
@@ -193,1 +198,2 @@ toJSON() { | ||
exports.Mat33 = Mat33; | ||
common_1.declareIndices(Mat33.prototype, ["m00", "m01", "m02", "m10", "m11", "m12", "m20", "m21", "m22"]); |
@@ -66,3 +66,22 @@ import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; | ||
i: number; | ||
m00: number; | ||
m01: number; | ||
m02: number; | ||
m03: number; | ||
m10: number; | ||
m11: number; | ||
m12: number; | ||
m13: number; | ||
m20: number; | ||
m21: number; | ||
m22: number; | ||
m23: number; | ||
m30: number; | ||
m31: number; | ||
m32: number; | ||
m33: number; | ||
[id: number]: number; | ||
constructor(buf?: Mat, i?: number); | ||
[Symbol.iterator](): IterableIterator<number>; | ||
readonly length: number; | ||
copy(): Mat44; | ||
@@ -69,0 +88,0 @@ eqDelta(m: Mat44, eps?: number): boolean; |
23
mat44.js
@@ -259,2 +259,8 @@ "use strict"; | ||
} | ||
[Symbol.iterator]() { | ||
return common_1.$iter(this.buf, 16, this.i); | ||
} | ||
get length() { | ||
return 16; | ||
} | ||
copy() { | ||
@@ -312,8 +318,7 @@ return new Mat44(exports.get44(this.buf, this.i)); | ||
toString() { | ||
const i = this.i; | ||
const b = [...this.buf.slice(i, i + 16)].map((x) => x.toFixed(4)); | ||
return `${b[i]} ${b[i + 4]} ${b[i + 8]} ${b[i + 12]} | ||
${b[i + 1]} ${b[i + 5]} ${b[i + 9]} ${b[i + 13]} | ||
${b[i + 2]} ${b[i + 6]} ${b[i + 10]} ${b[i + 14]} | ||
${b[i + 3]} ${b[i + 7]} ${b[i + 11]} ${b[i + 15]}`; | ||
const b = exports.get44(this.buf, this.i).map((x) => x.toFixed(4)); | ||
return `${b[0]} ${b[4]} ${b[8]} ${b[12]} | ||
${b[1]} ${b[5]} ${b[9]} ${b[13]} | ||
${b[2]} ${b[6]} ${b[10]} ${b[14]} | ||
${b[3]} ${b[7]} ${b[11]} ${b[15]}`; | ||
} | ||
@@ -325,1 +330,7 @@ toJSON() { | ||
exports.Mat44 = Mat44; | ||
common_1.declareIndices(Mat44.prototype, [ | ||
"m00", "m01", "m02", "m03", | ||
"m10", "m11", "m12", "m13", | ||
"m20", "m21", "m22", "m23", | ||
"m30", "m31", "m32", "m33" | ||
]); |
{ | ||
"name": "@thi.ng/vectors", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Vector algebra for fixed & variable sizes, memory mapped, flexible layouts", | ||
@@ -32,5 +32,5 @@ "main": "./index.js", | ||
"dependencies": { | ||
"@thi.ng/api": "^4.1.0", | ||
"@thi.ng/checks": "^1.5.7", | ||
"@thi.ng/errors": "^0.1.6" | ||
"@thi.ng/api": "^4.1.1", | ||
"@thi.ng/checks": "^1.5.8", | ||
"@thi.ng/errors": "^0.1.7" | ||
}, | ||
@@ -37,0 +37,0 @@ "keywords": [ |
# @thi.ng/vectors | ||
[![npm (scoped)](https://img.shields.io/npm/v/@thi.ng/vectors.svg)](https://www.npmjs.com/package/@thi.ng/vectors) | ||
[![npm version](https://img.shields.io/npm/v/@thi.ng/vectors.svg)](https://www.npmjs.com/package/@thi.ng/vectors) | ||
![npm downloads](https://img.shields.io/npm/dm/@thi.ng/vectors.svg) | ||
@@ -5,0 +6,0 @@ This project is part of the |
@@ -264,4 +264,4 @@ "use strict"; | ||
} | ||
*[Symbol.iterator]() { | ||
yield* this.array(); | ||
[Symbol.iterator]() { | ||
return common_1.$iter(this.buf, 2, this.i, this.s); | ||
} | ||
@@ -510,2 +510,2 @@ array() { | ||
exports.Vec2 = Vec2; | ||
common_1.declareIndices(Vec2.prototype, [0, 1]); | ||
common_1.declareIndices(Vec2.prototype, ["x", "y"]); |
10
vec3.js
@@ -363,4 +363,4 @@ "use strict"; | ||
} | ||
*[Symbol.iterator]() { | ||
yield* this.array(); | ||
[Symbol.iterator]() { | ||
return common_1.$iter(this.buf, 3, this.i, this.s); | ||
} | ||
@@ -613,3 +613,5 @@ array() { | ||
toString() { | ||
return `[${this.buf[this.i]}, ${this.buf[this.i + this.s]}, ${this.buf[this.i + 2 * this.s]}]`; | ||
const i = this.i; | ||
const s = this.s; | ||
return `[${this.buf[i]}, ${this.buf[i + s]}, ${this.buf[i + 2 * s]}]`; | ||
} | ||
@@ -625,2 +627,2 @@ toJSON() { | ||
exports.Vec3 = Vec3; | ||
common_1.declareIndices(Vec3.prototype, [0, 1, 2]); | ||
common_1.declareIndices(Vec3.prototype, ["x", "y", "z"]); |
10
vec4.js
@@ -340,4 +340,4 @@ "use strict"; | ||
} | ||
*[Symbol.iterator]() { | ||
yield* this.array(); | ||
[Symbol.iterator]() { | ||
return common_1.$iter(this.buf, 4, this.i, this.s); | ||
} | ||
@@ -539,3 +539,5 @@ array() { | ||
toString() { | ||
return `[${this.buf[this.i]}, ${this.buf[this.i + this.s]}, ${this.buf[this.i + 2 * this.s]}, ${this.buf[this.i + 3 * this.s]}]`; | ||
const i = this.i; | ||
const s = this.s; | ||
return `[${this.buf[i]}, ${this.buf[i + s]}, ${this.buf[i + 2 * s]}, ${this.buf[i + 3 * s]}]`; | ||
} | ||
@@ -551,2 +553,2 @@ toJSON() { | ||
exports.Vec4 = Vec4; | ||
common_1.declareIndices(Vec4.prototype, [0, 1, 2, 3]); | ||
common_1.declareIndices(Vec4.prototype, ["x", "y", "z", "w"]); |
239539
4259
353
Updated@thi.ng/api@^4.1.1
Updated@thi.ng/checks@^1.5.8
Updated@thi.ng/errors@^0.1.7