Comparing version 0.1.8 to 0.1.9
@@ -0,1 +1,7 @@ | ||
## 0.1.9 | ||
* [Add methods, fix .equals (#46)](https://github.com/PrismarineJS/node-vec3/commit/c6b94c4289cfba5fc460bed99d112cec85fe1cf3) (thanks @szdytom) | ||
* [Add command gh workflow allowing to use release command in comments (#45)](https://github.com/PrismarineJS/node-vec3/commit/8675f8ecf6065278c0d1f889a585a5febf446cc0) (thanks @rom1504) | ||
* [Update to node 18.0.0 (#44)](https://github.com/PrismarineJS/node-vec3/commit/358445025ff7d558c8f3fddec2d5786c8c468db5) (thanks @rom1504) | ||
* [New publish workflow (#38)](https://github.com/PrismarineJS/node-vec3/commit/ed6ba10a9b3d163f5c1ee8cb1b78108296b98477) (thanks @KTibow) | ||
## 0.1.8 | ||
@@ -2,0 +8,0 @@ |
@@ -9,3 +9,34 @@ export class Vec3 { | ||
/** | ||
* Returns true when it is a zero vector. | ||
*/ | ||
isZero(): boolean; | ||
/** | ||
* Access component by index | ||
*/ | ||
at(id: number): number; | ||
/** | ||
* Returns an array component x, z | ||
*/ | ||
xz(): [number, number]; | ||
/** | ||
* Returns an array component x, y | ||
*/ | ||
xy(): [number, number]; | ||
/** | ||
* Returns an array component y, z | ||
*/ | ||
yz(): [number, number]; | ||
/** | ||
* Returns a vector with swapped y and z | ||
*/ | ||
xzy(): Vec3; | ||
/** | ||
* Set own values to given x y z | ||
* If some components is given null, then those components won't change | ||
*/ | ||
@@ -110,5 +141,6 @@ set(x: number, y: number, z: number): this; | ||
/** | ||
* Returns true when all values match with the values off the other vector | ||
* Check whether two vectors are equal | ||
* Returns true if each components have at most `error` difference | ||
*/ | ||
equals(other: Vec3): boolean; | ||
equals(other: Vec3, error?: number): boolean; | ||
@@ -115,0 +147,0 @@ /** |
30
index.js
@@ -10,2 +10,26 @@ const re = /\((-?[.\d]+), (-?[.\d]+), (-?[.\d]+)\)/ | ||
isZero () { | ||
return this.x === 0 && this.y === 0 && this.z === 0 | ||
} | ||
at (id) { | ||
return this.toArray()[id] | ||
} | ||
xz () { | ||
return [this.x, this.z] | ||
} | ||
xy () { | ||
return [this.x, this.y] | ||
} | ||
yz () { | ||
return [this.y, this.z] | ||
} | ||
xzy () { | ||
return new Vec3(this.x, this.z, this.y) | ||
} | ||
set (x, y, z) { | ||
@@ -127,4 +151,6 @@ this.x = x | ||
equals (other) { | ||
return this.x === other.x && this.y === other.y && this.z === other.z | ||
equals (other, error = 0) { | ||
return Math.abs(this.x - other.x) <= error && | ||
Math.abs(this.y - other.y) <= error && | ||
Math.abs(this.z - other.z) <= error | ||
} | ||
@@ -131,0 +157,0 @@ |
{ | ||
"name": "vec3", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "3d vector math with good unit tests", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -32,51 +32,57 @@ # vec3 | ||
``` | ||
v() | ||
✓ no args | ||
✓ x, y, z | ||
✓ array | ||
✓ object | ||
✓ string coords | ||
✓ deserialize | ||
✓ invalid deserialize | ||
v() | ||
✔ no args | ||
✔ x, y, z | ||
✔ array | ||
✔ object | ||
✔ string coords | ||
✔ deserialize | ||
✔ invalid deserialize | ||
vec3 | ||
✓ rounded | ||
✓ round | ||
✓ floored | ||
✓ floor | ||
✓ offset | ||
✓ translate | ||
✓ plus | ||
✓ minus | ||
✓ scaled | ||
✓ abs | ||
✓ distanceTo | ||
✓ equals | ||
✓ toString | ||
✓ clone | ||
✓ add | ||
✓ subtract | ||
✓ multiply | ||
✓ divide | ||
✓ set | ||
✓ modulus | ||
✓ volume | ||
✓ min | ||
✓ max | ||
✓ update | ||
✓ norm | ||
✓ dot | ||
✓ cross | ||
✓ unit | ||
✓ normalize | ||
✓ scale | ||
✓ xyDistanceTo | ||
✓ xzDistanceTo | ||
✓ yzDistanceTo | ||
✓ innerProduct | ||
✓ manhattanDistanceTo | ||
✓ toArray | ||
✔ isZero | ||
✔ at | ||
✔ xz | ||
✔ xy | ||
✔ yz | ||
✔ xzy | ||
✔ rounded | ||
✔ round | ||
✔ floored | ||
✔ floor | ||
✔ offset | ||
✔ translate | ||
✔ plus | ||
✔ minus | ||
✔ scaled | ||
✔ abs | ||
✔ distanceTo | ||
✔ distanceSquared | ||
✔ equals | ||
✔ toString | ||
✔ clone | ||
✔ add | ||
✔ subtract | ||
✔ multiply | ||
✔ divide | ||
✔ set | ||
✔ modulus | ||
✔ volume | ||
✔ min | ||
✔ max | ||
✔ update | ||
✔ norm | ||
✔ dot | ||
✔ cross | ||
✔ unit | ||
✔ normalize | ||
✔ scale | ||
✔ xyDistanceTo | ||
✔ xzDistanceTo | ||
✔ yzDistanceTo | ||
✔ innerProduct | ||
✔ manhattanDistanceTo | ||
✔ toArray | ||
39 passing | ||
50 passing (14ms) | ||
``` | ||
@@ -83,0 +89,0 @@ |
@@ -20,2 +20,8 @@ import { expectType } from "tsd"; | ||
expectType<boolean>(vec.isZero()); | ||
expectType<number>(vec.at(1)); | ||
expectType<[number, number]>(vec.xz()); | ||
expectType<[number, number]>(vec.xy()); | ||
expectType<[number, number]>(vec.yz()); | ||
expectType<Vec3>(vec.xzy()); | ||
expectType<Vec3>(vec.set(4, 5, 6)); | ||
@@ -22,0 +28,0 @@ expectType<Vec3>(vec.update(vec)); |
@@ -55,2 +55,39 @@ /* eslint-env mocha */ | ||
describe('vec3', function () { | ||
it('isZero', function () { | ||
const v1 = new Vec3(0, 1, 2) | ||
const v2 = new Vec3(0, 0, 0) | ||
assert.ok(!v1.isZero()) | ||
assert.ok(v2.isZero()) | ||
}) | ||
it('at', function () { | ||
const v1 = new Vec3(0, 1, 2) | ||
assert.strictEqual(v1.at(0), 0) | ||
assert.strictEqual(v1.at(1), 1) | ||
assert.strictEqual(v1.at(2), 2) | ||
}) | ||
it('xz', function () { | ||
const v1 = new Vec3(0, 1, 2) | ||
const a = v1.xz() | ||
assert.strictEqual(a[0], 0) | ||
assert.strictEqual(a[1], 2) | ||
}) | ||
it('xy', function () { | ||
const v1 = new Vec3(0, 1, 2) | ||
const a = v1.xy() | ||
assert.strictEqual(a[0], 0) | ||
assert.strictEqual(a[1], 1) | ||
}) | ||
it('yz', function () { | ||
const v1 = new Vec3(0, 1, 2) | ||
const a = v1.yz() | ||
assert.strictEqual(a[0], 1) | ||
assert.strictEqual(a[1], 2) | ||
}) | ||
it('xzy', function () { | ||
const v1 = new Vec3(0, 1, 2) | ||
const v2 = v1.xzy() | ||
assert.strictEqual(v2.x, 0) | ||
assert.strictEqual(v2.y, 2) | ||
assert.strictEqual(v2.z, 1) | ||
}) | ||
it('rounded', function () { | ||
@@ -172,2 +209,6 @@ const v1 = new Vec3(1.1, -1.5, 1.9) | ||
assert.ok(v2.equals(v3)) | ||
const v4 = new Vec3(0.1, 0, 0) | ||
const v5 = new Vec3(0.2, 0, 0) | ||
const v6 = new Vec3(0.3, 0, 0) | ||
assert.ok(v4.plus(v5).equals(v6, Number.EPSILON)) | ||
}) | ||
@@ -174,0 +215,0 @@ it('toString', function () { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34076
13
886
94