Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 51fee0f

Browse files
committedMar 17, 2017
first commit
0 parents  commit 51fee0f

16 files changed

+4079
-0
lines changed
 

‎.eslintrc.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"rules": {
4+
"comma-dangle": 0,
5+
"no-console": 0,
6+
"no-constant-condition": 0,
7+
"semi": 1
8+
},
9+
"parserOptions": {
10+
"ecmaVersion": 6,
11+
"sourceType": "module",
12+
"ecmaFeatures": {
13+
"jsx": true
14+
}
15+
},
16+
"env": {
17+
"browser": true,
18+
"node": true,
19+
"es6": true,
20+
"mocha": true
21+
},
22+
"plugins": [
23+
],
24+
"globals": {
25+
"deprecate": false,
26+
"helper": false,
27+
"tap": false,
28+
"unused": false
29+
}
30+
}

‎.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# mac-osx files
2+
.DS_store
3+
profile
4+
5+
# visual-studio files
6+
*.ncb *.sln
7+
*.suo
8+
*.vcproj.*.user
9+
*.pdb
10+
*.idb
11+
*.csproj
12+
*.csproj.user
13+
14+
# visual-studio code
15+
.vscode/
16+
17+
# exvim files
18+
*.err
19+
*.exvim
20+
.exvim.*/
21+
22+
# webstorm
23+
.idea
24+
25+
# log files
26+
*.log
27+
28+
# project files
29+
node_modules/
30+
bower_components/

‎LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2016-2017 Johnny Wu
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## vmath
2+
3+
Yet another gl-matrix but smaller (without SIMD) and faster (use Hidden class instead of Float32Array).
4+
5+
## Why?
6+
7+
TODO
8+
9+
## Install
10+
11+
```bash
12+
npm install vmath
13+
```
14+
15+
## Documentation
16+
17+
TODO

‎dist/vmath.dev.js

Lines changed: 741 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/vmath.dev.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/vmath.js

Lines changed: 740 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/vmath.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './lib/utils';
2+
export { default as vec2 } from './lib/vec2';

‎lib/utils.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
const _d2r = Math.PI / 180.0;
2+
const _r2d = 180.0 / Math.PI;
3+
4+
/**
5+
* @property {number} EPSILON
6+
*/
7+
export const EPSILON = 0.000001;
8+
9+
/**
10+
* Tests whether or not the arguments have approximately the same value, within an absolute
11+
* or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less
12+
* than or equal to 1.0, and a relative tolerance is used for larger values)
13+
*
14+
* @param {Number} a The first number to test.
15+
* @param {Number} b The second number to test.
16+
* @returns {Boolean} True if the numbers are approximately equal, false otherwise.
17+
*/
18+
export function equals(a, b) {
19+
return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));
20+
}
21+
22+
/**
23+
* Tests whether or not the arguments have approximately the same value by given maxDiff
24+
*
25+
* @param {Number} a The first number to test.
26+
* @param {Number} b The second number to test.
27+
* @param {Number} maxDiff Maximum difference.
28+
* @returns {Boolean} True if the numbers are approximately equal, false otherwise.
29+
*/
30+
export function approx(a, b, maxDiff) {
31+
maxDiff = maxDiff || EPSILON;
32+
return Math.abs(a - b) <= maxDiff;
33+
}
34+
35+
/**
36+
* Clamps a value between a minimum float and maximum float value.
37+
*
38+
* @method clamp
39+
* @param {number} val
40+
* @param {number} min
41+
* @param {number} max
42+
* @return {number}
43+
*/
44+
export function clamp(val, min, max) {
45+
return val < min ? min : val > max ? max : val;
46+
}
47+
48+
/**
49+
* Clamps a value between 0 and 1.
50+
*
51+
* @method clamp01
52+
* @param {number} val
53+
* @return {number}
54+
*/
55+
export function clamp01(val) {
56+
return val < 0 ? 0 : val > 1 ? 1 : val;
57+
}
58+
59+
/**
60+
* Returns true if argument is a power-of-two and false otherwise.
61+
*
62+
* @method powof2
63+
* @param {number} x Number to check for power-of-two property.
64+
* @returns {boolean} true if power-of-two and false otherwise.
65+
*/
66+
export function powof2(x) {
67+
return ((x !== 0) && !(x & (x - 1)));
68+
}
69+
70+
/**
71+
* @method lerp
72+
* @param {number} from
73+
* @param {number} to
74+
* @param {number} ratio - the interpolation coefficient
75+
* @return {number}
76+
*/
77+
export function lerp(from, to, ratio) {
78+
return from + (to - from) * ratio;
79+
}
80+
81+
/**
82+
* Convert Degree To Radian
83+
*
84+
* @param {Number} a Angle in Degrees
85+
*/
86+
export function toRadian(a) {
87+
return a * _d2r;
88+
}
89+
90+
/**
91+
* Convert Radian To Degree
92+
*
93+
* @param {Number} a Angle in Radian
94+
*/
95+
export function toDegree(a) {
96+
return a * _r2d;
97+
}
98+
99+
/**
100+
* @method random
101+
*/
102+
export const random = Math.random;
103+
104+
/**
105+
* Returns a floating-point random number between min (inclusive) and max (exclusive).
106+
*
107+
* @method randomRange
108+
* @param {number} min
109+
* @param {number} max
110+
* @return {number} the random number
111+
*/
112+
export function randomRange(min, max) {
113+
return Math.random() * (max - min) + min;
114+
}
115+
116+
/**
117+
* Returns a random integer between min (inclusive) and max (exclusive).
118+
*
119+
* @method randomRangeInt
120+
* @param {number} min
121+
* @param {number} max
122+
* @return {number} the random integer
123+
*/
124+
export function randomRangeInt(min, max) {
125+
return Math.floor(this.randomRange(min, max));
126+
}

