Comparing version 0.1.7 to 0.1.8
@@ -0,1 +1,6 @@ | ||
## 0.1.8 | ||
* fix some typescript stuff | ||
* new methods: rounded, round, multiply, and divide | ||
## 0.1.7 | ||
@@ -2,0 +7,0 @@ * fix standard not being a dev dependency |
206
index.d.ts
export class Vec3 { | ||
constructor(x: number, y: number, z: number); | ||
constructor(x: number, y: number, z: number); | ||
x: number; | ||
y: number; | ||
z: number; | ||
x: number; | ||
y: number; | ||
z: number; | ||
set(x: number, y: number, z: number): this; | ||
/** | ||
* Set own values to given x y z | ||
*/ | ||
set(x: number, y: number, z: number): this; | ||
update(other: Vec3): this; | ||
/** | ||
* Set own values to values given by other | ||
*/ | ||
update(other: Vec3): this; | ||
floored(): Vec3; | ||
/** | ||
* Return a new instance with copied values that are rounded | ||
*/ | ||
rounded(): Vec3; | ||
floor(): this; | ||
/** | ||
* Round own values to nearest integer | ||
*/ | ||
round(): this; | ||
offset(dx: number, dy: number, dz: number): Vec3; | ||
/** | ||
* Return a new instance with copied values that are floored | ||
*/ | ||
floored(): Vec3; | ||
translate(dx: number, dy: number, dz: number): this; | ||
/** | ||
* Floor own values | ||
*/ | ||
floor(): this; | ||
add(other: Vec3): this; | ||
/** | ||
* Return a new instance with copied values that are offset by dx dy and dz | ||
*/ | ||
offset(dx: number, dy: number, dz: number): Vec3; | ||
subtract(other: Vec3): this; | ||
/** | ||
* Translate own values by dx dy and dz | ||
*/ | ||
translate(dx: number, dy: number, dz: number): this; | ||
plus(other: Vec3): Vec3; | ||
/** | ||
* Add to own values by vector | ||
*/ | ||
add(other: Vec3): this; | ||
minus(other: Vec3): Vec3; | ||
/** | ||
* Subtract own values by vector | ||
*/ | ||
subtract(other: Vec3): this; | ||
scaled(scalar: number): Vec3; | ||
/** | ||
* Multiply own values by value from vector | ||
*/ | ||
multiply(other: Vec3): this; | ||
abs(): Vec3; | ||
/** | ||
* Divide own values by value from vector | ||
*/ | ||
divide(other: Vec3): this; | ||
volume(): number; | ||
/** | ||
* Return a new instance with copied values that are added to by vector | ||
*/ | ||
plus(other: Vec3): Vec3; | ||
modulus(other: Vec3): Vec3; | ||
/** | ||
* Return a new instance with copied values that are subtracted by vector | ||
*/ | ||
minus(other: Vec3): Vec3; | ||
distanceTo(other: Vec3): number; | ||
/** | ||
* Return a new instance with copied values that are scaled by number | ||
*/ | ||
scaled(scalar: number): Vec3; | ||
distanceSquared(other: Vec3): number; | ||
/** | ||
* Return a new instance with copied values that are absolute | ||
*/ | ||
abs(): Vec3; | ||
equals(other: Vec3): boolean; | ||
/** | ||
* Return the volume off the vector | ||
*/ | ||
volume(): number; | ||
toString(): string; | ||
/** | ||
* Return a new instance with copied values that are modulated by value from a vector | ||
*/ | ||
modulus(other: Vec3): Vec3; | ||
clone(): Vec3; | ||
/** | ||
* Return the euclidean distance to another vector | ||
*/ | ||
distanceTo(other: Vec3): number; | ||
min(other: Vec3): Vec3; | ||
/** | ||
* Return the squared euclidean distance to another vector | ||
*/ | ||
distanceSquared(other: Vec3): number; | ||
max(other: Vec3): Vec3; | ||
/** | ||
* Returns true when all values match with the values off the other vector | ||
*/ | ||
equals(other: Vec3): boolean; | ||
dot(other: Vec3): number; | ||
/** | ||
* Converts own values to a string representation in the format `(x, y, z)` | ||
*/ | ||
toString(): string; | ||
cross(other: Vec3): Vec3; | ||
/** | ||
* Return a new instance with the same values | ||
*/ | ||
clone(): Vec3; | ||
norm(): number; | ||
/** | ||
* Return a new instance with the min values by value compared to another vector | ||
*/ | ||
min(other: Vec3): Vec3; | ||
unit(): Vec3; | ||
/** | ||
* Return a new instance with the max values by value compared to another vector | ||
*/ | ||
max(other: Vec3): Vec3; | ||
normalize(): Vec3; | ||
/** | ||
* Returns its own euclidean norm | ||
*/ | ||
norm(): number; | ||
scale(scalar: number): this; | ||
/** | ||
* Returns the dot product with another vector | ||
*/ | ||
dot(other: Vec3): number; | ||
xyDistanceTo(other: Vec3): number; | ||
/** | ||
* Returns a new instance off the cross product to another vector | ||
*/ | ||
cross(other: Vec3): Vec3; | ||
xzDistanceTo(other: Vec3): number; | ||
/** | ||
* Returns a new instance with copied values normed to the unit vector | ||
*/ | ||
unit(): Vec3; | ||
yzDistanceTo(other: Vec3): number; | ||
/** | ||
* Normalize own values | ||
*/ | ||
normalize(): Vec3; | ||
innerProduct(other: Vec3): number; | ||
/** | ||
* Scale own values by a number | ||
*/ | ||
scale(scalar: number): this; | ||
manhattanDistanceTo(other: Vec3): number; | ||
/** | ||
* Returns the xy distance to another vector | ||
*/ | ||
xyDistanceTo(other: Vec3): number; | ||
toArray(): Array<number>; | ||
/** | ||
* Returns the xz distance to another vector | ||
*/ | ||
xzDistanceTo(other: Vec3): number; | ||
/** | ||
* Returns the yz distance to another vector | ||
*/ | ||
yzDistanceTo(other: Vec3): number; | ||
/** | ||
* Returns the inner product to another vector | ||
*/ | ||
innerProduct(other: Vec3): number; | ||
/** | ||
* Returns the manhattan distance to another vector | ||
*/ | ||
manhattanDistanceTo(other: Vec3): number; | ||
/** | ||
* Returns an array with x y z in array form ie [x, y, z] | ||
*/ | ||
toArray(): [number, number, number]; | ||
} | ||
export default function v( | ||
x: null | Array<number | string> | {x: number | string, y: number | string, z: number | string} | string, | ||
y?: number | string, | ||
z?: number | string | ||
coordinates: | ||
| null | ||
| string | ||
| [number | string, number | string, number | string] | ||
| { x: number | string; y: number | string; z: number | string } | ||
): Vec3; | ||
export default function v( | ||
x: number | string, | ||
y: number | string, | ||
z: number | string | ||
): Vec3; |
65
index.js
@@ -24,2 +24,13 @@ const re = /\((-?[.\d]+), (-?[.\d]+), (-?[.\d]+)\)/ | ||
rounded () { | ||
return new Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z)) | ||
} | ||
round () { | ||
this.x = Math.round(this.x) | ||
this.y = Math.round(this.y) | ||
this.z = Math.round(this.z) | ||
return this | ||
} | ||
floored () { | ||
@@ -61,2 +72,16 @@ return new Vec3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z)) | ||
multiply (other) { | ||
this.x *= other.x | ||
this.y *= other.y | ||
this.z *= other.z | ||
return this | ||
} | ||
divide (other) { | ||
this.x /= other.x | ||
this.y /= other.y | ||
this.z /= other.z | ||
return this | ||
} | ||
plus (other) { | ||
@@ -90,5 +115,5 @@ return this.offset(other.x, other.y, other.z) | ||
distanceTo (other) { | ||
var dx = other.x - this.x | ||
var dy = other.y - this.y | ||
var dz = other.z - this.z | ||
const dx = other.x - this.x | ||
const dy = other.y - this.y | ||
const dz = other.z - this.z | ||
return Math.sqrt(dx * dx + dy * dy + dz * dz) | ||
@@ -98,5 +123,5 @@ } | ||
distanceSquared (other) { | ||
var dx = other.x - this.x | ||
var dy = other.y - this.y | ||
var dz = other.z - this.z | ||
const dx = other.x - this.x | ||
const dy = other.y - this.y | ||
const dz = other.z - this.z | ||
return dx * dx + dy * dy + dz * dz | ||
@@ -164,4 +189,4 @@ } | ||
xyDistanceTo (other) { | ||
var dx = other.x - this.x | ||
var dy = other.y - this.y | ||
const dx = other.x - this.x | ||
const dy = other.y - this.y | ||
return Math.sqrt(dx * dx + dy * dy) | ||
@@ -171,4 +196,4 @@ } | ||
xzDistanceTo (other) { | ||
var dx = other.x - this.x | ||
var dz = other.z - this.z | ||
const dx = other.x - this.x | ||
const dz = other.z - this.z | ||
return Math.sqrt(dx * dx + dz * dz) | ||
@@ -178,4 +203,4 @@ } | ||
yzDistanceTo (other) { | ||
var dy = other.y - this.y | ||
var dz = other.z - this.z | ||
const dy = other.y - this.y | ||
const dz = other.z - this.z | ||
return Math.sqrt(dy * dy + dz * dz) | ||
@@ -201,12 +226,12 @@ } | ||
} else if (Array.isArray(x)) { | ||
return new Vec3(parseFloat(x[0], 10), parseFloat(x[1], 10), parseFloat(x[2], 10)) | ||
return new Vec3(parseFloat(x[0]), parseFloat(x[1]), parseFloat(x[2])) | ||
} else if (typeof x === 'object') { | ||
return new Vec3(parseFloat(x.x, 10), parseFloat(x.y, 10), parseFloat(x.z, 10)) | ||
return new Vec3(parseFloat(x.x), parseFloat(x.y), parseFloat(x.z)) | ||
} else if (typeof x === 'string' && y == null) { | ||
var match = x.match(re) | ||
const match = x.match(re) | ||
if (match) { | ||
return new Vec3( | ||
parseFloat(match[1], 10), | ||
parseFloat(match[2], 10), | ||
parseFloat(match[3], 10)) | ||
parseFloat(match[1]), | ||
parseFloat(match[2]), | ||
parseFloat(match[3])) | ||
} else { | ||
@@ -216,3 +241,3 @@ throw new Error('vec3: cannot parse: ' + x) | ||
} else { | ||
return new Vec3(parseFloat(x, 10), parseFloat(y, 10), parseFloat(z, 10)) | ||
return new Vec3(parseFloat(x), parseFloat(y), parseFloat(z)) | ||
} | ||
@@ -222,3 +247,3 @@ } | ||
function euclideanMod (numerator, denominator) { | ||
var result = numerator % denominator | ||
const result = numerator % denominator | ||
return result < 0 ? result + denominator : result | ||
@@ -225,0 +250,0 @@ } |
{ | ||
"name": "vec3", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "3d vector math with good unit tests", | ||
@@ -8,3 +8,5 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "mocha --reporter spec", | ||
"test": "npm run test-js && npm run test-types", | ||
"test-js": "mocha --reporter spec", | ||
"test-types": "tsd", | ||
"pretest": "npm run lint", | ||
@@ -17,10 +19,21 @@ "lint": "standard", | ||
], | ||
"exports": { | ||
"require": "./index.js", | ||
"import": "./wrapper.mjs" | ||
}, | ||
"author": "Andrew Kelley", | ||
"license": "BSD", | ||
"devDependencies": { | ||
"mocha": "^7.2.0", | ||
"standard": "^14.3.4" | ||
"mocha": "^10.0.0", | ||
"standard": "^17.0.0", | ||
"tsd": "^0.25.0" | ||
}, | ||
"dependencies": { | ||
"dependencies": {}, | ||
"tsd": { | ||
"directory": "test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/PrismarineJS/node-vec3.git" | ||
} | ||
} |
@@ -42,2 +42,4 @@ # vec3 | ||
vec3 | ||
✓ rounded | ||
✓ round | ||
✓ floored | ||
@@ -57,2 +59,4 @@ ✓ floor | ||
✓ subtract | ||
✓ multiply | ||
✓ divide | ||
✓ set | ||
@@ -85,2 +89,2 @@ ✓ modulus | ||
See [History](History.md) | ||
See [History](HISTORY.md) |
260
test/test.js
/* eslint-env mocha */ | ||
var v = require('../') | ||
var Vec3 = v.Vec3 | ||
var assert = require('assert') | ||
const v = require('../') | ||
const Vec3 = v.Vec3 | ||
const assert = require('assert') | ||
describe('v()', function () { | ||
it('no args', function () { | ||
var v1 = v() | ||
const v1 = v() | ||
assert.strictEqual(v1.x, 0) | ||
@@ -15,3 +15,3 @@ assert.strictEqual(v1.y, 0) | ||
it('x, y, z', function () { | ||
var v1 = v(-1, 5, 10.10) | ||
const v1 = v(-1, 5, 10.10) | ||
assert.strictEqual(v1.x, -1) | ||
@@ -22,3 +22,3 @@ assert.strictEqual(v1.y, 5) | ||
it('array', function () { | ||
var v1 = v([4, 5, 6]) | ||
const v1 = v([4, 5, 6]) | ||
assert.strictEqual(v1.x, 4) | ||
@@ -29,3 +29,3 @@ assert.strictEqual(v1.y, 5) | ||
it('object', function () { | ||
var v1 = v({ x: 9, y: 8, z: 7 }) | ||
const v1 = v({ x: 9, y: 8, z: 7 }) | ||
assert.strictEqual(v1.x, 9) | ||
@@ -36,3 +36,3 @@ assert.strictEqual(v1.y, 8) | ||
it('string coords', function () { | ||
var v1 = v('1', '1.5', '-30.2') | ||
const v1 = v('1', '1.5', '-30.2') | ||
assert.strictEqual(v1.x, 1) | ||
@@ -43,10 +43,10 @@ assert.strictEqual(v1.y, 1.5) | ||
it('deserialize', function () { | ||
var v1 = v(v(1, -3.5, 0).toString()) | ||
const v1 = v(v(1, -3.5, 0).toString()) | ||
assert.strictEqual(v1.x, 1) | ||
assert.strictEqual(v1.y, -3.5) | ||
assert.strictEqual(v1.z, 0) | ||
var v2 = v(v(-111, 222, 9876543210.123456789).toString()) | ||
const v2 = v(v(-111, 222, 9876543210.12345).toString()) | ||
assert.strictEqual(v2.x, -111) | ||
assert.strictEqual(v2.y, 222) | ||
assert.strictEqual(v2.z, 9876543210.123456789) | ||
assert.strictEqual(v2.z, 9876543210.12345) | ||
}) | ||
@@ -60,5 +60,21 @@ it('invalid deserialize', function () { | ||
describe('vec3', function () { | ||
it('rounded', function () { | ||
const v1 = new Vec3(1.1, -1.5, 1.9) | ||
const v2 = v1.rounded() | ||
v1.x = 10 | ||
assert.strictEqual(v2.x, 1) | ||
assert.strictEqual(v2.y, -1) | ||
assert.strictEqual(v2.z, 2) | ||
}) | ||
it('round', function () { | ||
const v1 = new Vec3(1.1, -1.5, 1.9) | ||
const v2 = v1.round() | ||
assert.strictEqual(v2, v1) | ||
assert.strictEqual(v1.x, 1) | ||
assert.strictEqual(v1.y, -1) | ||
assert.strictEqual(v1.z, 2) | ||
}) | ||
it('floored', function () { | ||
var v1 = new Vec3(1.1, -1.5, 1.9) | ||
var v2 = v1.floored() | ||
const v1 = new Vec3(1.1, -1.5, 1.9) | ||
const v2 = v1.floored() | ||
v1.x = 10 | ||
@@ -70,4 +86,4 @@ assert.strictEqual(v2.x, 1) | ||
it('floor', function () { | ||
var v1 = new Vec3(1.1, -1.5, 1.9) | ||
var v2 = v1.floor() | ||
const v1 = new Vec3(1.1, -1.5, 1.9) | ||
const v2 = v1.floor() | ||
assert.strictEqual(v2, v1) | ||
@@ -79,4 +95,4 @@ assert.strictEqual(v1.x, 1) | ||
it('offset', function () { | ||
var v1 = new Vec3(1, 2, 3) | ||
var v2 = v1.offset(10, -10, 20) | ||
const v1 = new Vec3(1, 2, 3) | ||
const v2 = v1.offset(10, -10, 20) | ||
v1.x = -100 | ||
@@ -88,3 +104,3 @@ assert.strictEqual(v2.x, 11) | ||
it('translate', function () { | ||
var v1 = new Vec3(1, 2, 3) | ||
const v1 = new Vec3(1, 2, 3) | ||
v1.translate(10, -10, 20) | ||
@@ -96,5 +112,5 @@ assert.strictEqual(v1.x, 11) | ||
it('plus', function () { | ||
var v1 = new Vec3(1, 2, 3) | ||
var v2 = new Vec3(-1, 0, 1) | ||
var v3 = v1.plus(v2) | ||
const v1 = new Vec3(1, 2, 3) | ||
const v2 = new Vec3(-1, 0, 1) | ||
const v3 = v1.plus(v2) | ||
assert.strictEqual(v1.x, 1) | ||
@@ -111,5 +127,5 @@ assert.strictEqual(v1.y, 2) | ||
it('minus', function () { | ||
var v1 = new Vec3(1, 2, 3) | ||
var v2 = new Vec3(-1, 0, 1) | ||
var v3 = v1.minus(v2) | ||
const v1 = new Vec3(1, 2, 3) | ||
const v2 = new Vec3(-1, 0, 1) | ||
const v3 = v1.minus(v2) | ||
assert.strictEqual(v1.x, 1) | ||
@@ -126,4 +142,4 @@ assert.strictEqual(v1.y, 2) | ||
it('scaled', function () { | ||
var v1 = new Vec3(1, 2, 3) | ||
var v2 = v1.scaled(2) | ||
const v1 = new Vec3(1, 2, 3) | ||
const v2 = v1.scaled(2) | ||
assert.strictEqual(v1.x, 1) | ||
@@ -137,4 +153,4 @@ assert.strictEqual(v1.y, 2) | ||
it('abs', function () { | ||
var v1 = new Vec3(1.1, -1.5, 1.9) | ||
var v2 = v1.abs() | ||
const v1 = new Vec3(1.1, -1.5, 1.9) | ||
const v2 = v1.abs() | ||
v1.x = 10 | ||
@@ -146,7 +162,7 @@ assert.strictEqual(v2.x, 1.1) | ||
it('distanceTo', function () { | ||
var v1 = new Vec3(1, 1, 1) | ||
var v2 = new Vec3(2, 2, 2) | ||
var dist1 = v1.distanceTo(v2) | ||
var dist2 = v2.distanceTo(v1) | ||
var expected = 1.7320508075688772 | ||
const v1 = new Vec3(1, 1, 1) | ||
const v2 = new Vec3(2, 2, 2) | ||
const dist1 = v1.distanceTo(v2) | ||
const dist2 = v2.distanceTo(v1) | ||
const expected = 1.7320508075688772 | ||
assert.strictEqual(dist1, dist2) | ||
@@ -156,7 +172,7 @@ assert.strictEqual(Math.round(dist1 * 100000), Math.round(expected * 100000)) | ||
it('distanceSquared', function () { | ||
var v1 = new Vec3(1, 1, 1) | ||
var v2 = new Vec3(2, 2, 2) | ||
var dist1 = v1.distanceSquared(v2) | ||
var dist2 = v2.distanceSquared(v1) | ||
var expected = 3 | ||
const v1 = new Vec3(1, 1, 1) | ||
const v2 = new Vec3(2, 2, 2) | ||
const dist1 = v1.distanceSquared(v2) | ||
const dist2 = v2.distanceSquared(v1) | ||
const expected = 3 | ||
assert.strictEqual(dist1, dist2) | ||
@@ -166,14 +182,14 @@ assert.strictEqual(Math.round(dist1 * 100000), Math.round(expected * 100000)) | ||
it('equals', function () { | ||
var v1 = new Vec3(1, 2, 3) | ||
var v2 = v1.scaled(0.23424) | ||
var v3 = v1.scaled(0.23424) | ||
const v1 = new Vec3(1, 2, 3) | ||
const v2 = v1.scaled(0.23424) | ||
const v3 = v1.scaled(0.23424) | ||
assert.ok(v2.equals(v3)) | ||
}) | ||
it('toString', function () { | ||
var v1 = new Vec3(1, -1, 3.14) | ||
const v1 = new Vec3(1, -1, 3.14) | ||
assert.strictEqual(v1.toString(), '(1, -1, 3.14)') | ||
}) | ||
it('clone', function () { | ||
var v1 = new Vec3(1, 2, 3) | ||
var v2 = v1.clone() | ||
const v1 = new Vec3(1, 2, 3) | ||
const v2 = v1.clone() | ||
v2.x = 10 | ||
@@ -188,5 +204,5 @@ assert.strictEqual(v1.x, 1) | ||
it('add', function () { | ||
var v1 = new Vec3(1, 2, 3) | ||
var v2 = new Vec3(-1, -2, -3) | ||
var v3 = v1.add(v2) | ||
const v1 = new Vec3(1, 2, 3) | ||
const v2 = new Vec3(-1, -2, -3) | ||
const v3 = v1.add(v2) | ||
assert.strictEqual(v3, v1) | ||
@@ -198,5 +214,5 @@ assert.strictEqual(v1.x, 0) | ||
it('subtract', function () { | ||
var v1 = new Vec3(1, 2, 3) | ||
var v2 = new Vec3(-1, -2, -3) | ||
var v3 = v1.subtract(v2) | ||
const v1 = new Vec3(1, 2, 3) | ||
const v2 = new Vec3(-1, -2, -3) | ||
const v3 = v1.subtract(v2) | ||
assert.strictEqual(v3, v1) | ||
@@ -207,5 +223,23 @@ assert.strictEqual(v1.x, 2) | ||
}) | ||
it('multiply', function () { | ||
const v1 = new Vec3(1, 2, 3) | ||
const v2 = new Vec3(-1, -2, -5) | ||
const v3 = v1.multiply(v2) | ||
assert.strictEqual(v3, v1) | ||
assert.strictEqual(v1.x, -1) | ||
assert.strictEqual(v1.y, -4) | ||
assert.strictEqual(v1.z, -15) | ||
}) | ||
it('divide', function () { | ||
const v1 = new Vec3(10, 20, 30) | ||
const v2 = new Vec3(2, 5, 3) | ||
const v3 = v1.divide(v2) | ||
assert.strictEqual(v3, v1) | ||
assert.strictEqual(v1.x, 5) | ||
assert.strictEqual(v1.y, 4) | ||
assert.strictEqual(v1.z, 10) | ||
}) | ||
it('set', function () { | ||
var v1 = new Vec3(12, 32, 46) | ||
var v2 = v1.set(0, 10, 100) | ||
const v1 = new Vec3(12, 32, 46) | ||
const v2 = v1.set(0, 10, 100) | ||
assert.strictEqual(v1, v2) | ||
@@ -217,5 +251,5 @@ assert.strictEqual(v1.x, 0) | ||
it('modulus', function () { | ||
var v1 = new Vec3(12, 32, -1) | ||
var v2 = new Vec3(14, 32, 16) | ||
var v3 = v1.modulus(v2) | ||
const v1 = new Vec3(12, 32, -1) | ||
const v2 = new Vec3(14, 32, 16) | ||
const v3 = v1.modulus(v2) | ||
assert.strictEqual(v1.x, 12) | ||
@@ -232,9 +266,9 @@ assert.strictEqual(v1.y, 32) | ||
it('volume', function () { | ||
var v1 = new Vec3(3, 4, 5) | ||
const v1 = new Vec3(3, 4, 5) | ||
assert.strictEqual(v1.volume(), 60) | ||
}) | ||
it('min', function () { | ||
var v1 = new Vec3(-1, 0, 1) | ||
var v2 = new Vec3(10, -10, 1.1) | ||
var v3 = v1.min(v2) | ||
const v1 = new Vec3(-1, 0, 1) | ||
const v2 = new Vec3(10, -10, 1.1) | ||
const v3 = v1.min(v2) | ||
assert.strictEqual(v3.x, -1) | ||
@@ -245,5 +279,5 @@ assert.strictEqual(v3.y, -10) | ||
it('max', function () { | ||
var v1 = new Vec3(-1, 0, 1) | ||
var v2 = new Vec3(10, -10, 1.1) | ||
var v3 = v1.max(v2) | ||
const v1 = new Vec3(-1, 0, 1) | ||
const v2 = new Vec3(10, -10, 1.1) | ||
const v3 = v1.max(v2) | ||
assert.strictEqual(v3.x, 10) | ||
@@ -254,5 +288,5 @@ assert.strictEqual(v3.y, 0) | ||
it('update', function () { | ||
var v1 = new Vec3(-1, 0, 1) | ||
var v2 = new Vec3(10, -10, 1.1) | ||
var v3 = v1.update(v2) | ||
const v1 = new Vec3(-1, 0, 1) | ||
const v2 = new Vec3(10, -10, 1.1) | ||
const v3 = v1.update(v2) | ||
assert.strictEqual(v3, v1) | ||
@@ -267,24 +301,24 @@ assert.strictEqual(v1.x, 10) | ||
it('norm', function () { | ||
var v1 = new Vec3(-10, 0, 10) | ||
assert.strictEqual(Math.round(v1.norm() * 100000), Math.round(14.142135623730950 * 100000)) | ||
const v1 = new Vec3(-10, 0, 10) | ||
assert.strictEqual(Math.round(v1.norm() * 100000), Math.round(14.1421356237 * 100000)) | ||
}) | ||
it('dot', function () { | ||
var v1 = new Vec3(-1, -1, -1) | ||
var v2 = new Vec3(1, 1, 1) | ||
const v1 = new Vec3(-1, -1, -1) | ||
const v2 = new Vec3(1, 1, 1) | ||
assert.strictEqual(v1.dot(v2), -3) | ||
}) | ||
it('cross', function () { | ||
var v1 = new Vec3(1, 0, 0) | ||
var v2 = new Vec3(0, 1, 0) | ||
var v3 = new Vec3(0, 0, 1) | ||
const v1 = new Vec3(1, 0, 0) | ||
const v2 = new Vec3(0, 1, 0) | ||
const v3 = new Vec3(0, 0, 1) | ||
assert.ok(v1.cross(v2).equals(v3)) | ||
}) | ||
it('unit', function () { | ||
var v1 = new Vec3(10, -10, 1.1) | ||
var v2 = v1.unit() | ||
assert.strictEqual(Math.round(v2.x * 100000), Math.round(0.7049774402016568 * 100000)) | ||
assert.strictEqual(Math.round(v2.y * 100000), Math.round(-0.704977440201656 * 100000)) | ||
assert.strictEqual(Math.round(v2.z * 100000), Math.round(0.07754751842218225 * 100000)) | ||
var v3 = new Vec3(0, 0, 0) | ||
var v4 = v3.unit() | ||
const v1 = new Vec3(10, -10, 1.1) | ||
const v2 = v1.unit() | ||
assert.strictEqual(Math.round(v2.x * 100000), Math.round(0.70497744020 * 100000)) | ||
assert.strictEqual(Math.round(v2.y * 100000), Math.round(-0.7049774402 * 100000)) | ||
assert.strictEqual(Math.round(v2.z * 100000), Math.round(0.07754751842 * 100000)) | ||
const v3 = new Vec3(0, 0, 0) | ||
const v4 = v3.unit() | ||
assert.strictEqual(v4.x, 0) | ||
@@ -295,9 +329,9 @@ assert.strictEqual(v4.y, 0) | ||
it('normalize', function () { | ||
var v1 = new Vec3(10, -10, 1.1) | ||
var v2 = v1.normalize() | ||
assert.strictEqual(Math.round(v2.x * 100000), Math.round(0.7049774402016568 * 100000)) | ||
assert.strictEqual(Math.round(v2.y * 100000), Math.round(-0.704977440201656 * 100000)) | ||
assert.strictEqual(Math.round(v2.z * 100000), Math.round(0.07754751842218225 * 100000)) | ||
var v3 = new Vec3(0, 0, 0) | ||
var v4 = v3.normalize() | ||
const v1 = new Vec3(10, -10, 1.1) | ||
const v2 = v1.normalize() | ||
assert.strictEqual(Math.round(v2.x * 100000), Math.round(0.70497744020 * 100000)) | ||
assert.strictEqual(Math.round(v2.y * 100000), Math.round(-0.7049774402 * 100000)) | ||
assert.strictEqual(Math.round(v2.z * 100000), Math.round(0.07754751842 * 100000)) | ||
const v3 = new Vec3(0, 0, 0) | ||
const v4 = v3.normalize() | ||
assert.strictEqual(v4.x, 0) | ||
@@ -308,4 +342,4 @@ assert.strictEqual(v4.y, 0) | ||
it('scale', function () { | ||
var v1 = new Vec3(10, -10, 1.1) | ||
var v2 = v1.scale(1.5) | ||
const v1 = new Vec3(10, -10, 1.1) | ||
const v2 = v1.scale(1.5) | ||
assert.strictEqual(v2.x, 15) | ||
@@ -316,7 +350,7 @@ assert.strictEqual(v2.y, -15) | ||
it('xyDistanceTo', function () { | ||
var v1 = new Vec3(1, 1, 1) | ||
var v2 = new Vec3(2, 2, 2) | ||
var dist1 = v1.xyDistanceTo(v2) | ||
var dist2 = v2.xyDistanceTo(v1) | ||
var expected = 1.4142135623730950 | ||
const v1 = new Vec3(1, 1, 1) | ||
const v2 = new Vec3(2, 2, 2) | ||
const dist1 = v1.xyDistanceTo(v2) | ||
const dist2 = v2.xyDistanceTo(v1) | ||
const expected = 1.414213562 | ||
assert.strictEqual(dist1, dist2) | ||
@@ -326,7 +360,7 @@ assert.strictEqual(Math.round(dist1 * 100000), Math.round(expected * 100000)) | ||
it('xzDistanceTo', function () { | ||
var v1 = new Vec3(1, 1, 1) | ||
var v2 = new Vec3(2, 2, 2) | ||
var dist1 = v1.xzDistanceTo(v2) | ||
var dist2 = v2.xzDistanceTo(v1) | ||
var expected = 1.4142135623730950 | ||
const v1 = new Vec3(1, 1, 1) | ||
const v2 = new Vec3(2, 2, 2) | ||
const dist1 = v1.xzDistanceTo(v2) | ||
const dist2 = v2.xzDistanceTo(v1) | ||
const expected = 1.41421356237 | ||
assert.strictEqual(dist1, dist2) | ||
@@ -336,7 +370,7 @@ assert.strictEqual(Math.round(dist1 * 100000), Math.round(expected * 100000)) | ||
it('yzDistanceTo', function () { | ||
var v1 = new Vec3(1, 1, 1) | ||
var v2 = new Vec3(2, 2, 2) | ||
var dist1 = v1.yzDistanceTo(v2) | ||
var dist2 = v2.yzDistanceTo(v1) | ||
var expected = 1.4142135623730950 | ||
const v1 = new Vec3(1, 1, 1) | ||
const v2 = new Vec3(2, 2, 2) | ||
const dist1 = v1.yzDistanceTo(v2) | ||
const dist2 = v2.yzDistanceTo(v1) | ||
const expected = 1.41421356237 | ||
assert.strictEqual(dist1, dist2) | ||
@@ -346,6 +380,6 @@ assert.strictEqual(Math.round(dist1 * 100000), Math.round(expected * 100000)) | ||
it('innerProduct', function () { | ||
var v1 = new Vec3(-1, 0, 1) | ||
var v2 = new Vec3(0, 1, 0) | ||
var ip1 = v1.innerProduct(v2) | ||
var ip2 = v2.innerProduct(v1) | ||
const v1 = new Vec3(-1, 0, 1) | ||
const v2 = new Vec3(0, 1, 0) | ||
const ip1 = v1.innerProduct(v2) | ||
const ip2 = v2.innerProduct(v1) | ||
assert.strictEqual(ip1, ip2) | ||
@@ -355,6 +389,6 @@ assert.strictEqual(ip1, 0) | ||
it('manhattanDistanceTo', function () { | ||
var v1 = new Vec3(-1, 0, 1) | ||
var v2 = new Vec3(10, -10, 1.1) | ||
var dist1 = v1.manhattanDistanceTo(v2) | ||
var dist2 = v2.manhattanDistanceTo(v1) | ||
const v1 = new Vec3(-1, 0, 1) | ||
const v2 = new Vec3(10, -10, 1.1) | ||
const dist1 = v1.manhattanDistanceTo(v2) | ||
const dist2 = v2.manhattanDistanceTo(v1) | ||
assert.strictEqual(dist1, dist2) | ||
@@ -364,4 +398,4 @@ assert.strictEqual(dist1, 21.1) | ||
it('toArray', function () { | ||
var v1 = new Vec3(1, -1, 3.14) | ||
var array = v1.toArray() | ||
const v1 = new Vec3(1, -1, 3.14) | ||
const array = v1.toArray() | ||
assert.strictEqual(v1.x, array[0]) | ||
@@ -368,0 +402,0 @@ assert.strictEqual(v1.y, array[1]) |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
30198
12
793
88
0
3