From 8406e5af269226c13b06f9466fda2e1d93df9648 Mon Sep 17 00:00:00 2001 From: Vladimir Bykov Date: Sat, 18 Nov 2017 14:18:41 +0300 Subject: [PATCH 1/8] Moved to tape --- README.md | 2 +- package.json | 17 +++++++++-------- test/addition.test.js | 8 +++++++- test/angle.test.js | 6 +++++- test/convertion.test.js | 14 ++++++++++++-- test/copy.test.js | 4 +++- test/creation.test.js | 7 ++++++- test/distance.test.js | 4 +++- test/division.test.js | 8 +++++++- test/dot-product.test.js | 4 +++- test/equality.test.js | 6 +++++- test/index.test.js | 26 ++++++++++++++++++++++++++ test/iterator.test.js | 5 +++-- test/lerp.test.js | 4 +++- test/magnitude.test.js | 4 +++- test/multiplication.test.js | 8 +++++++- test/normalization.test.js | 10 +++++++++- test/resetting.test.js | 15 ++++++++++++++- test/rotation.test.js | 8 +++++++- test/substraction.test.js | 8 +++++++- test/swizzling.test.js | 14 +++++++++++++- 21 files changed, 153 insertions(+), 29 deletions(-) create mode 100644 test/index.test.js diff --git a/README.md b/README.md index e4e6339..88f81d9 100644 --- a/README.md +++ b/README.md @@ -312,5 +312,5 @@ Command | Description `npm run check` | Check standard code style by [snazzy](https://www.npmjs.com/package/snazzy) `npm run build` | Wrap source code in [UMD](https://github.com/umdjs/umd) by [rollup](https://github.com/rollup/rollup) `npm run bench` | Run [benchmark](http://benchmarkjs.com/) -`npm run test` | Run tests by [ava](https://github.com/sindresorhus/ava) and compute code coverage by [nyc](https://github.com/bcoe/nyc) +`npm run test` | Run tests by [tape](https://github.com/substack/tape) and compute code coverage by [nyc](https://github.com/bcoe/nyc) `npm run min` | Minify code by [UglifyJS](https://github.com/mishoo/UglifyJS) diff --git a/package.json b/package.json index a19c554..b5ec98a 100644 --- a/package.json +++ b/package.json @@ -28,18 +28,19 @@ "main": "dist/vectory.umd.js", "module": "dist/vectory.js", "devDependencies": { - "ava": "0.22.0", "benchmark": "2.1.4", - "coveralls": "2.13.1", - "log-symbols": "2.0.0", + "coveralls": "3.0.0", + "log-symbols": "2.1.0", "minimist": "1.2.0", - "nyc": "11.1.0", - "rollup": "0.49.2", - "rollup-plugin-commonjs": "8.2.0", + "nyc": "11.3.0", + "rollup": "0.51.7", + "rollup-plugin-commonjs": "8.2.6", "rollup-plugin-node-resolve": "3.0.0", "snazzy": "7.0.0", "standard": "10.0.3", - "uglify-js": "3.0.28" + "tap-diff": "0.1.1", + "tape": "4.8.0", + "uglify-js": "3.1.9" }, "dependencies": { "number-epsilon": "1.0.3" @@ -52,7 +53,7 @@ "scripts": { "check": "standard src/*.js test/*.js bench/*.js bench/**/*.js | snazzy", "build": "rollup -c", - "test": "nyc --reporter=html --reporter=lcov --reporter=text ava", + "test": "nyc --reporter=html --reporter=lcov --reporter=text tape test/index.test.js", "bench": "node ./bench/index.js", "min": "uglifyjs dist/vectory.umd.js -c -m > dist/vectory.min.js", "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" diff --git a/test/addition.test.js b/test/addition.test.js index 66e3176..df54041 100644 --- a/test/addition.test.js +++ b/test/addition.test.js @@ -1,5 +1,5 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.add(one, another)` should return sum of two vectors', function (t) { var one = new Vector(1, 2) @@ -8,6 +8,7 @@ test('`Vector.add(one, another)` should return sum of two vectors', function (t) t.true(result instanceof Vector) t.is(result.x, 4) t.is(result.y, 6) + t.end() }) test('`Vector#add(vector)` should return sum of two vectors', function (t) { @@ -17,6 +18,7 @@ test('`Vector#add(vector)` should return sum of two vectors', function (t) { t.true(result instanceof Vector) t.is(result.x, 4) t.is(result.y, 6) + t.end() }) test('`Vector.iadd(one, another)` should add one vector to another', function (t) { @@ -25,6 +27,7 @@ test('`Vector.iadd(one, another)` should add one vector to another', function (t Vector.iadd(one, another) t.is(another.x, 4) t.is(another.y, 6) + t.end() }) test('`Vector.iadd(one, another)` should return another vector', function (t) { @@ -32,6 +35,7 @@ test('`Vector.iadd(one, another)` should return another vector', function (t) { var another = new Vector(3, 4) var result = Vector.iadd(one, another) t.is(result, another) + t.end() }) test('`Vector#iadd(vector)` should add vector to self', function (t) { @@ -40,6 +44,7 @@ test('`Vector#iadd(vector)` should add vector to self', function (t) { self.iadd(vector) t.is(self.x, 4) t.is(self.y, 6) + t.end() }) test('`Vector#iadd(vector)` should return self instance', function (t) { @@ -47,4 +52,5 @@ test('`Vector#iadd(vector)` should return self instance', function (t) { var vector = new Vector(3, 4) var result = self.iadd(vector) t.is(result, self) + t.end() }) diff --git a/test/angle.test.js b/test/angle.test.js index e43db81..a71c55f 100644 --- a/test/angle.test.js +++ b/test/angle.test.js @@ -1,16 +1,18 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.angleOf(vector)` should return the angle theta of vector', function (t) { var vector = new Vector(0, 1) var result = Vector.angleOf(vector) t.is(result * 180 / Math.PI, 90) + t.end() }) test('`Vector#angleOf()` should return the angle theta of vector', function (t) { var self = new Vector(0, 1) var result = self.angleOf() t.is(result * 180 / Math.PI, 90) + t.end() }) test('`Vector.angleTo(one, another)` should return the angle between vectors', function (t) { @@ -18,6 +20,7 @@ test('`Vector.angleTo(one, another)` should return the angle between vectors', f var another = new Vector(1, 0) var result = Vector.angleTo(one, another) t.is(result * 180 / Math.PI, 90) + t.end() }) test('`Vector#angleTo(vector)` should return the angle between vectors', function (t) { @@ -25,4 +28,5 @@ test('`Vector#angleTo(vector)` should return the angle between vectors', functio var vector = new Vector(1, 0) var result = self.angleTo(vector) t.is(result * 180 / Math.PI, 90) + t.end() }) diff --git a/test/convertion.test.js b/test/convertion.test.js index e710073..348ea0b 100644 --- a/test/convertion.test.js +++ b/test/convertion.test.js @@ -1,5 +1,5 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.toJSON(vector)` should convert passed vector to JSON', function (t) { var vector = new Vector(1, 2) @@ -8,6 +8,7 @@ test('`Vector.toJSON(vector)` should convert passed vector to JSON', function (t t.is(result.length, 2) t.is(result[0], 1) t.is(result[1], 2) + t.end() }) test('`Vector#toJSON()` should convert self to JSON', function (t) { @@ -17,22 +18,26 @@ test('`Vector#toJSON()` should convert self to JSON', function (t) { t.is(result.length, 2) t.is(result[0], 1) t.is(result[1], 2) + t.end() }) test('`Vector.toString(vector)` should convert to string passed vector', function (t) { var vector = new Vector(1, 2) var result = Vector.toString(vector) t.is(result, '1.000 2.000') + t.end() }) test('`Vector.toString(vector)` should call base .toString() if passed nothing', function (t) { t.is(Vector.toString(), Function.prototype.toString.call(Vector)) + t.end() }) test('`Vector#toString()` should convert self to JSON', function (t) { var self = new Vector(1, 2) var result = self.toString() t.is(result, '1.000 2.000') + t.end() }) if (typeof Symbol !== 'undefined' && Symbol.toStringTag && Vector.prototype[Symbol.toStringTag]) { @@ -40,9 +45,12 @@ if (typeof Symbol !== 'undefined' && Symbol.toStringTag && Vector.prototype[Symb var vector = new Vector(1, 2) var result = Object.prototype.toString.call(vector) t.is(result, '[object Vector]') + t.end() }) } else { - test.skip('`Vector.prototype[Symbol.toStringTag]` should specified [object ___] stringification', function (t) {}) + test.skip('`Vector.prototype[Symbol.toStringTag]` should specified [object ___] stringification', function (t) { + t.end() + }) } test('`Vector.toArray(vector)` should convert passed vector to array', function (t) { @@ -52,6 +60,7 @@ test('`Vector.toArray(vector)` should convert passed vector to array', function t.is(result.length, 2) t.is(result[0], 1) t.is(result[1], 2) + t.end() }) test('`Vector#toArray()` should convert self to array', function (t) { @@ -61,4 +70,5 @@ test('`Vector#toArray()` should convert self to array', function (t) { t.is(result.length, 2) t.is(result[0], 1) t.is(result[1], 2) + t.end() }) diff --git a/test/copy.test.js b/test/copy.test.js index 5fa3397..f16830e 100644 --- a/test/copy.test.js +++ b/test/copy.test.js @@ -1,5 +1,5 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.copy(vector)` should copy passed vector', function (t) { var vector = new Vector(1, 2) @@ -7,6 +7,7 @@ test('`Vector.copy(vector)` should copy passed vector', function (t) { t.true(result instanceof Vector) t.is(result.x, 1) t.is(result.y, 2) + t.end() }) test('`Vector#copy()` should copy self', function (t) { @@ -15,4 +16,5 @@ test('`Vector#copy()` should copy self', function (t) { t.true(result instanceof Vector) t.is(result.x, 1) t.is(result.y, 2) + t.end() }) diff --git a/test/creation.test.js b/test/creation.test.js index a818fc6..1a2e33c 100644 --- a/test/creation.test.js +++ b/test/creation.test.js @@ -1,11 +1,12 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`new Vector(x, y)` should create vector instance', function (t) { var vector = new Vector(1, 2) t.true(vector instanceof Vector) t.is(vector.x, 1) t.is(vector.y, 2) + t.end() }) test('`new Vector(x, y)` should create zero vector if args not passed', function (t) { @@ -13,6 +14,7 @@ test('`new Vector(x, y)` should create zero vector if args not passed', function t.true(vector instanceof Vector) t.is(vector.x, 0) t.is(vector.y, 0) + t.end() }) test('`Vector.from([x, y])` should return new vector from data', function (t) { @@ -20,6 +22,7 @@ test('`Vector.from([x, y])` should return new vector from data', function (t) { t.true(vector instanceof Vector) t.is(vector.x, 1) t.is(vector.y, 2) + t.end() }) test('`Vector.fromAngle(angle, magnitude)` should return new vector from angle and magnitude', function (t) { @@ -27,6 +30,7 @@ test('`Vector.fromAngle(angle, magnitude)` should return new vector from angle a t.true(vector instanceof Vector) t.is(Math.round(vector.x), 0) t.is(vector.y, 1) + t.end() }) test('`Vector.parse(string)` should return new vector from string', function (t) { @@ -49,4 +53,5 @@ test('`Vector.parse(string)` should return new vector from string', function (t) t.true(vector instanceof Vector) t.is(vector.x, 1.1) t.is(vector.y, 2.2) + t.end() }) diff --git a/test/distance.test.js b/test/distance.test.js index c78f613..6c54aae 100644 --- a/test/distance.test.js +++ b/test/distance.test.js @@ -1,11 +1,12 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.distance(one, another)` should return distance between vectors', function (t) { var one = new Vector(4, 3) var another = new Vector(8, 6) var distance = Vector.distance(one, another) t.is(distance, 5) + t.end() }) test('`Vector#distance(vector)` should return distance between vectors', function (t) { @@ -13,4 +14,5 @@ test('`Vector#distance(vector)` should return distance between vectors', functio var vector = new Vector(4, 3) var distance = self.distance(vector) t.is(distance, 5) + t.end() }) diff --git a/test/division.test.js b/test/division.test.js index 5b85b8e..826e54e 100644 --- a/test/division.test.js +++ b/test/division.test.js @@ -1,5 +1,5 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.div(scalar, vector)` should divide vector on scalar', function (t) { var vector = new Vector(4, 6) @@ -8,6 +8,7 @@ test('`Vector.div(scalar, vector)` should divide vector on scalar', function (t) t.true(result instanceof Vector) t.is(result.x, 2) t.is(result.y, 3) + t.end() }) test('`Vector#div(scalar)` should divide self on scalar', function (t) { @@ -17,6 +18,7 @@ test('`Vector#div(scalar)` should divide self on scalar', function (t) { t.true(result instanceof Vector) t.is(result.x, 2) t.is(result.y, 3) + t.end() }) test('`Vector.idiv(scalar, vector)` should divide vector on scalar', function (t) { @@ -25,6 +27,7 @@ test('`Vector.idiv(scalar, vector)` should divide vector on scalar', function (t Vector.idiv(scalar, vector) t.is(vector.x, 2) t.is(vector.y, 3) + t.end() }) test('`Vector.idiv(scalar, vector)` should return vector', function (t) { @@ -32,6 +35,7 @@ test('`Vector.idiv(scalar, vector)` should return vector', function (t) { var scalar = 2 var result = Vector.idiv(scalar, vector) t.is(result, vector) + t.end() }) test('`Vector#idiv(scalar)` should multiply self on scalar', function (t) { @@ -40,6 +44,7 @@ test('`Vector#idiv(scalar)` should multiply self on scalar', function (t) { vector.idiv(scalar) t.is(vector.x, 2) t.is(vector.y, 3) + t.end() }) test('`Vector#idiv(scalar)` should return self instance', function (t) { @@ -47,4 +52,5 @@ test('`Vector#idiv(scalar)` should return self instance', function (t) { var scalar = 2 var result = vector.idiv(scalar) t.is(result, vector) + t.end() }) diff --git a/test/dot-product.test.js b/test/dot-product.test.js index 72c8011..830c9d2 100644 --- a/test/dot-product.test.js +++ b/test/dot-product.test.js @@ -1,11 +1,12 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.dot(one, another)` should return dot product', function (t) { var one = new Vector(2, 3) var another = new Vector(3, 2) var product = Vector.dot(one, another) t.is(product, 12) + t.end() }) test('`Vector#dot(vector)` should return dot product', function (t) { @@ -13,4 +14,5 @@ test('`Vector#dot(vector)` should return dot product', function (t) { var vector = new Vector(3, 2) var product = self.dot(vector) t.is(product, 12) + t.end() }) diff --git a/test/equality.test.js b/test/equality.test.js index a3c8970..3aed0ae 100644 --- a/test/equality.test.js +++ b/test/equality.test.js @@ -1,11 +1,12 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.equals(one, another)` should check vectors equality', function (t) { var one = new Vector(1, 2) var another = new Vector(1, 2) var result = Vector.equals(one, another) t.true(result) + t.end() }) test('`Vector#equals(vector)` should check vectors equality', function (t) { @@ -13,6 +14,7 @@ test('`Vector#equals(vector)` should check vectors equality', function (t) { var vector = new Vector(1, 2) var result = self.equals(vector) t.true(result) + t.end() }) test('`Vector.compare(one, another)` should check vectors equality', function (t) { @@ -20,6 +22,7 @@ test('`Vector.compare(one, another)` should check vectors equality', function (t var another = new Vector(1, 2) var result = Vector.compare(one, another) t.is(result, 1) + t.end() }) test('`Vector#compare(vector)` should check vectors equality', function (t) { @@ -27,4 +30,5 @@ test('`Vector#compare(vector)` should check vectors equality', function (t) { var vector = new Vector(2, 2) var result = self.compare(vector) t.is(result, -1) + t.end() }) diff --git a/test/index.test.js b/test/index.test.js new file mode 100644 index 0000000..abbefcc --- /dev/null +++ b/test/index.test.js @@ -0,0 +1,26 @@ +var test = require('tape') +var tapDiff = require('tap-diff') + +test.createStream() + .pipe(tapDiff()) + .pipe(process.stdout) + +require('./addition.test.js') +require('./angle.test.js') +require('./convertion.test.js') +require('./copy.test.js') +require('./creation.test.js') +require('./distance.test.js') +require('./division.test.js') +require('./dot-product.test.js') +require('./equality.test.js') +require('./index.test.js') +require('./iterator.test.js') +require('./lerp.test.js') +require('./magnitude.test.js') +require('./multiplication.test.js') +require('./normalization.test.js') +require('./resetting.test.js') +require('./rotation.test.js') +require('./substraction.test.js') +require('./swizzling.test.js') diff --git a/test/iterator.test.js b/test/iterator.test.js index 69b556b..67a0405 100644 --- a/test/iterator.test.js +++ b/test/iterator.test.js @@ -1,15 +1,16 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') if (typeof Symbol !== 'undefined' && Symbol.iterator && Vector.prototype[Symbol.iterator]) { test('`Vector.prototype[Symbol.iterator]()` should return an iterator', function (t) { var vector = new Vector(3, 4) var iterator = vector[Symbol.iterator]() - t.truthy(iterator) + t.ok(iterator) t.true(typeof iterator.next === 'function') t.deepEqual(iterator.next(), { done: false, value: 3 }) t.deepEqual(iterator.next(), { done: false, value: 4 }) t.deepEqual(iterator.next(), { done: true, value: void 0 }) + t.end() }) } else { test.skip('`Vector.prototype[Symbol.iterator]()` should return an iterator', function (t) {}) diff --git a/test/lerp.test.js b/test/lerp.test.js index 6b23439..e8b8a80 100644 --- a/test/lerp.test.js +++ b/test/lerp.test.js @@ -1,5 +1,5 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.lerp(one, another, t)` should return linear interpolant between the vectors', function (t) { var one = new Vector(2, 2) @@ -9,6 +9,7 @@ test('`Vector.lerp(one, another, t)` should return linear interpolant between th t.true(result instanceof Vector) t.is(result.x, 3) t.is(result.y, 3) + t.end() }) test('`Vector#lerp(vector, t)` should return linear interpolant between the vectors', function (t) { @@ -19,4 +20,5 @@ test('`Vector#lerp(vector, t)` should return linear interpolant between the vect t.true(result instanceof Vector) t.is(result.x, 3) t.is(result.y, 3) + t.end() }) diff --git a/test/magnitude.test.js b/test/magnitude.test.js index 87cb805..b256f39 100644 --- a/test/magnitude.test.js +++ b/test/magnitude.test.js @@ -1,14 +1,16 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.magnitude(vector)` should return vector magnitude', function (t) { var vector = new Vector(3, 4) var magnitude = Vector.magnitude(vector) t.is(magnitude, 5) + t.end() }) test('`Vector#magnitude()` should return vector magnitude', function (t) { var vector = new Vector(3, 4) var magnitude = vector.magnitude() t.is(magnitude, 5) + t.end() }) diff --git a/test/multiplication.test.js b/test/multiplication.test.js index ec67521..0f7f314 100644 --- a/test/multiplication.test.js +++ b/test/multiplication.test.js @@ -1,5 +1,5 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.mul(scalar, vector)` should multiply vector on scalar', function (t) { var vector = new Vector(2, 3) @@ -8,6 +8,7 @@ test('`Vector.mul(scalar, vector)` should multiply vector on scalar', function ( t.true(result instanceof Vector) t.is(result.x, 4) t.is(result.y, 6) + t.end() }) test('`Vector#mul(scalar)` should multiply self on scalar', function (t) { @@ -17,6 +18,7 @@ test('`Vector#mul(scalar)` should multiply self on scalar', function (t) { t.true(result instanceof Vector) t.is(result.x, 4) t.is(result.y, 6) + t.end() }) test('`Vector.imul(scalar, vector)` should multiply vector on scalar', function (t) { @@ -25,6 +27,7 @@ test('`Vector.imul(scalar, vector)` should multiply vector on scalar', function Vector.imul(scalar, vector) t.is(vector.x, 4) t.is(vector.y, 6) + t.end() }) test('`Vector.imul(scalar, vector)` should return vector', function (t) { @@ -32,6 +35,7 @@ test('`Vector.imul(scalar, vector)` should return vector', function (t) { var scalar = 2 var result = Vector.imul(scalar, vector) t.is(result, vector) + t.end() }) test('`Vector#imul(scalar)` should multiply self on scalar', function (t) { @@ -40,6 +44,7 @@ test('`Vector#imul(scalar)` should multiply self on scalar', function (t) { vector.imul(scalar) t.is(vector.x, 4) t.is(vector.y, 6) + t.end() }) test('`Vector#imul(scalar)` should return self instance', function (t) { @@ -47,4 +52,5 @@ test('`Vector#imul(scalar)` should return self instance', function (t) { var scalar = 2 var result = vector.imul(scalar) t.is(result, vector) + t.end() }) diff --git a/test/normalization.test.js b/test/normalization.test.js index 85f6bdc..c786de6 100644 --- a/test/normalization.test.js +++ b/test/normalization.test.js @@ -1,5 +1,5 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.normalized(vector)` should return unit vector', function (t) { var vector = new Vector(2, 0) @@ -7,6 +7,7 @@ test('`Vector.normalized(vector)` should return unit vector', function (t) { t.true(result instanceof Vector) t.is(result.x, 1) t.is(result.y, 0) + t.end() }) test('`Vector.normalized(vector)` should return zero vector if zero vector was passed', function (t) { @@ -15,6 +16,7 @@ test('`Vector.normalized(vector)` should return zero vector if zero vector was p t.true(result instanceof Vector) t.is(result.x, 0) t.is(result.y, 0) + t.end() }) test('`Vector#normalized()` should return unit vector', function (t) { @@ -23,6 +25,7 @@ test('`Vector#normalized()` should return unit vector', function (t) { t.true(result instanceof Vector) t.is(result.x, 1) t.is(result.y, 0) + t.end() }) test('`Vector#normalized()` should return zero vector from zero vector', function (t) { @@ -31,6 +34,7 @@ test('`Vector#normalized()` should return zero vector from zero vector', functio t.true(result instanceof Vector) t.is(result.x, 0) t.is(result.y, 0) + t.end() }) test('`Vector.normalize(vector)` should convert passed vector to unit vector', function (t) { @@ -39,6 +43,7 @@ test('`Vector.normalize(vector)` should convert passed vector to unit vector', f t.is(vector.x, 1) t.is(vector.y, 0) t.is(result, vector) + t.end() }) test('`Vector.normalize(vector)` should do nothing if zero vector was passed', function (t) { @@ -47,6 +52,7 @@ test('`Vector.normalize(vector)` should do nothing if zero vector was passed', f t.is(vector.x, 0) t.is(vector.y, 0) t.is(result, vector) + t.end() }) test('`Vector#normalize()` should convert vector to unit vector', function (t) { @@ -54,10 +60,12 @@ test('`Vector#normalize()` should convert vector to unit vector', function (t) { vector.normalize() t.is(vector.x, 1) t.is(vector.y, 0) + t.end() }) test('`Vector#normalize()` should return self', function (t) { var vector = new Vector(0, 0) var result = vector.normalize() t.is(result, vector) + t.end() }) diff --git a/test/resetting.test.js b/test/resetting.test.js index 7a285eb..a31dab4 100644 --- a/test/resetting.test.js +++ b/test/resetting.test.js @@ -1,5 +1,5 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.reset(one, another)` should reset vector values', function (t) { var one = new Vector(1, 2) @@ -7,6 +7,7 @@ test('`Vector.reset(one, another)` should reset vector values', function (t) { Vector.reset(one, another) t.is(another.x, 1) t.is(another.y, 2) + t.end() }) test('`Vector.reset(one, another)` should return another vector', function (t) { @@ -14,6 +15,7 @@ test('`Vector.reset(one, another)` should return another vector', function (t) { var another = new Vector(0, 0) var result = Vector.reset(one, another) t.is(result, another) + t.end() }) test('`Vector#reset(vector)` should reset vector values', function (t) { @@ -22,6 +24,7 @@ test('`Vector#reset(vector)` should reset vector values', function (t) { self.reset(vector) t.is(self.x, 1) t.is(self.y, 2) + t.end() }) test('`Vector#reset(vector)` should return self', function (t) { @@ -29,6 +32,7 @@ test('`Vector#reset(vector)` should return self', function (t) { var vector = new Vector(1, 2) var result = self.reset(vector) t.is(result, self) + t.end() }) test('`Vector.zero(vector)` should reset vector values to zero', function (t) { @@ -36,12 +40,14 @@ test('`Vector.zero(vector)` should reset vector values to zero', function (t) { Vector.zero(vector) t.is(vector.x, 0) t.is(vector.y, 0) + t.end() }) test('`Vector.zero(vector)` should return passed vector', function (t) { var vector = new Vector(1, 2) var result = Vector.zero(vector) t.is(result, vector) + t.end() }) test('`Vector#zero()` should reset vector values to zero', function (t) { @@ -49,12 +55,14 @@ test('`Vector#zero()` should reset vector values to zero', function (t) { self.zero() t.is(self.x, 0) t.is(self.y, 0) + t.end() }) test('`Vector#zero()` should return self', function (t) { var self = new Vector(1, 2) var result = self.zero() t.is(result, self) + t.end() }) test('`Vector.set(x, y, vector)` should set vector values', function (t) { @@ -62,12 +70,14 @@ test('`Vector.set(x, y, vector)` should set vector values', function (t) { Vector.set(1, 2, vector) t.is(vector.x, 1) t.is(vector.y, 2) + t.end() }) test('`Vector.set(one, another)` should return vector', function (t) { var vector = new Vector(0, 0) var result = Vector.set(1, 2, vector) t.is(result, vector) + t.end() }) test('`Vector#set(vector)` should set vector values', function (t) { @@ -75,12 +85,14 @@ test('`Vector#set(vector)` should set vector values', function (t) { vector.set(1, 2) t.is(vector.x, 1) t.is(vector.y, 2) + t.end() }) test('`Vector#set(vector)` should return self', function (t) { var vector = new Vector(0, 0) var result = vector.set(1, 2) t.is(result, vector) + t.end() }) test('`Vector#set(vector)` should set vector values to zero if args not passed', function (t) { @@ -88,4 +100,5 @@ test('`Vector#set(vector)` should set vector values to zero if args not passed', vector.set() t.is(vector.x, 0) t.is(vector.y, 0) + t.end() }) diff --git a/test/rotation.test.js b/test/rotation.test.js index 8273074..7ef4cb8 100644 --- a/test/rotation.test.js +++ b/test/rotation.test.js @@ -1,5 +1,5 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.rotate(theta, vector)` should rotate vector on theta angle', function (t) { var vector = new Vector(3, 3) @@ -8,6 +8,7 @@ test('`Vector.rotate(theta, vector)` should rotate vector on theta angle', funct t.true(result instanceof Vector) t.is(result.x, -3) t.is(result.y, 3) + t.end() }) test('`Vector#rotate(theta)` should rotate vector on theta angle', function (t) { @@ -17,6 +18,7 @@ test('`Vector#rotate(theta)` should rotate vector on theta angle', function (t) t.true(result instanceof Vector) t.is(result.x, -3) t.is(result.y, 3) + t.end() }) test('`Vector.irotate(theta, vector)` should rotate vector on theta angle', function (t) { @@ -27,6 +29,7 @@ test('`Vector.irotate(theta, vector)` should rotate vector on theta angle', func t.is(result, vector) t.is(result.x, -3) t.is(result.y, 3) + t.end() }) test('`Vector.irotate(theta, vector)` should return vector', function (t) { @@ -34,6 +37,7 @@ test('`Vector.irotate(theta, vector)` should return vector', function (t) { var theta = Math.PI / 2 var result = Vector.irotate(theta, vector) t.is(result, vector) + t.end() }) test('`Vector#irotate(theta)` should rotate vector on theta angle', function (t) { @@ -44,6 +48,7 @@ test('`Vector#irotate(theta)` should rotate vector on theta angle', function (t) t.is(result, self) t.is(result.x, -3) t.is(result.y, 3) + t.end() }) test('`Vector#irotate(theta)` should return self instance', function (t) { @@ -51,4 +56,5 @@ test('`Vector#irotate(theta)` should return self instance', function (t) { var theta = Math.PI / 2 var result = self.irotate(theta) t.is(result, self) + t.end() }) diff --git a/test/substraction.test.js b/test/substraction.test.js index 9be52db..339f970 100644 --- a/test/substraction.test.js +++ b/test/substraction.test.js @@ -1,5 +1,5 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector.sub(one, another)` should return diff of two vectors', function (t) { var one = new Vector(1, 2) @@ -8,6 +8,7 @@ test('`Vector.sub(one, another)` should return diff of two vectors', function (t t.true(result instanceof Vector) t.is(result.x, 2) t.is(result.y, 2) + t.end() }) test('`Vector#sub(vector)` should return diff of two vectors', function (t) { @@ -17,6 +18,7 @@ test('`Vector#sub(vector)` should return diff of two vectors', function (t) { t.true(result instanceof Vector) t.is(result.x, 2) t.is(result.y, 2) + t.end() }) test('`Vector.isub(one, another)` should substract one vector from another', function (t) { @@ -25,6 +27,7 @@ test('`Vector.isub(one, another)` should substract one vector from another', fun Vector.isub(one, another) t.is(another.x, 2) t.is(another.y, 2) + t.end() }) test('`Vector.isub(one, another)` should return another vector', function (t) { @@ -32,6 +35,7 @@ test('`Vector.isub(one, another)` should return another vector', function (t) { var another = new Vector(3, 4) var result = Vector.isub(one, another) t.is(result, another) + t.end() }) test('`Vector#isub(vector)` should substract vector from self', function (t) { @@ -40,6 +44,7 @@ test('`Vector#isub(vector)` should substract vector from self', function (t) { self.isub(vector) t.is(self.x, 2) t.is(self.y, 2) + t.end() }) test('`Vector#isub(vector)` should return self instance', function (t) { @@ -47,4 +52,5 @@ test('`Vector#isub(vector)` should return self instance', function (t) { var vector = new Vector(1, 2) var result = self.isub(vector) t.is(result, self) + t.end() }) diff --git a/test/swizzling.test.js b/test/swizzling.test.js index d1d1a35..28772cc 100644 --- a/test/swizzling.test.js +++ b/test/swizzling.test.js @@ -1,5 +1,5 @@ var Vector = require('../dist/vectory.umd.js') -var test = require('ava') +var test = require('tape') test('`Vector#xx` should be an accessor', function (t) { var descriptor = Object.getOwnPropertyDescriptor(Vector.prototype, 'xx') @@ -7,6 +7,7 @@ test('`Vector#xx` should be an accessor', function (t) { t.is(descriptor.enumerable, false) t.true(typeof descriptor.get === 'function') t.true(typeof descriptor.set === 'function') + t.end() }) test('`Vector#xx` should have getter which return new vector', function (t) { @@ -15,6 +16,7 @@ test('`Vector#xx` should have getter which return new vector', function (t) { t.true(result instanceof Vector) t.is(result.x, 1) t.is(result.y, 1) + t.end() }) test('`Vector#xx` should have setter which set vector values', function (t) { @@ -23,6 +25,7 @@ test('`Vector#xx` should have setter which set vector values', function (t) { self.xx = vector t.is(self.x, 3) t.is(self.y, 3) + t.end() }) test('`Vector#xy` should be an accessor', function (t) { @@ -31,6 +34,7 @@ test('`Vector#xy` should be an accessor', function (t) { t.is(descriptor.enumerable, false) t.true(typeof descriptor.get === 'function') t.true(typeof descriptor.set === 'function') + t.end() }) test('`Vector#xy` should have getter which return new vector', function (t) { @@ -39,6 +43,7 @@ test('`Vector#xy` should have getter which return new vector', function (t) { t.true(result instanceof Vector) t.is(result.x, 1) t.is(result.y, 2) + t.end() }) test('`Vector#xy` should have setter which set vector values', function (t) { @@ -47,6 +52,7 @@ test('`Vector#xy` should have setter which set vector values', function (t) { self.xy = vector t.is(self.x, 3) t.is(self.y, 4) + t.end() }) test('`Vector#yx` should be an accessor', function (t) { @@ -55,6 +61,7 @@ test('`Vector#yx` should be an accessor', function (t) { t.is(descriptor.enumerable, false) t.true(typeof descriptor.get === 'function') t.true(typeof descriptor.set === 'function') + t.end() }) test('`Vector#yx` should have getter which return new vector', function (t) { var self = new Vector(1, 2) @@ -62,6 +69,7 @@ test('`Vector#yx` should have getter which return new vector', function (t) { t.true(result instanceof Vector) t.is(result.x, 2) t.is(result.y, 1) + t.end() }) test('`Vector#yx` should have setter which set vector values', function (t) { @@ -70,6 +78,7 @@ test('`Vector#yx` should have setter which set vector values', function (t) { self.yx = vector t.is(self.x, 4) t.is(self.y, 3) + t.end() }) test('`Vector#yy` should be an accessor', function (t) { @@ -78,6 +87,7 @@ test('`Vector#yy` should be an accessor', function (t) { t.is(descriptor.enumerable, false) t.true(typeof descriptor.get === 'function') t.true(typeof descriptor.set === 'function') + t.end() }) test('`Vector#yy` should have getter which return new vector', function (t) { @@ -86,6 +96,7 @@ test('`Vector#yy` should have getter which return new vector', function (t) { t.true(result instanceof Vector) t.is(result.x, 2) t.is(result.y, 2) + t.end() }) test('`Vector#yy` should have setter which set vector values', function (t) { @@ -94,4 +105,5 @@ test('`Vector#yy` should have setter which set vector values', function (t) { self.yy = vector t.is(self.x, 4) t.is(self.y, 4) + t.end() }) From f54406b944b1ccf3068b0acb06091e6b63d46ce3 Mon Sep 17 00:00:00 2001 From: Vladimir Bykov Date: Sat, 18 Nov 2017 14:28:50 +0300 Subject: [PATCH 2/8] Added changelog; resolved #40 --- CHANGELOG.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..0921c1b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,44 @@ +# Changelog + +## [1.2.1] - 2017-09-04 + +### Added + +- Support of es6 [pkg.module](https://github.com/rollup/rollup/wiki/pkg.module) #38 + +## [1.2.0] - 2017-08-29 + +### Added + +- Implemented vector rotation #34 + + - `Vector.rotate(theta, vector)` + - `Vector.prototype.rotate(theta)` + - `Vector.irotate(theta, vector)` + - `Vector.prototype.irotate(theta)` + +- Implemented alias `Vector#clone()` for `Vector#copy()` #35 + +- Implemented filter for benchmark #29 + +``` +npm run behch -- --filter add +``` + +list of available filters: `create`, `add`, `sub`, `mul`, `div`, `lerp`, `norm`, `mag`, `dot`, `dist`, `angle`, `rotate`, `reset`, `copy`, `convert`, `equal`, `swizzling`, `iterator` + +### Fixed + +- Fixed vectors' equality: implemented usage of `Number.EPSILON` #36 + +### Removed + +- Dropped support of Node < 4 + +## [1.1.0] - 2016-07-23 + +### Added + +- Implemented `Vector.prototype.set(x, y)` +- Implemented `Vector.prototype.toArray()` +- Implemented `Symbol.toStringTag` support diff --git a/README.md b/README.md index 88f81d9..5657469 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,44 @@

+Yet another 2d vector implementation for basic motion + +``` js +this.velocity.iadd(this.acceleration) +this.position.iadd(this.velocity) +this.acceleration.zero() +``` + +with rare methods such as [lerp](https://en.wikipedia.org/wiki/Linear_interpolation) + +``` js +var prev = new Vector(1, 2) +var next = new Vector(3, 4) +prev.lerp(next, 0.5) // Vector(2, 3) +``` + +and [swizzling](https://www.opengl.org/wiki/Data_Type_%28GLSL%29#Swizzling) + +``` js +var vector = new Vector(1 ,2) +vector.yx // Vector(2, 1) +``` + +with some ES6 support + +``` js +var vector = new Vector(0, 0) +var vec3 = [...vector, 0] // [0, 0, 0] +``` + +and FP ability + +``` js +// create vectors from raw data and scale them twice +var data = [[1, 2], [3, 4]/*, ... */] +var vectors = data.map(Vector.from).map(Vector.mul.bind(null, 2)) +``` + ## Table of Contents - [Features](#features) From fa5cdcf182aee0d9a85f2ea897255f8ca05d3e1f Mon Sep 17 00:00:00 2001 From: Vladimir Bykov Date: Sat, 18 Nov 2017 14:36:01 +0300 Subject: [PATCH 3/8] Fixed Wrong .angleTo() computing; resolved #41 --- dist/vectory.js | 2 +- dist/vectory.min.js | 2 +- dist/vectory.umd.js | 2 +- src/angle.js | 2 +- test/angle.test.js | 12 ++++++------ 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dist/vectory.js b/dist/vectory.js index 4c2fac8..87c7f77 100644 --- a/dist/vectory.js +++ b/dist/vectory.js @@ -168,7 +168,7 @@ Vector$1.angleTo = function (one, another) { }; Vector$1.prototype.angleTo = function (vector) { - return Math.acos(this.dot(vector) / this.magnitude() * vector.magnitude()) + return Math.acos(this.dot(vector) / (this.magnitude() * vector.magnitude())) }; function rotate (vector, theta) { diff --git a/dist/vectory.min.js b/dist/vectory.min.js index 0cf9cb3..8496768 100644 --- a/dist/vectory.min.js +++ b/dist/vectory.min.js @@ -1 +1 @@ -!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.Vector=n()}(this,function(){"use strict";function t(t,n){this.x=t||0,this.y=n||0}function n(t,n){var i=Math.cos(n),r=Math.sin(n),e=t.x,o=t.y;return t.x=e*i-o*r,t.y=e*r+o*i,t}function i(t){this.vector=t,this.__idx=0}t.displayName="Vector",t.from=function(n){return new t(n[0],n[1])},t.fromAngle=function(n,i){return new t(i*Math.cos(n),i*Math.sin(n))},t.parse=function(n){return t.from(n.trim().replace(","," ").split(/\s+/).map(parseFloat))},t.add=function(t,n){return n.add(t)},t.prototype.add=function(n){return new t(this.x+n.x,this.y+n.y)},t.iadd=function(t,n){return n.iadd(t)},t.prototype.iadd=function(t){return this.x+=t.x,this.y+=t.y,this},t.sub=function(t,n){return n.sub(t)},t.prototype.sub=function(n){return new t(this.x-n.x,this.y-n.y)},t.isub=function(t,n){return n.isub(t)},t.prototype.isub=function(t){return this.x-=t.x,this.y-=t.y,this},t.mul=function(t,n){return n.mul(t)},t.prototype.mul=function(n){return new t(this.x*n,this.y*n)},t.imul=function(t,n){return n.imul(t)},t.prototype.imul=function(t){return this.x*=t,this.y*=t,this},t.div=function(t,n){return n.div(t)},t.prototype.div=function(n){return new t(this.x/n,this.y/n)},t.idiv=function(t,n){return n.idiv(t)},t.prototype.idiv=function(t){return this.x/=t,this.y/=t,this},t.lerp=function(t,n,i){return t.lerp(n,i)},t.prototype.lerp=function(n,i){return new t((1-i)*this.x+i*n.x,(1-i)*this.y+i*n.y)},t.normalized=function(t){return t.normalized()},t.prototype.normalized=function(){var n=this.x,i=this.y,r=Math.sqrt(n*n+i*i);return r>0?new t(n/r,i/r):new t(0,0)},t.normalize=function(t){return t.normalize()},t.prototype.normalize=function(){var t=this.x,n=this.y,i=Math.sqrt(t*t+n*n);return i>0&&(this.x=t/i,this.y=n/i),this},t.magnitude=function(t){return t.magnitude()},t.prototype.magnitude=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.dot=function(t,n){return n.dot(t)},t.prototype.dot=function(t){return this.x*t.x+this.y*t.y},t.distance=function(t,n){return n.distance(t)},t.prototype.distance=function(t){var n=this.x-t.x,i=this.y-t.y;return Math.sqrt(n*n+i*i)},t.angleOf=function(t){return t.angleOf()},t.prototype.angleOf=function(){return Math.atan2(this.y,this.x)},t.angleTo=function(t,n){return n.angleTo(t)},t.prototype.angleTo=function(t){return Math.acos(this.dot(t)/this.magnitude()*t.magnitude())},t.rotate=function(t,n){return n.rotate(t)},t.prototype.rotate=function(t){return n(this.copy(),t)},t.irotate=function(t,n){return n.irotate(t)},t.prototype.irotate=function(t){return n(this,t)},t.reset=function(t,n){return n.reset(t)},t.prototype.reset=function(t){return this.x=t.x,this.y=t.y,this},t.zero=function(t){return t.zero()},t.prototype.zero=function(){return this.x=0,this.y=0,this},t.set=function(t,n,i){return i.set(t,n)},t.prototype.set=function(t,n){return this.x=t||0,this.y=n||0,this},t.copy=function(t){return t.copy()},t.prototype.copy=function(){return new t(this.x,this.y)},t.clone=t.copy,t.prototype.clone=t.prototype.copy,t.toJSON=function(t){return t.toJSON()},t.prototype.toJSON=function(){return[this.x,this.y]},t.toString=function(t){return t?t.toString():Function.prototype.toString.call(this)},t.prototype.toString=function(){return this.x.toFixed(3)+" "+this.y.toFixed(3)},"undefined"!=typeof Symbol&&Symbol.toStringTag&&(t.prototype[Symbol.toStringTag]="Vector"),t.toArray=function(t){return t.toArray()},t.prototype.toArray=function(){return[this.x,this.y]};var r="EPSILON"in Number?Number.EPSILON:2.220446049250313e-16;return t.equals=function(t,n){return t.equals(n)},t.prototype.equals=function(t){return Math.abs(this.x-t.x)i)-(i>n)},Object.defineProperties(t.prototype,{xx:{configurable:!0,get:function(){return new t(this.x,this.x)},set:function(t){this.x=t.x,this.y=t.x}},xy:{configurable:!0,get:function(){return new t(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y}},yx:{configurable:!0,get:function(){return new t(this.y,this.x)},set:function(t){this.x=t.y,this.y=t.x}},yy:{configurable:!0,get:function(){return new t(this.y,this.y)},set:function(t){this.x=t.y,this.y=t.y}}}),i.prototype.next=function(){return 0===this.__idx?(this.__idx++,{done:!1,value:this.vector.x}):1===this.__idx?(this.__idx++,{done:!1,value:this.vector.y}):{done:!0,value:void 0}},"undefined"!=typeof Symbol&&Symbol.iterator&&(t.prototype[Symbol.iterator]=function(){return new i(this)}),t}); +!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.Vector=n()}(this,function(){"use strict";function t(t,n){this.x=t||0,this.y=n||0}function n(t,n){var i=Math.cos(n),r=Math.sin(n),e=t.x,o=t.y;return t.x=e*i-o*r,t.y=e*r+o*i,t}function i(t){this.vector=t,this.__idx=0}t.displayName="Vector",t.from=function(n){return new t(n[0],n[1])},t.fromAngle=function(n,i){return new t(i*Math.cos(n),i*Math.sin(n))},t.parse=function(n){return t.from(n.trim().replace(","," ").split(/\s+/).map(parseFloat))},t.add=function(t,n){return n.add(t)},t.prototype.add=function(n){return new t(this.x+n.x,this.y+n.y)},t.iadd=function(t,n){return n.iadd(t)},t.prototype.iadd=function(t){return this.x+=t.x,this.y+=t.y,this},t.sub=function(t,n){return n.sub(t)},t.prototype.sub=function(n){return new t(this.x-n.x,this.y-n.y)},t.isub=function(t,n){return n.isub(t)},t.prototype.isub=function(t){return this.x-=t.x,this.y-=t.y,this},t.mul=function(t,n){return n.mul(t)},t.prototype.mul=function(n){return new t(this.x*n,this.y*n)},t.imul=function(t,n){return n.imul(t)},t.prototype.imul=function(t){return this.x*=t,this.y*=t,this},t.div=function(t,n){return n.div(t)},t.prototype.div=function(n){return new t(this.x/n,this.y/n)},t.idiv=function(t,n){return n.idiv(t)},t.prototype.idiv=function(t){return this.x/=t,this.y/=t,this},t.lerp=function(t,n,i){return t.lerp(n,i)},t.prototype.lerp=function(n,i){return new t((1-i)*this.x+i*n.x,(1-i)*this.y+i*n.y)},t.normalized=function(t){return t.normalized()},t.prototype.normalized=function(){var n=this.x,i=this.y,r=Math.sqrt(n*n+i*i);return r>0?new t(n/r,i/r):new t(0,0)},t.normalize=function(t){return t.normalize()},t.prototype.normalize=function(){var t=this.x,n=this.y,i=Math.sqrt(t*t+n*n);return i>0&&(this.x=t/i,this.y=n/i),this},t.magnitude=function(t){return t.magnitude()},t.prototype.magnitude=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.dot=function(t,n){return n.dot(t)},t.prototype.dot=function(t){return this.x*t.x+this.y*t.y},t.distance=function(t,n){return n.distance(t)},t.prototype.distance=function(t){var n=this.x-t.x,i=this.y-t.y;return Math.sqrt(n*n+i*i)},t.angleOf=function(t){return t.angleOf()},t.prototype.angleOf=function(){return Math.atan2(this.y,this.x)},t.angleTo=function(t,n){return n.angleTo(t)},t.prototype.angleTo=function(t){return Math.acos(this.dot(t)/(this.magnitude()*t.magnitude()))},t.rotate=function(t,n){return n.rotate(t)},t.prototype.rotate=function(t){return n(this.copy(),t)},t.irotate=function(t,n){return n.irotate(t)},t.prototype.irotate=function(t){return n(this,t)},t.reset=function(t,n){return n.reset(t)},t.prototype.reset=function(t){return this.x=t.x,this.y=t.y,this},t.zero=function(t){return t.zero()},t.prototype.zero=function(){return this.x=0,this.y=0,this},t.set=function(t,n,i){return i.set(t,n)},t.prototype.set=function(t,n){return this.x=t||0,this.y=n||0,this},t.copy=function(t){return t.copy()},t.prototype.copy=function(){return new t(this.x,this.y)},t.clone=t.copy,t.prototype.clone=t.prototype.copy,t.toJSON=function(t){return t.toJSON()},t.prototype.toJSON=function(){return[this.x,this.y]},t.toString=function(t){return t?t.toString():Function.prototype.toString.call(this)},t.prototype.toString=function(){return this.x.toFixed(3)+" "+this.y.toFixed(3)},"undefined"!=typeof Symbol&&Symbol.toStringTag&&(t.prototype[Symbol.toStringTag]="Vector"),t.toArray=function(t){return t.toArray()},t.prototype.toArray=function(){return[this.x,this.y]};var r="EPSILON"in Number?Number.EPSILON:2.220446049250313e-16;return t.equals=function(t,n){return t.equals(n)},t.prototype.equals=function(t){return Math.abs(this.x-t.x)i)-(i>n)},Object.defineProperties(t.prototype,{xx:{configurable:!0,get:function(){return new t(this.x,this.x)},set:function(t){this.x=t.x,this.y=t.x}},xy:{configurable:!0,get:function(){return new t(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y}},yx:{configurable:!0,get:function(){return new t(this.y,this.x)},set:function(t){this.x=t.y,this.y=t.x}},yy:{configurable:!0,get:function(){return new t(this.y,this.y)},set:function(t){this.x=t.y,this.y=t.y}}}),i.prototype.next=function(){return 0===this.__idx?(this.__idx++,{done:!1,value:this.vector.x}):1===this.__idx?(this.__idx++,{done:!1,value:this.vector.y}):{done:!0,value:void 0}},"undefined"!=typeof Symbol&&Symbol.iterator&&(t.prototype[Symbol.iterator]=function(){return new i(this)}),t}); diff --git a/dist/vectory.umd.js b/dist/vectory.umd.js index 35e7929..032374f 100644 --- a/dist/vectory.umd.js +++ b/dist/vectory.umd.js @@ -174,7 +174,7 @@ Vector$1.angleTo = function (one, another) { }; Vector$1.prototype.angleTo = function (vector) { - return Math.acos(this.dot(vector) / this.magnitude() * vector.magnitude()) + return Math.acos(this.dot(vector) / (this.magnitude() * vector.magnitude())) }; function rotate (vector, theta) { diff --git a/src/angle.js b/src/angle.js index 16ada82..b9bdaab 100644 --- a/src/angle.js +++ b/src/angle.js @@ -13,7 +13,7 @@ Vector.angleTo = function (one, another) { } Vector.prototype.angleTo = function (vector) { - return Math.acos(this.dot(vector) / this.magnitude() * vector.magnitude()) + return Math.acos(this.dot(vector) / (this.magnitude() * vector.magnitude())) } export default Vector diff --git a/test/angle.test.js b/test/angle.test.js index a71c55f..00d7361 100644 --- a/test/angle.test.js +++ b/test/angle.test.js @@ -16,17 +16,17 @@ test('`Vector#angleOf()` should return the angle theta of vector', function (t) }) test('`Vector.angleTo(one, another)` should return the angle between vectors', function (t) { - var one = new Vector(0, 1) - var another = new Vector(1, 0) + var one = new Vector(5, 10) + var another = new Vector(10, 15) var result = Vector.angleTo(one, another) - t.is(result * 180 / Math.PI, 90) + t.is(Math.round(result * 180 / Math.PI), 7) t.end() }) test('`Vector#angleTo(vector)` should return the angle between vectors', function (t) { - var self = new Vector(0, 1) - var vector = new Vector(1, 0) + var self = new Vector(5, 10) + var vector = new Vector(10, 15) var result = self.angleTo(vector) - t.is(result * 180 / Math.PI, 90) + t.is(Math.round(result * 180 / Math.PI), 7) t.end() }) From cfa0f849e14f5de067cb10af711ac982ed4843a7 Mon Sep 17 00:00:00 2001 From: Vladimir Bykov Date: Sat, 18 Nov 2017 14:37:05 +0300 Subject: [PATCH 4/8] Added changes to changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0921c1b..ed47bff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [1.2.2] - 2017-11-18 + +### Fixed + +- Fixed Wrong .angleTo() computing #41 + ## [1.2.1] - 2017-09-04 ### Added From 6661ee5c0609d2a70d92aed26c6e192acbcc55ee Mon Sep 17 00:00:00 2001 From: Vladimir Bykov Date: Sat, 18 Nov 2017 14:46:36 +0300 Subject: [PATCH 5/8] Benchmark on latest node --- README.md | 143 +++++++++++++++++++++++++------------------------ bench/index.js | 2 +- 2 files changed, 73 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 5657469..cb79e1e 100644 --- a/README.md +++ b/README.md @@ -229,117 +229,118 @@ Follow [this link](https://processing.org/tutorials/pvector/) to read more about ## Benchmark -Intel Core i5-4210U @ 1.7 GHz, DDR3 4 Gb, node v8.2.1 +Intel Core i5-4210U @ 1.7 GHz, DDR3 4 Gb, node v9.2.0 ``` -> vectory@1.2.0 bench d:\Projects\vectory + +> vectory@1.2.2 bench d:\Projects\vectory > node ./bench/index.js ℹ start benchmark, please wait a bit... Cteation - ✔ Vector(x, y) x 46,743,543 ops/sec ±0.51% (95 runs sampled) - ✔ Vector.from([x, y]) x 43,975,387 ops/sec ±0.74% (95 runs sampled) - ✔ Vector.fromAngle(angle, magnitude) x 46,690,953 ops/sec ±0.50% (94 runs sampled) - ✔ Vector.parse(string) x 844,061 ops/sec ±0.71% (91 runs sampled) + ✔ Vector(x, y) x 348,913,616 ops/sec ±1.21% (85 runs sampled) + ✔ Vector.from([x, y]) x 338,169,673 ops/sec ±1.39% (86 runs sampled) + ✔ Vector.fromAngle(angle, magnitude) x 356,315,826 ops/sec ±0.82% (85 runs sampled) + ✔ Vector.parse(string) x 1,524,501 ops/sec ±0.38% (96 runs sampled) Addition - ✔ Vector.add(one, another) x 42,209,927 ops/sec ±0.85% (91 runs sampled) - ✔ Vector#add(vector) x 45,393,805 ops/sec ±0.60% (91 runs sampled) - ✔ Vector.iadd(one, another) x 51,974,197 ops/sec ±0.67% (92 runs sampled) - ✔ Vector#iadd(vector) x 56,314,420 ops/sec ±0.97% (94 runs sampled) + ✔ Vector.add(one, another) x 350,259,731 ops/sec ±0.85% (84 runs sampled) + ✔ Vector#add(vector) x 352,389,076 ops/sec ±0.74% (87 runs sampled) + ✔ Vector.iadd(one, another) x 168,892,112 ops/sec ±0.78% (90 runs sampled) + ✔ Vector#iadd(vector) x 170,948,920 ops/sec ±0.66% (88 runs sampled) Substraction - ✔ Vector.sub(one, another) x 42,524,916 ops/sec ±0.87% (92 runs sampled) - ✔ Vector#sub(vector) x 46,091,266 ops/sec ±0.63% (91 runs sampled) - ✔ Vector.isub(one, another) x 51,595,827 ops/sec ±0.67% (94 runs sampled) - ✔ Vector#isub(vector) x 56,167,879 ops/sec ±1.27% (90 runs sampled) + ✔ Vector.sub(one, another) x 352,975,428 ops/sec ±0.96% (90 runs sampled) + ✔ Vector#sub(vector) x 346,215,470 ops/sec ±1.30% (88 runs sampled) + ✔ Vector.isub(one, another) x 168,818,810 ops/sec ±0.90% (87 runs sampled) + ✔ Vector#isub(vector) x 164,773,894 ops/sec ±1.83% (87 runs sampled) Multiplication - ✔ Vector.mul(scalar, vector) x 42,963,883 ops/sec ±1.10% (89 runs sampled) - ✔ Vector#mul(vector) x 45,479,457 ops/sec ±0.99% (93 runs sampled) - ✔ Vector.imul(scalar, vector) x 53,674,489 ops/sec ±0.89% (93 runs sampled) - ✔ Vector#imul(vector) x 56,131,658 ops/sec ±1.45% (87 runs sampled) + ✔ Vector.mul(scalar, vector) x 352,641,917 ops/sec ±0.72% (92 runs sampled) + ✔ Vector#mul(vector) x 228,131,960 ops/sec ±18.68% (59 runs sampled) + ✔ Vector.imul(scalar, vector) x 60,518,558 ops/sec ±1.63% (80 runs sampled) + ✔ Vector#imul(vector) x 148,143,360 ops/sec ±8.39% (81 runs sampled) - undefined - ✔ Vector.div(scalar, vector) x 41,455,674 ops/sec ±1.00% (92 runs sampled) - ✔ Vector#div(vector) x 43,982,841 ops/sec ±0.94% (92 runs sampled) - ✔ Vector.idiv(scalar, vector) x 50,470,195 ops/sec ±0.99% (92 runs sampled) - ✔ Vector#idiv(vector) x 54,262,823 ops/sec ±1.11% (89 runs sampled) + Division + ✔ Vector.div(scalar, vector) x 61,518,555 ops/sec ±1.58% (85 runs sampled) + ✔ Vector#div(vector) x 163,262,379 ops/sec ±22.63% (44 runs sampled) + ✔ Vector.idiv(scalar, vector) x 49,366,939 ops/sec ±4.25% (76 runs sampled) + ✔ Vector#idiv(vector) x 59,498,001 ops/sec ±1.77% (83 runs sampled) Linear Interpolation - ✔ Vector.lerp(one, another, t) x 37,476,071 ops/sec ±0.67% (93 runs sampled) - ✔ Vector#lerp(vector, t) x 40,018,105 ops/sec ±0.95% (91 runs sampled) + ✔ Vector.lerp(one, another, t) x 110,432,701 ops/sec ±12.50% (33 runs sampled) + ✔ Vector#lerp(vector, t) x 60,057,103 ops/sec ±1.93% (85 runs sampled) Normalization - ✔ Vector.normalized(vector) x 34,610,141 ops/sec ±1.70% (91 runs sampled) - ✔ Vector#normalized() x 33,910,394 ops/sec ±1.02% (91 runs sampled) - ✔ Vector.normalize(vector) x 45,430,996 ops/sec ±0.48% (93 runs sampled) - ✔ Vector#normalize() x 51,779,510 ops/sec ±0.98% (92 runs sampled) + ✔ Vector.normalized(vector) x 51,621,604 ops/sec ±3.21% (60 runs sampled) + ✔ Vector#normalized() x 25,901,696 ops/sec ±3.97% (76 runs sampled) + ✔ Vector.normalize(vector) x 29,906,998 ops/sec ±4.02% (75 runs sampled) + ✔ Vector#normalize() x 29,326,114 ops/sec ±3.41% (80 runs sampled) Magnitude - ✔ Vector.magnitude(vector) x 50,388,862 ops/sec ±1.07% (92 runs sampled) - ✔ Vector#magnitude() x 52,680,430 ops/sec ±0.55% (92 runs sampled) + ✔ Vector.magnitude(vector) x 61,280,362 ops/sec ±3.38% (82 runs sampled) + ✔ Vector#magnitude() x 79,351,707 ops/sec ±2.30% (62 runs sampled) Dot Product - ✔ Vector.dot(one, another) x 49,099,926 ops/sec ±1.11% (92 runs sampled) - ✔ Vector#dot(vector) x 50,984,589 ops/sec ±0.75% (91 runs sampled) + ✔ Vector.dot(one, another) x 65,872,652 ops/sec ±1.83% (83 runs sampled) + ✔ Vector#dot(vector) x 73,566,904 ops/sec ±1.89% (78 runs sampled) Distance - ✔ Vector.distance(one, another) x 45,798,049 ops/sec ±1.19% (91 runs sampled) - ✔ Vector#distance(vector) x 48,614,015 ops/sec ±0.86% (86 runs sampled) + ✔ Vector.distance(one, another) x 63,302,249 ops/sec ±1.41% (85 runs sampled) + ✔ Vector#distance(vector) x 62,915,660 ops/sec ±2.25% (84 runs sampled) Angle computing - ✔ Vector.angleOf(vector) x 19,578,714 ops/sec ±0.71% (94 runs sampled) - ✔ Vector#angleOf() x 15,775,111 ops/sec ±0.71% (93 runs sampled) - ✔ Vector.angleTo(one, another) x 24,279,594 ops/sec ±1.05% (89 runs sampled) - ✔ Vector#angleTo(vector) x 25,635,012 ops/sec ±2.02% (88 runs sampled) + ✔ Vector.angleOf(vector) x 19,971,981 ops/sec ±2.31% (75 runs sampled) + ✔ Vector#angleOf() x 36,392,689 ops/sec ±1.45% (84 runs sampled) + ✔ Vector.angleTo(one, another) x 9,924,167 ops/sec ±0.68% (93 runs sampled) + ✔ Vector#angleTo(vector) x 12,599,284 ops/sec ±2.59% (64 runs sampled) Rotation - ✔ Vector.rotate(theta, vector) x 14,454,664 ops/sec ±0.29% (95 runs sampled) - ✔ Vector#rotate(theta) x 14,748,750 ops/sec ±0.83% (89 runs sampled) - ✔ Vector.irotate(theta, vector) x 15,671,034 ops/sec ±0.99% (92 runs sampled) - ✔ Vector#irotate(theta) x 15,809,098 ops/sec ±0.40% (93 runs sampled) + ✔ Vector.rotate(theta, vector) x 60,097,845 ops/sec ±1.84% (81 runs sampled) + ✔ Vector#rotate(theta) x 61,736,300 ops/sec ±1.72% (86 runs sampled) + ✔ Vector.irotate(theta, vector) x 54,403,112 ops/sec ±2.12% (83 runs sampled) + ✔ Vector#irotate(theta) x 54,691,285 ops/sec ±1.82% (83 runs sampled) Resetting - ✔ Vector.reset(one, another) x 56,820,469 ops/sec ±0.71% (91 runs sampled) - ✔ Vector#reset(vector) x 59,785,743 ops/sec ±1.02% (89 runs sampled) - ✔ Vector.zero(vector) x 61,210,667 ops/sec ±0.95% (90 runs sampled) - ✔ Vector#zero() x 37,152,570 ops/sec ±18.39% (52 runs sampled) - ✔ Vector.set(x, y, vector) x 23,268,702 ops/sec ±4.99% (69 runs sampled) - ✔ Vector#set(vector) x 33,454,572 ops/sec ±4.58% (66 runs sampled) + ✔ Vector.reset(one, another) x 60,446,058 ops/sec ±1.94% (87 runs sampled) + ✔ Vector#reset(vector) x 46,877,562 ops/sec ±15.80% (69 runs sampled) + ✔ Vector.zero(vector) x 12,040,985 ops/sec ±17.99% (61 runs sampled) + ✔ Vector#zero() x 11,444,775 ops/sec ±6.08% (67 runs sampled) + ✔ Vector.set(x, y, vector) x 17,119,965 ops/sec ±9.95% (64 runs sampled) + ✔ Vector#set(vector) x 15,993,806 ops/sec ±2.24% (80 runs sampled) Copy - ✔ Vector.copy(vector) x 25,562,562 ops/sec ±3.15% (66 runs sampled) - ✔ Vector#copy() x 24,956,985 ops/sec ±2.95% (69 runs sampled) + ✔ Vector.copy(vector) x 16,624,837 ops/sec ±10.64% (60 runs sampled) + ✔ Vector#copy() x 22,157,494 ops/sec ±13.33% (68 runs sampled) Convertion - ✔ Vector.toJSON(vector) x 25,875,224 ops/sec ±4.33% (72 runs sampled) - ✔ Vector#toJSON() x 31,665,509 ops/sec ±3.53% (81 runs sampled) - ✔ Vector.toString(vector) x 1,394,192 ops/sec ±2.21% (81 runs sampled) - ✔ Vector#toString() x 1,722,970 ops/sec ±0.89% (89 runs sampled) - ✔ Vector.toArray(vector) x 38,888,744 ops/sec ±2.66% (86 runs sampled) - ✔ Vector#toArray() x 34,146,372 ops/sec ±2.63% (87 runs sampled) + ✔ Vector.toJSON(vector) x 19,314,908 ops/sec ±17.50% (60 runs sampled) + ✔ Vector#toJSON() x 11,781,944 ops/sec ±2.69% (76 runs sampled) + ✔ Vector.toString(vector) x 914,328 ops/sec ±6.69% (59 runs sampled) + ✔ Vector#toString() x 927,311 ops/sec ±5.89% (66 runs sampled) + ✔ Vector.toArray(vector) x 30,829,118 ops/sec ±7.14% (67 runs sampled) + ✔ Vector#toArray() x 35,954,257 ops/sec ±6.06% (70 runs sampled) Equality - ✔ Vector.equals(one, another) x 40,988,367 ops/sec ±2.15% (84 runs sampled) - ✔ Vector#equals(vector) x 41,154,452 ops/sec ±2.89% (78 runs sampled) - ✔ Vector.compare(one, another) x 21,772,261 ops/sec ±1.69% (86 runs sampled) - ✔ Vector#compare(vector) x 26,722,372 ops/sec ±0.38% (94 runs sampled) + ✔ Vector.equals(one, another) x 25,457,189 ops/sec ±4.57% (71 runs sampled) + ✔ Vector#equals(vector) x 23,318,002 ops/sec ±6.88% (66 runs sampled) + ✔ Vector.compare(one, another) x 46,436,815 ops/sec ±3.08% (78 runs sampled) + ✔ Vector#compare(vector) x 32,291,344 ops/sec ±4.25% (69 runs sampled) Swizzling - ✔ Vector#xx get x 49,012,070 ops/sec ±0.91% (92 runs sampled) - ✔ Vector#xx set x 59,257,367 ops/sec ±1.06% (89 runs sampled) - ✔ Vector#xy get x 48,156,050 ops/sec ±0.68% (92 runs sampled) - ✔ Vector#xy set x 59,525,311 ops/sec ±0.98% (92 runs sampled) - ✔ Vector#yx get x 47,543,864 ops/sec ±0.43% (90 runs sampled) - ✔ Vector#yx set x 59,701,618 ops/sec ±0.86% (92 runs sampled) - ✔ Vector#yy get x 49,532,593 ops/sec ±0.62% (92 runs sampled) - ✔ Vector#yy set x 59,408,608 ops/sec ±1.11% (88 runs sampled) + ✔ Vector#xx get x 31,354,935 ops/sec ±4.03% (66 runs sampled) + ✔ Vector#xx set x 33,392,725 ops/sec ±5.28% (69 runs sampled) + ✔ Vector#xy get x 29,551,855 ops/sec ±6.72% (68 runs sampled) + ✔ Vector#xy set x 33,795,883 ops/sec ±5.03% (63 runs sampled) + ✔ Vector#yx get x 28,904,521 ops/sec ±13.83% (68 runs sampled) + ✔ Vector#yx set x 41,581,221 ops/sec ±6.78% (76 runs sampled) + ✔ Vector#yy get x 33,609,933 ops/sec ±6.54% (68 runs sampled) + ✔ Vector#yy set x 35,494,083 ops/sec ±5.73% (66 runs sampled) Iterator - ✔ Spread operator x 3,825,038 ops/sec ±0.56% (92 runs sampled) - ✔ for..of loop x 12,763,966 ops/sec ±1.56% (93 runs sampled) + ✔ Spread operator x 2,642,300 ops/sec ±4.77% (70 runs sampled) + ✔ for..of loop x 8,924,210 ops/sec ±4.14% (61 runs sampled) ``` diff --git a/bench/index.js b/bench/index.js index db0c4c3..77ea141 100644 --- a/bench/index.js +++ b/bench/index.js @@ -28,7 +28,7 @@ var benchmarks = { 'add': require('./benchmarks/addition.bench.js'), 'sub': require('./benchmarks/substraction.bench.js'), 'mul': require('./benchmarks/multiplication.bench.js'), - 'dev': require('./benchmarks/division.bench.js'), + 'div': require('./benchmarks/division.bench.js'), 'lerp': require('./benchmarks/lerp.bench.js'), 'norm': require('./benchmarks/normalization.bench.js'), 'mag': require('./benchmarks/magnitude.bench.js'), From 052e3e111429b2e8f30ca52458840a724cf5904c Mon Sep 17 00:00:00 2001 From: Vladimir Bykov Date: Sat, 18 Nov 2017 14:49:26 +0300 Subject: [PATCH 6/8] Update ver --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5ec98a..93ac1f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vectory", - "version": "1.2.1", + "version": "1.2.2", "description": "High performant, DevTools friendly, Crankshaft tolerant 2d vectors", "keywords": [ "math", From 465ee12e021ad3c68245a2f73e3bb4af944f73e2 Mon Sep 17 00:00:00 2001 From: Vladimir Bykov Date: Sat, 18 Nov 2017 14:53:38 +0300 Subject: [PATCH 7/8] Update CHANGELOG.md --- CHANGELOG.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed47bff..dded8a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,28 +4,28 @@ ### Fixed -- Fixed Wrong .angleTo() computing #41 +- Fixed Wrong .angleTo() computing [#41](https://github.com/broadsw0rd/vectory/issues/41) ## [1.2.1] - 2017-09-04 ### Added -- Support of es6 [pkg.module](https://github.com/rollup/rollup/wiki/pkg.module) #38 +- Support of es6 [pkg.module](https://github.com/rollup/rollup/wiki/pkg.module) [#38](https://github.com/broadsw0rd/vectory/issues/38) ## [1.2.0] - 2017-08-29 ### Added -- Implemented vector rotation #34 +- Implemented vector rotation [#34](https://github.com/broadsw0rd/vectory/issues/34) - `Vector.rotate(theta, vector)` - `Vector.prototype.rotate(theta)` - `Vector.irotate(theta, vector)` - `Vector.prototype.irotate(theta)` -- Implemented alias `Vector#clone()` for `Vector#copy()` #35 +- Implemented alias `Vector#clone()` for `Vector#copy()` [#35](https://github.com/broadsw0rd/vectory/issues/35) -- Implemented filter for benchmark #29 +- Implemented filter for benchmark [#29](https://github.com/broadsw0rd/vectory/issues/29) ``` npm run behch -- --filter add @@ -35,7 +35,7 @@ list of available filters: `create`, `add`, `sub`, `mul`, `div`, `lerp`, `norm`, ### Fixed -- Fixed vectors' equality: implemented usage of `Number.EPSILON` #36 +- Fixed vectors' equality: implemented usage of `Number.EPSILON` [#36](https://github.com/broadsw0rd/vectory/issues/36) ### Removed From 7c5103490f9ae03307c0b0ba2436f7e7f0a1f9f5 Mon Sep 17 00:00:00 2001 From: Vladimir Bykov Date: Sat, 18 Nov 2017 14:59:38 +0300 Subject: [PATCH 8/8] Only latest node in CI --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 69eaec2..92ca091 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: node_js node_js: - - '4' - - '5' - - '6' - - '7' - '8' + - '9' after_script: - npm run coveralls \ No newline at end of file