‎lib/vec2.js

Lines changed: 591 additions & 0 deletions
Large diffs are not rendered by default.

‎package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "vmath",
3+
"version": "1.0.0",
4+
"description": "Yet another gl-matrix: faster and smaller",
5+
"main": "dist/vmath.js",
6+
"scripts": {
7+
"build": "rollup --config ./script/rollup.config.js",
8+
"min": "uglifyjs ./dist/vmath.dev.js --source-map ./dist/vmath.min.js.map -o ./dist/vmath.min.js",
9+
"release": "npm run build && npm run min",
10+
"test": "npm run build && tap test/*.spec.js"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/gamedev-js/vmath.git"
15+
},
16+
"keywords": [
17+
"math",
18+
"algebre",
19+
"vector",
20+
"matrix"
21+
],
22+
"author": "jwu",
23+
"license": "MIT",
24+
"bugs": {
25+
"url": "https://github.com/gamedev-js/vmath/issues"
26+
},
27+
"homepage": "https://github.com/gamedev-js/vmath/issues",
28+
"dependencies": {},
29+
"devDependencies": {
30+
"fs-jetpack": "^0.13.0",
31+
"rollup": "^0.41.4",
32+
"tap": "^10.3.0",
33+
"uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony"
34+
}
35+
}

‎script/rollup.config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const fsJetpack = require('fs-jetpack');
4+
const pjson = require('../package.json');
5+
6+
let banner = `
7+
/*
8+
* ${pjson.name} v${pjson.version}
9+
* (c) ${new Date().getFullYear()} @Johnny Wu
10+
* Released under the MIT License.
11+
*/
12+
`;
13+
14+
let dest = './dist';
15+
let file = 'vmath';
16+
let moduleName = 'vmath';
17+
18+
// clear directory
19+
fsJetpack.dir(dest, { empty: true });
20+
21+
module.exports = {
22+
entry: './index.js',
23+
targets: [
24+
{ dest: `${dest}/${file}.dev.js`, format: 'iife' },
25+
{ dest: `${dest}/${file}.js`, format: 'cjs' },
26+
],
27+
moduleName,
28+
banner,
29+
external: [],
30+
globals: {},
31+
sourceMap: true,
32+
};

‎test/tap.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const tap = require('tap');
2+
3+
tap.Test.prototype.addAssert('approx', 3, function (found, wanted, maxDifferent, message, extra ) {
4+
let diff = Math.abs(found - wanted);
5+
6+
maxDifferent = maxDifferent || 0.0001;
7+
message = message || `should be approximate (${maxDifferent})`;
8+
9+
if ( diff <= maxDifferent ) {
10+
return this.pass(message, extra);
11+
}
12+
13+
extra.found = found;
14+
extra.wanted = wanted;
15+
extra.compare = '~=';
16+
17+
return this.fail(message, extra);
18+
});
19+
20+
tap.Test.prototype.addAssert('notApprox', 3, function (found, wanted, maxDifferent, message, extra ) {
21+
let diff = Math.abs(found - wanted);
22+
23+
maxDifferent = maxDifferent || 0.0001;
24+
message = message || `should be not approximate (${maxDifferent})`;
25+
26+
if ( diff > maxDifferent ) {
27+
return this.pass(message, extra);
28+
}
29+
30+
extra.found = found;
31+
extra.wanted = wanted;
32+
extra.compare = '!~=';
33+
34+
return this.fail(message, extra);
35+
});
36+
37+
module.exports = tap;

‎test/vec2.spec.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const tap = require('./tap');
2+
const {vec2} = require('../dist/vmath');
3+
4+
tap.test('vec2', t => {
5+
let out, vecA, vecB, result;
6+
7+
t.beforeEach(done => {
8+
vecA = vec2.fromValues(1,2);
9+
vecB = vec2.fromValues(3,4);
10+
out = vec2.fromValues(0,0);
11+
12+
done();
13+
});
14+
15+
t.test('create', t => {
16+
result = vec2.create();
17+
t.equal(result.x, 0.0);
18+
t.equal(result.y, 0.0);
19+
20+
t.end();
21+
});
22+
23+
t.test('clone', t => {
24+
result = vec2.clone(vecA);
25+
t.deepEqual(result, vecA);
26+
27+
t.end();
28+
});
29+
30+
t.test('fromValues', t => {
31+
result = vec2.fromValues(1, 2);
32+
t.equal(result.x, 1);
33+
t.equal(result.y, 2);
34+
35+
t.end();
36+
});
37+
38+
t.test('copy', t => {
39+
result = vec2.copy(out, vecA);
40+
t.deepEqual(result, vecA);
41+
t.deepEqual(out, vecA);
42+
43+
t.end();
44+
});
45+
46+
t.test('set', t => {
47+
result = vec2.set(out, 1, 2);
48+
t.equal(result.x, 1);
49+
t.equal(result.y, 2);
50+
t.equal(out.x, 1);
51+
t.equal(out.y, 2);
52+
53+
t.end();
54+
});
55+
56+
t.end();
57+
});

‎yarn.lock

Lines changed: 1619 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.