From a14c5e01d7151169ae8c5031469d9902164bdf80 Mon Sep 17 00:00:00 2001 From: moajo Date: Thu, 12 Oct 2017 13:17:14 +0900 Subject: [PATCH 01/38] [fix] change reference path --- src/Converters/Angle2DConverter.ts | 2 +- src/Converters/Color3Converter.ts | 2 +- src/Converters/Color4Converter.ts | 2 +- src/Converters/NumberArrayConverter.ts | 2 +- src/Converters/Rotation3Converter.ts | 24 ++++++++++++------------ src/Converters/Vector2Converter.ts | 2 +- src/Converters/Vector3Converter.ts | 2 +- src/Converters/Vector4Converter.ts | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Converters/Angle2DConverter.ts b/src/Converters/Angle2DConverter.ts index 7c23fb2..a3eb70f 100644 --- a/src/Converters/Angle2DConverter.ts +++ b/src/Converters/Angle2DConverter.ts @@ -1,6 +1,6 @@ import gr from "grimoirejs"; import Angle2DParser from "../Util/Angle2DParser"; -import Attribute from "grimoirejs/ref/Node/Attribute"; +import Attribute from "grimoirejs/ref/Core/Attribute"; function Angle2DConverter(this: Attribute, val: any): any { if (typeof val === "number") { return val; diff --git a/src/Converters/Color3Converter.ts b/src/Converters/Color3Converter.ts index 93a439c..bcd6f5b 100644 --- a/src/Converters/Color3Converter.ts +++ b/src/Converters/Color3Converter.ts @@ -1,5 +1,5 @@ import gr from "grimoirejs"; -import Attribute from "grimoirejs/ref/Node/Attribute"; +import Attribute from "grimoirejs/ref/Core/Attribute"; import Color3 from "../Color3"; import Color4 from "../Color4"; function Color3Converter(this: Attribute, val: any): any { diff --git a/src/Converters/Color4Converter.ts b/src/Converters/Color4Converter.ts index e3ac401..d2963fe 100644 --- a/src/Converters/Color4Converter.ts +++ b/src/Converters/Color4Converter.ts @@ -1,5 +1,5 @@ import gr from "grimoirejs"; -import Attribute from "grimoirejs/ref/Node/Attribute"; +import Attribute from "grimoirejs/ref/Core/Attribute"; import Color3 from "../Color3"; import Color4 from "../Color4"; diff --git a/src/Converters/NumberArrayConverter.ts b/src/Converters/NumberArrayConverter.ts index 2967da2..3243023 100644 --- a/src/Converters/NumberArrayConverter.ts +++ b/src/Converters/NumberArrayConverter.ts @@ -1,4 +1,4 @@ -import Attribute from "grimoirejs/ref/Node/Attribute"; +import Attribute from "grimoirejs/ref/Core/Attribute"; function NumberArrayConverter(this: Attribute, val: any): any { if(typeof val === "string"){ return new Float32Array(val.split(",").map(f=>parseFloat(f))); diff --git a/src/Converters/Rotation3Converter.ts b/src/Converters/Rotation3Converter.ts index 26c95ea..87758ab 100644 --- a/src/Converters/Rotation3Converter.ts +++ b/src/Converters/Rotation3Converter.ts @@ -1,18 +1,18 @@ import gr from "grimoirejs"; -import Attribute from "grimoirejs/ref/Node/Attribute"; +import Attribute from "grimoirejs/ref/Core/Attribute"; import Quaternion from "../Quaternion"; function Rotation3Converter(this: Attribute, val: any): any { - if (val instanceof Quaternion) { - return val; - } else if (Array.isArray(val)) { - return val.length === 4 ? new Quaternion([val[0], val[1], val[2], val[3]]) : Quaternion.euler(val[0],val[1],val[2]); - } else if (typeof val === "string") { - return Quaternion.parse(val); - } else if(!!val && val[0] !== void 0 && val[1] !== void 0 && val[2] !== void 0 && val[3] !== void 0){ - return new Quaternion([val[0],val[1],val[2],val[3]]); - } else if(!!val && val.X !== void 0 && val.Y !== void 0 && val.Z !== void 0 && val.W !== void 0){ - return new Quaternion([val.X,val.Y,val.Z,val.W]); - } + if (val instanceof Quaternion) { + return val; + } else if (Array.isArray(val)) { + return val.length === 4 ? new Quaternion([val[0], val[1], val[2], val[3]]) : Quaternion.euler(val[0], val[1], val[2]); + } else if (typeof val === "string") { + return Quaternion.parse(val); + } else if (!!val && val[0] !== void 0 && val[1] !== void 0 && val[2] !== void 0 && val[3] !== void 0) { + return new Quaternion([val[0], val[1], val[2], val[3]]); + } else if (!!val && val.X !== void 0 && val.Y !== void 0 && val.Z !== void 0 && val.W !== void 0) { + return new Quaternion([val.X, val.Y, val.Z, val.W]); + } } export default Rotation3Converter; diff --git a/src/Converters/Vector2Converter.ts b/src/Converters/Vector2Converter.ts index 3e85a82..6fff6b4 100644 --- a/src/Converters/Vector2Converter.ts +++ b/src/Converters/Vector2Converter.ts @@ -1,5 +1,5 @@ import gr from "grimoirejs"; -import Attribute from "grimoirejs/ref/Node/Attribute"; +import Attribute from "grimoirejs/ref/Core/Attribute"; import Vector2 from "../Vector2"; function Vector2Converter(this: Attribute, val: any): any { if (val instanceof Vector2) { diff --git a/src/Converters/Vector3Converter.ts b/src/Converters/Vector3Converter.ts index 3150586..ce5c1ed 100644 --- a/src/Converters/Vector3Converter.ts +++ b/src/Converters/Vector3Converter.ts @@ -1,5 +1,5 @@ import gr from "grimoirejs"; -import Attribute from "grimoirejs/ref/Node/Attribute"; +import Attribute from "grimoirejs/ref/Core/Attribute"; import Vector3 from "../Vector3"; function Vector3Converter(this: Attribute, val: any): any { diff --git a/src/Converters/Vector4Converter.ts b/src/Converters/Vector4Converter.ts index 141f65a..60c6c0c 100644 --- a/src/Converters/Vector4Converter.ts +++ b/src/Converters/Vector4Converter.ts @@ -1,5 +1,5 @@ import gr from "grimoirejs"; -import Attribute from "grimoirejs/ref/Node/Attribute"; +import Attribute from "grimoirejs/ref/Core/Attribute"; import Vector4 from "../Vector4"; function Vector4Converter(this: Attribute, val: any): any { if (val instanceof Vector4) { From fa8f7ac486d6ad7e7ca0a79020ff7b85ae82acda Mon Sep 17 00:00:00 2001 From: moajo Date: Thu, 12 Oct 2017 13:34:48 +0900 Subject: [PATCH 02/38] [fix] add lint --- .gitmodules | 3 +++ common | 1 + package.json | 5 ++++- src/Converters/Angle2DConverter.ts | 2 +- src/Converters/Color4Converter.ts | 2 +- src/Converters/NumberArrayConverter.ts | 18 +++++++++--------- src/Converters/Vector2Converter.ts | 6 +++--- src/Converters/Vector3Converter.ts | 8 ++++---- src/Converters/Vector4Converter.ts | 8 ++++---- tslint.json | 8 ++++++++ 10 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 .gitmodules create mode 160000 common create mode 100644 tslint.json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..5afd887 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "common"] + path = common + url = git@github.com:GrimoireGL/common-configurations.git diff --git a/common b/common new file mode 160000 index 0000000..27e461c --- /dev/null +++ b/common @@ -0,0 +1 @@ +Subproject commit 27e461cebf2bef9779777f79a0ba732457b24c67 diff --git a/package.json b/package.json index b4af466..e545cc9 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "grimoirejs-cauldron": "^3.1.6", "semantic-release": "^7.0.2", "ts-loader": "^2.3.3", + "tslint": "^5.7.0", "typedoc": "^0.8.0", "typescript": "^2.4.2", "webpack": "^3.5.5", @@ -44,6 +45,8 @@ "test": "tsc --outDir ./lib && babel ./lib --presets es2015 --plugins transform-runtime --out-dir ./lib-es5 && babel ./test --presets es2015 --plugins transform-runtime --out-dir ./test-es5 && ava ./test-es5/**/*Test.js --verbose ", "prepublish": "npm run build -- --env.prod&& npm test", "start": "webpack --progress --watch", + "lint": "tslint -c tslint.json ./src/**/*.ts --project ./ --type-check --exclude ./src/index.ts", + "lint:fix": "tslint -c tslint.json ./src/**/*.ts --project ./ --type-check --exclude ./src/index.ts --fix", "build": "webpack --progress", "generate-expose": "cauldron generate-exposure --src ./src --dest ./src/index.ts --ts --main ./src/main.ts --dts ./ref", "generate-reference": "cauldron generate-reference --src ./src --dest ./src/index.ts --ts --main ./src/main.ts --dts ./ref", @@ -54,5 +57,5 @@ "release": { "verifyConditions": "condition-circle" }, - "api-reference":"https://api.grimoire.gl/grimoirejs-math" + "api-reference": "https://api.grimoire.gl/grimoirejs-math" } diff --git a/src/Converters/Angle2DConverter.ts b/src/Converters/Angle2DConverter.ts index a3eb70f..309f945 100644 --- a/src/Converters/Angle2DConverter.ts +++ b/src/Converters/Angle2DConverter.ts @@ -1,6 +1,6 @@ import gr from "grimoirejs"; -import Angle2DParser from "../Util/Angle2DParser"; import Attribute from "grimoirejs/ref/Core/Attribute"; +import Angle2DParser from "../Util/Angle2DParser"; function Angle2DConverter(this: Attribute, val: any): any { if (typeof val === "number") { return val; diff --git a/src/Converters/Color4Converter.ts b/src/Converters/Color4Converter.ts index d2963fe..035d426 100644 --- a/src/Converters/Color4Converter.ts +++ b/src/Converters/Color4Converter.ts @@ -7,7 +7,7 @@ function Color4Converter(this: Attribute, val: any): any { if (val instanceof Color4) { return val; } else if (val instanceof Color3) { - return new Color4(val.R, val.G, val.B, 1.0); + return new Color4(val.R, val.G, val.B, 1); } else if (typeof val === "string") { return Color4.parse(val); } else if (Array.isArray(val)) { diff --git a/src/Converters/NumberArrayConverter.ts b/src/Converters/NumberArrayConverter.ts index 3243023..bca7fc5 100644 --- a/src/Converters/NumberArrayConverter.ts +++ b/src/Converters/NumberArrayConverter.ts @@ -1,12 +1,12 @@ import Attribute from "grimoirejs/ref/Core/Attribute"; function NumberArrayConverter(this: Attribute, val: any): any { - if(typeof val === "string"){ - return new Float32Array(val.split(",").map(f=>parseFloat(f))); - }else if(Array.isArray(val)){ - return new Float32Array(val); - }else if(val instanceof Float32Array){ - return val; - } + if (typeof val === "string") { + return new Float32Array(val.split(",").map(parseFloat)); + } else if (Array.isArray(val)) { + return new Float32Array(val); + } else if (val instanceof Float32Array) { + return val; } - - export default NumberArrayConverter; \ No newline at end of file +} + +export default NumberArrayConverter; diff --git a/src/Converters/Vector2Converter.ts b/src/Converters/Vector2Converter.ts index 6fff6b4..1087c82 100644 --- a/src/Converters/Vector2Converter.ts +++ b/src/Converters/Vector2Converter.ts @@ -10,10 +10,10 @@ function Vector2Converter(this: Attribute, val: any): any { return new Vector2(val, val); } else if (Array.isArray(val)) { return new Vector2(val[0], val[1]); - }else if(val[0] !== void 0 && val[1] !== void 0){ + } else if (val[0] !== void 0 && val[1] !== void 0) { return new Vector2(val[0], val[1]); - } else if(val.X !== void 0 && val.Y !== void 0){ - return new Vector2(val.X,val.Y); + } else if (val.X !== void 0 && val.Y !== void 0) { + return new Vector2(val.X, val.Y); } } diff --git a/src/Converters/Vector3Converter.ts b/src/Converters/Vector3Converter.ts index ce5c1ed..b7741cf 100644 --- a/src/Converters/Vector3Converter.ts +++ b/src/Converters/Vector3Converter.ts @@ -7,14 +7,14 @@ function Vector3Converter(this: Attribute, val: any): any { return val; } else if (typeof val === "string") { return Vector3.parse(val); // TODO: to do not throws execptions. - } else if (typeof val == "number") { + } else if (typeof val === "number") { return new Vector3(val, val, val); } else if (Array.isArray(val)) { return new Vector3(val[0], val[1], val[2]); - } else if(val[0] !== void 0 && val[1] !== void 0 && val[2] !== void 0){ + } else if (val[0] !== void 0 && val[1] !== void 0 && val[2] !== void 0) { return new Vector3(val[0], val[1], val[2]); - } else if(val.X !== void 0 && val.Y !== void 0 && val.Z !== void 0){ - return new Vector3(val.X,val.Y,val.Z); + } else if (val.X !== void 0 && val.Y !== void 0 && val.Z !== void 0) { + return new Vector3(val.X, val.Y, val.Z); } } diff --git a/src/Converters/Vector4Converter.ts b/src/Converters/Vector4Converter.ts index 60c6c0c..b9a04e7 100644 --- a/src/Converters/Vector4Converter.ts +++ b/src/Converters/Vector4Converter.ts @@ -10,10 +10,10 @@ function Vector4Converter(this: Attribute, val: any): any { return new Vector4(val, val, val, val); } else if (Array.isArray(val)) { return new Vector4(val[0], val[1], val[2], val[3]); - } else if(!!val && val[0] !== void 0 && val[1] !== void 0 && val[2] !== void 0 && val[3] !== void 0){ - return new Vector4(val[0], val[1], val[2],val[3]); - } else if(!!val && val.X !== void 0 && val.Y !== void 0 && val.Z !== void 0 && val.W !== void 0){ - return new Vector4(val.X,val.Y,val.Z,val.W); + } else if (!!val && val[0] !== void 0 && val[1] !== void 0 && val[2] !== void 0 && val[3] !== void 0) { + return new Vector4(val[0], val[1], val[2], val[3]); + } else if (!!val && val.X !== void 0 && val.Y !== void 0 && val.Z !== void 0 && val.W !== void 0) { + return new Vector4(val.X, val.Y, val.Z, val.W); } } diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..f230b5d --- /dev/null +++ b/tslint.json @@ -0,0 +1,8 @@ +{ + "extends": "./common/tslint.json", + "rulesDirectory": [], + "rules": { + "no-unused-variable": false, + "match-default-export-name": false + } +} \ No newline at end of file From 6b22123234a4d54a090ab8ba449764fb18bbbfe3 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Sat, 16 Dec 2017 18:43:21 +0900 Subject: [PATCH 03/38] Adopt common-configuration environment --- .gitmodules | 3 +++ circle.yml | 27 ++++++++------------------- common | 1 + doc-timestamp.js | 24 ------------------------ package.json | 6 +++--- tsconfig.json | 45 --------------------------------------------- 6 files changed, 15 insertions(+), 91 deletions(-) create mode 100644 .gitmodules create mode 160000 common delete mode 100644 doc-timestamp.js delete mode 100644 tsconfig.json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0ac1b7d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "common"] + path = common + url = https://github.com/GrimoireGL/common-configurations.git diff --git a/circle.yml b/circle.yml index 4815380..d419f0c 100644 --- a/circle.yml +++ b/circle.yml @@ -1,29 +1,18 @@ -machine: - node: - version: 6.9.5 - - post: - - curl -o- -L https://yarnpkg.com/install.sh | bash - -dependencies: - cache_directories: - - "~/.cache/yarn" - - pre: - - yarn --version - - override: - - yarn install - test: post: - sh release.sh override: - npm run build && npm test - + - sh ./common/e2e.sh +checkout: + post: + - git submodule init + - git submodule update deployment: deploy: branch: master commands: - npm run doc - - aws s3 cp ./docs/ s3://api.grimoire.gl/$CIRCLE_PROJECT_REPONAME --recursive --acl public-read + - >- + aws s3 cp ./docs/ s3://api.grimoire.gl/$CIRCLE_PROJECT_REPONAME + --recursive --acl public-read diff --git a/common b/common new file mode 160000 index 0000000..7cb3fe2 --- /dev/null +++ b/common @@ -0,0 +1 @@ +Subproject commit 7cb3fe2bcbbea238e4090024820ff7c2c3213187 diff --git a/doc-timestamp.js b/doc-timestamp.js deleted file mode 100644 index 11e7ea4..0000000 --- a/doc-timestamp.js +++ /dev/null @@ -1,24 +0,0 @@ -const fs = require("fs"); - -fs.readFile("./package.json","utf8",(err,data)=>{ - if(err){ - console.error(err); - process.exit(1); - }else{ - const version = JSON.parse(data).version; - fs.readFile("./README.md","utf8",(err,original)=>{ - if(err){ - console.error(err); - process.exit(1); - }else{ - const replaced = original.replace("",`* Update date: \`${new Date()}\`\n* Build version: \`${version}\``); - fs.writeFile("./README.md",replaced,(err,data)=>{ - if(err){ - console.error(err); - process.exit(1); - } - }); - } - }); - } -}); \ No newline at end of file diff --git a/package.json b/package.json index b4af466..29f48b8 100644 --- a/package.json +++ b/package.json @@ -48,11 +48,11 @@ "generate-expose": "cauldron generate-exposure --src ./src --dest ./src/index.ts --ts --main ./src/main.ts --dts ./ref", "generate-reference": "cauldron generate-reference --src ./src --dest ./src/index.ts --ts --main ./src/main.ts --dts ./ref", "semantic-release": "semantic-release pre && npm publish && semantic-release post", - "doc": "node ./doc-timestamp.js && typedoc --out ./docs/ --options typedoc.json ./tsconfig.json" + "doc": "node ./common/doc-timestamp.js && typedoc --out ./docs/ --options ./common/typedoc.json ./tsconfig.json" }, "license": "MIT", "release": { "verifyConditions": "condition-circle" }, - "api-reference":"https://api.grimoire.gl/grimoirejs-math" -} + "api-reference": "https://api.grimoire.gl/grimoirejs-math" +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 0e7366f..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "compilerOptions": { - "target": "es6", - "module": "es6", - "noImplicitAny": false, - "outDir": "lib", - "declarationDir": "ref", - "declaration": true, - "moduleResolution": "node" - }, - "filesGlob": [ - "./src/**/*.ts" - ], - "files": [ - "./src/AABB.ts", - "./src/Color3.ts", - "./src/Color4.ts", - "./src/Colors.ts", - "./src/Converters/Angle2DConverter.ts", - "./src/Converters/Color3Converter.ts", - "./src/Converters/Color4Converter.ts", - "./src/Converters/Rotation3Converter.ts", - "./src/Converters/Vector2Converter.ts", - "./src/Converters/Vector3Converter.ts", - "./src/Converters/Vector4Converter.ts", - "./src/gl-matrix.d.ts", - "./src/GLM.ts", - "./src/index.ts", - "./src/IVectorParseDescription.ts", - "./src/main.ts", - "./src/Matrix.ts", - "./src/MatrixBase.ts", - "./src/Quaternion.ts", - "./src/Rectangle.ts", - "./src/Util/Angle2DParser.ts", - "./src/Vector2.ts", - "./src/Vector3.ts", - "./src/Vector4.ts", - "./src/VectorBase.ts" - ], - "exclude": [], - "atom": { - "rewriteTsconfig": true - } -} From d8ec349d881c5dab9b9c7a27e6f660b7c3cce78d Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Sat, 16 Dec 2017 18:51:31 +0900 Subject: [PATCH 04/38] Adopt core1.0 beta --- .gitignore | 1 + package.json | 6 +++--- release.sh | 6 ------ src/metaInfo.ts | 13 +++++++++++++ tsconfig.json | 45 +++++++++++++++++++++++++++++++++++++++++++++ tslint.json | 8 -------- typedoc.json | 9 --------- 7 files changed, 62 insertions(+), 26 deletions(-) delete mode 100644 release.sh create mode 100644 src/metaInfo.ts create mode 100644 tsconfig.json delete mode 100644 tslint.json delete mode 100644 typedoc.json diff --git a/.gitignore b/.gitignore index 310d796..7fb3746 100644 --- a/.gitignore +++ b/.gitignore @@ -115,3 +115,4 @@ register yarn.lock src/index.ts docs +package-lock.json \ No newline at end of file diff --git a/package.json b/package.json index 6cda8b7..4b7c615 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,8 @@ "babel-preset-es2015": "^6.24.1", "babel-preset-stage-2": "^6.24.1", "condition-circle": "^1.5.0", - "grimoirejs": "^0.19.5", - "grimoirejs-cauldron": "^3.1.6", + "grimoirejs": "beta", + "grimoirejs-cauldron": "beta", "semantic-release": "^7.0.2", "ts-loader": "^2.3.3", "tslint": "^5.7.0", @@ -58,4 +58,4 @@ "verifyConditions": "condition-circle" }, "api-reference": "https://api.grimoire.gl/grimoirejs-math" -} \ No newline at end of file +} diff --git a/release.sh b/release.sh deleted file mode 100644 index 0915df2..0000000 --- a/release.sh +++ /dev/null @@ -1,6 +0,0 @@ -npm run semantic-release -if [ $? = "0" ]; then - echo PRESET_UPDATE - curl "https://preset-updater.herokuapp.com/?repo=preset-basic&repoURL=https://github.com/GrimoireGL/grimoirejs-preset-basic.git&buildNumber=$CIRCLE_BUILD_NUM¤tPkg=grimoirejs-math" -fi -exit 0 diff --git a/src/metaInfo.ts b/src/metaInfo.ts new file mode 100644 index 0000000..8962df1 --- /dev/null +++ b/src/metaInfo.ts @@ -0,0 +1,13 @@ +/* + * this file is generated by grimoirejs-cauldron + */ + +// build version +export const __VERSION__ = "1.14.0-beta1"; + +// full package name +export const __NAME__ = "grimoirejs-math"; + +const shortening = /^[Gg]rimoire(?:js|JS)?-(.*)$/.exec(__NAME__); +// dafault registerd namespace +export const __NAMESPACE__ = shortening ? shortening[1] : __NAME__; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..7c38bce --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,45 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "es6", + "noImplicitAny": false, + "outDir": "lib", + "declarationDir": "ref", + "declaration": true, + "moduleResolution": "node" + }, + "filesGlob": [ + "./src/**/*.ts" + ], + "files": [ + "./src/AABB.ts", + "./src/Color3.ts", + "./src/Color4.ts", + "./src/Colors.ts", + "./src/Converters/Angle2DConverter.ts", + "./src/Converters/Color3Converter.ts", + "./src/Converters/Color4Converter.ts", + "./src/Converters/Rotation3Converter.ts", + "./src/Converters/Vector2Converter.ts", + "./src/Converters/Vector3Converter.ts", + "./src/Converters/Vector4Converter.ts", + "./src/gl-matrix.d.ts", + "./src/GLM.ts", + "./src/index.ts", + "./src/IVectorParseDescription.ts", + "./src/main.ts", + "./src/Matrix.ts", + "./src/MatrixBase.ts", + "./src/Quaternion.ts", + "./src/Rectangle.ts", + "./src/Util/Angle2DParser.ts", + "./src/Vector2.ts", + "./src/Vector3.ts", + "./src/Vector4.ts", + "./src/VectorBase.ts" + ], + "exclude": [], + "atom": { + "rewriteTsconfig": true + } +} \ No newline at end of file diff --git a/tslint.json b/tslint.json deleted file mode 100644 index f230b5d..0000000 --- a/tslint.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "./common/tslint.json", - "rulesDirectory": [], - "rules": { - "no-unused-variable": false, - "match-default-export-name": false - } -} \ No newline at end of file diff --git a/typedoc.json b/typedoc.json deleted file mode 100644 index 7a2094c..0000000 --- a/typedoc.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "mode": "file", - "moduleResolution": "node", - "tsconfig": "tsconfig.json", - "includeDeclarations": true, - "ignoreCompilerErrors": true, - "excludePrivate": true, - "excludeExternals": true -} From b638c79696648696ed9d8c3588b81453152abbd2 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Sat, 16 Dec 2017 18:54:57 +0900 Subject: [PATCH 05/38] fix node version --- circle.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/circle.yml b/circle.yml index d419f0c..e3c3ffe 100644 --- a/circle.yml +++ b/circle.yml @@ -1,3 +1,6 @@ +machine: + node: + version: 9.3.0 test: post: - sh release.sh From 164360b9ddd744c12bdca64f75e7a16c0cf08090 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Sat, 16 Dec 2017 18:59:16 +0900 Subject: [PATCH 06/38] Revert removing release.sh --- release.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 release.sh diff --git a/release.sh b/release.sh new file mode 100644 index 0000000..705a319 --- /dev/null +++ b/release.sh @@ -0,0 +1,6 @@ +npm run semantic-release +if [ $? = "0" ]; then + echo PRESET_UPDATE + curl "https://preset-updater.herokuapp.com/?repo=preset-basic&repoURL=https://github.com/GrimoireGL/grimoirejs-preset-basic.git&buildNumber=$CIRCLE_BUILD_NUM¤tPkg=grimoirejs-math" +fi +exit 0 \ No newline at end of file From c1c9872f5f012519b57562049a1ec87760ed3c52 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Sat, 16 Dec 2017 19:26:38 +0900 Subject: [PATCH 07/38] Adopt core1.0 --- .gitignore | 1 + package.json | 4 ++-- src/metaInfo.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7fb3746..899a23d 100644 --- a/.gitignore +++ b/.gitignore @@ -114,5 +114,6 @@ ref register yarn.lock src/index.ts +src/metaInfo.ts docs package-lock.json \ No newline at end of file diff --git a/package.json b/package.json index 4b7c615..b1f547e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grimoirejs-math", - "version": "1.14.0-beta1", + "version": "2.0.0", "description": "The basement library for math of grimoire.js", "main": "./ref/index.js", "typings": "./ref/index.d.ts", @@ -58,4 +58,4 @@ "verifyConditions": "condition-circle" }, "api-reference": "https://api.grimoire.gl/grimoirejs-math" -} +} \ No newline at end of file diff --git a/src/metaInfo.ts b/src/metaInfo.ts index 8962df1..6561fe6 100644 --- a/src/metaInfo.ts +++ b/src/metaInfo.ts @@ -3,7 +3,7 @@ */ // build version -export const __VERSION__ = "1.14.0-beta1"; +export const __VERSION__ = "2.0.0"; // full package name export const __NAME__ = "grimoirejs-math"; From fb376d6104a85c33927bd990db1acf7d19d97683 Mon Sep 17 00:00:00 2001 From: moajo Date: Thu, 4 Jan 2018 15:14:59 +0900 Subject: [PATCH 08/38] chore: remove metaInfo.ts --- package.json | 4 ++-- src/metaInfo.ts | 13 ------------- 2 files changed, 2 insertions(+), 15 deletions(-) delete mode 100644 src/metaInfo.ts diff --git a/package.json b/package.json index b1f547e..fa9189f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grimoirejs-math", - "version": "2.0.0", + "version": "2.0.6-beta", "description": "The basement library for math of grimoire.js", "main": "./ref/index.js", "typings": "./ref/index.d.ts", @@ -58,4 +58,4 @@ "verifyConditions": "condition-circle" }, "api-reference": "https://api.grimoire.gl/grimoirejs-math" -} \ No newline at end of file +} diff --git a/src/metaInfo.ts b/src/metaInfo.ts deleted file mode 100644 index 6561fe6..0000000 --- a/src/metaInfo.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * this file is generated by grimoirejs-cauldron - */ - -// build version -export const __VERSION__ = "2.0.0"; - -// full package name -export const __NAME__ = "grimoirejs-math"; - -const shortening = /^[Gg]rimoire(?:js|JS)?-(.*)$/.exec(__NAME__); -// dafault registerd namespace -export const __NAMESPACE__ = shortening ? shortening[1] : __NAME__; From ae5cc6e279fad820c7dfd6ee66619fe947067d1c Mon Sep 17 00:00:00 2001 From: moajo Date: Sun, 21 Jan 2018 03:20:26 +0900 Subject: [PATCH 09/38] fix: refactor and change converter declarations --- package.json | 11 +- src/AABB.ts | 17 +- src/Color3.ts | 21 +- src/Color4.ts | 19 +- src/Converters/Angle2DConverter.ts | 19 +- src/Converters/Color3Converter.ts | 26 +- src/Converters/Color4Converter.ts | 25 +- src/Converters/NumberArrayConverter.ts | 12 - src/Converters/Rotation3Converter.ts | 29 +- src/Converters/Vector2Converter.ts | 33 +- src/Converters/Vector3Converter.ts | 31 +- src/Converters/Vector4Converter.ts | 32 +- src/GLM.ts | 19 +- src/IVectorParseDescription.ts | 5 +- src/Matrix.ts | 63 +- src/MatrixBase.ts | 28 +- src/Quaternion.ts | 63 +- src/Rectangle.ts | 32 +- src/Util/Angle2DParser.ts | 3 +- src/Vector2.ts | 34 +- src/Vector3.ts | 38 +- src/Vector4.ts | 38 +- src/VectorBase.ts | 30 +- src/gl-matrix.d.ts | 2169 ------------------------ src/main.ts | 16 +- test/MatrixTest.js | 4 +- test/NumberArrayTest.js | 28 - test/QuaternionTest.js | 42 +- tsconfig.json | 43 +- 29 files changed, 352 insertions(+), 2578 deletions(-) delete mode 100644 src/Converters/NumberArrayConverter.ts delete mode 100644 src/gl-matrix.d.ts delete mode 100644 test/NumberArrayTest.js diff --git a/package.json b/package.json index fa9189f..58a274c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grimoirejs-math", - "version": "2.0.6-beta", + "version": "2.1.0-beta", "description": "The basement library for math of grimoire.js", "main": "./ref/index.js", "typings": "./ref/index.d.ts", @@ -14,9 +14,10 @@ "grimoire" ], "dependencies": { - "gl-matrix": "https://github.com/GrimoireGL/gl-matrix.git" + "gl-matrix": "git+https://github.com/GrimoireGL/gl-matrix.git" }, "devDependencies": { + "@types/gl-matrix": "^2.4.0", "ava": "^0.22.0", "babel-cli": "^6.26.0", "babel-loader": "^7.1.2", @@ -24,13 +25,13 @@ "babel-preset-es2015": "^6.24.1", "babel-preset-stage-2": "^6.24.1", "condition-circle": "^1.5.0", - "grimoirejs": "beta", - "grimoirejs-cauldron": "beta", + "grimoirejs": "^1.0.9-beta17", + "grimoirejs-cauldron": "^4.1.5-beta2", "semantic-release": "^7.0.2", "ts-loader": "^2.3.3", "tslint": "^5.7.0", "typedoc": "^0.8.0", - "typescript": "^2.4.2", + "typescript": "^2.6.2", "webpack": "^3.5.5", "webpack-shell-plugin": "^0.5.0" }, diff --git a/src/AABB.ts b/src/AABB.ts index 87295d6..c998961 100644 --- a/src/AABB.ts +++ b/src/AABB.ts @@ -1,14 +1,15 @@ -/// + import Vector3 from "./Vector3"; +import { Nullable } from "grimoirejs/ref/Tool/Types"; /** * Axis-Aligned Bounding Box implementation */ -class AABB { +export default class AABB { constructor(initialPoints?: Vector3[]) { if (initialPoints) { - initialPoints.forEach(f => this.expand(f)); + initialPoints.forEach(this.expand); } } /** @@ -27,7 +28,7 @@ class AABB { * Center of this AABB * @type {Vector3} */ - private _center: Vector3; + private _center: Nullable; /** * Width of this AABB @@ -76,10 +77,8 @@ class AABB { * Clean up this AABB with initial value. */ public clear(): void { - this.pointLBF = null; - this.pointRTN = null; + delete this.pointLBF; + delete this.pointRTN; this._center = null; } -} - -export default AABB; +} \ No newline at end of file diff --git a/src/Color3.ts b/src/Color3.ts index 190ec64..fefa46d 100644 --- a/src/Color3.ts +++ b/src/Color3.ts @@ -1,15 +1,15 @@ -/// - import VectorBase from "./VectorBase"; import Vector3 from "./Vector3"; import Color4 from "./Color4"; import Vector4 from "./Vector4"; import Colors from "./Colors"; +import { Undef } from "grimoirejs/ref/Tool/Types"; +import { vec3 } from "gl-matrix"; /** * Represents 3-component color without alpha. */ -class Color3 extends VectorBase { +export default class Color3 extends VectorBase { /** * Convert Color4 to Color3. @@ -25,7 +25,7 @@ class Color3 extends VectorBase { * @param {boolean} tryParse Internal use. Please use undefined always. * @return {Color3} Converted Color3 value */ - public static parse(color: string, tryParse?: boolean): Color3 { + public static parse(color: string, tryParse?: boolean): Undef { return Color3.internalParse(color, true, tryParse); } @@ -37,9 +37,9 @@ class Color3 extends VectorBase { * @param {boolean} tryParse [description] * @return {Color3} [description] */ - public static internalParse(color: string, isFirst: boolean, tryParse?: boolean): Color3 { - if (isFirst && Colors[color]) { - const col = Color4.internalParse(Colors[color], false, tryParse); + public static internalParse(color: string, isFirst: boolean, tryParse?: boolean): Undef { + if (isFirst && (Colors as any)[color]) { + const col = Color4.internalParse((Colors as any)[color], false, tryParse)!; return Color3.fromColor4(col); } let m; @@ -95,7 +95,7 @@ class Color3 extends VectorBase { */ constructor(r: number, g: number, b: number) { super(); - this.rawElements = [r, g, b]; + this.rawElements = vec3.fromValues(r, g, b); } /** @@ -173,7 +173,4 @@ class Color3 extends VectorBase { st += Math.round(this.B * 0xff).toString(16).toUpperCase(); return `Color3(${this.R}, ${this.G}, ${this.B}, ${st})`; } -} - - -export default Color3; +} \ No newline at end of file diff --git a/src/Color4.ts b/src/Color4.ts index 787e229..0741f8b 100644 --- a/src/Color4.ts +++ b/src/Color4.ts @@ -1,19 +1,20 @@ -/// - import VectorBase from "./VectorBase"; import Vector4 from "./Vector4"; import Colors from "./Colors"; +import { Undef } from "grimoirejs/ref/Tool/Types"; +import { vec4 } from "gl-matrix"; + /** * Represents 4-components color. */ -class Color4 extends VectorBase { +export default class Color4 extends VectorBase { /** * Internal use. Do not call this manually. */ - public static internalParse(color: string, isFirst: boolean, tryParse?: boolean): Color4 { - if (isFirst && Colors[color]) { - return Color4.internalParse(Colors[color], false); + public static internalParse(color: string, isFirst: boolean, tryParse?: boolean): Undef { + if (isFirst && (Colors as any)[color]) { + return Color4.internalParse((Colors as any)[color], false); } let m; if (isFirst) { @@ -87,7 +88,7 @@ class Color4 extends VectorBase { * @param {boolean} tryParse Internal use. Please use undefined always. * @return {Color4} Instance of Color4 generated by the expression. */ - public static parse(color: string, tryParse?: boolean): Color4 { + public static parse(color: string, tryParse?: boolean): Undef { return Color4.internalParse(color, true, tryParse); } @@ -110,7 +111,7 @@ class Color4 extends VectorBase { */ constructor(r: number, g: number, b: number, a: number) { super(); - this.rawElements = [r, g, b, a]; + this.rawElements = vec4.fromValues(r, g, b, a); } /** @@ -182,4 +183,4 @@ class Color4 extends VectorBase { } } -export default Color4; + diff --git a/src/Converters/Angle2DConverter.ts b/src/Converters/Angle2DConverter.ts index 309f945..e94ca68 100644 --- a/src/Converters/Angle2DConverter.ts +++ b/src/Converters/Angle2DConverter.ts @@ -1,12 +1,19 @@ import gr from "grimoirejs"; import Attribute from "grimoirejs/ref/Core/Attribute"; import Angle2DParser from "../Util/Angle2DParser"; -function Angle2DConverter(this: Attribute, val: any): any { - if (typeof val === "number") { - return val; - } - if (typeof val === "string") { - return Angle2DParser.parseAngle(val); +import { Undef } from "grimoirejs/ref/Tool/Types"; + + +export const Angle2DConverter = { + name: "Angle2D", + convert(val: any): Undef { + if (typeof val === "number") { + return val; + } + if (typeof val === "string") { + return Angle2DParser.parseAngle(val); + } + return undefined; } } diff --git a/src/Converters/Color3Converter.ts b/src/Converters/Color3Converter.ts index bcd6f5b..583d8ad 100644 --- a/src/Converters/Color3Converter.ts +++ b/src/Converters/Color3Converter.ts @@ -2,17 +2,21 @@ import gr from "grimoirejs"; import Attribute from "grimoirejs/ref/Core/Attribute"; import Color3 from "../Color3"; import Color4 from "../Color4"; -function Color3Converter(this: Attribute, val: any): any { - if (val instanceof Color3) { - return val; - } else if (val instanceof Color4) { - return new Color3(val.R, val.G, val.B); - } else if (typeof val === "string") { - return Color3.parse(val); - } else if (Array.isArray(val)) { - return new Color3(val[0], val[1], val[2]); - } else { - return null; +import { Undef } from "grimoirejs/ref/Tool/Types"; + +export const Color3Converter = { + name: "Color3", + convert(val: any): Undef { + if (val instanceof Color3) { + return val; + } else if (val instanceof Color4) { + return new Color3(val.R, val.G, val.B); + } else if (typeof val === "string") { + return Color3.parse(val); + } else if (Array.isArray(val)) { + return new Color3(val[0], val[1], val[2]); + } + return undefined; } } diff --git a/src/Converters/Color4Converter.ts b/src/Converters/Color4Converter.ts index 035d426..bb68c3c 100644 --- a/src/Converters/Color4Converter.ts +++ b/src/Converters/Color4Converter.ts @@ -2,18 +2,21 @@ import gr from "grimoirejs"; import Attribute from "grimoirejs/ref/Core/Attribute"; import Color3 from "../Color3"; import Color4 from "../Color4"; +import { Undef } from "grimoirejs/ref/Tool/Types"; -function Color4Converter(this: Attribute, val: any): any { - if (val instanceof Color4) { - return val; - } else if (val instanceof Color3) { - return new Color4(val.R, val.G, val.B, 1); - } else if (typeof val === "string") { - return Color4.parse(val); - } else if (Array.isArray(val)) { - return new Color4(val[0], val[1], val[2], val[3]); - } else { - return null; +export const Color4Converter = { + name: "Color4", + convert(val: any): Undef { + if (val instanceof Color4) { + return val; + } else if (val instanceof Color3) { + return new Color4(val.R, val.G, val.B, 1); + } else if (typeof val === "string") { + return Color4.parse(val); + } else if (Array.isArray(val)) { + return new Color4(val[0], val[1], val[2], val[3]); + } + return undefined; } } diff --git a/src/Converters/NumberArrayConverter.ts b/src/Converters/NumberArrayConverter.ts deleted file mode 100644 index bca7fc5..0000000 --- a/src/Converters/NumberArrayConverter.ts +++ /dev/null @@ -1,12 +0,0 @@ -import Attribute from "grimoirejs/ref/Core/Attribute"; -function NumberArrayConverter(this: Attribute, val: any): any { - if (typeof val === "string") { - return new Float32Array(val.split(",").map(parseFloat)); - } else if (Array.isArray(val)) { - return new Float32Array(val); - } else if (val instanceof Float32Array) { - return val; - } -} - -export default NumberArrayConverter; diff --git a/src/Converters/Rotation3Converter.ts b/src/Converters/Rotation3Converter.ts index 87758ab..1245db1 100644 --- a/src/Converters/Rotation3Converter.ts +++ b/src/Converters/Rotation3Converter.ts @@ -1,17 +1,24 @@ import gr from "grimoirejs"; import Attribute from "grimoirejs/ref/Core/Attribute"; import Quaternion from "../Quaternion"; -function Rotation3Converter(this: Attribute, val: any): any { - if (val instanceof Quaternion) { - return val; - } else if (Array.isArray(val)) { - return val.length === 4 ? new Quaternion([val[0], val[1], val[2], val[3]]) : Quaternion.euler(val[0], val[1], val[2]); - } else if (typeof val === "string") { - return Quaternion.parse(val); - } else if (!!val && val[0] !== void 0 && val[1] !== void 0 && val[2] !== void 0 && val[3] !== void 0) { - return new Quaternion([val[0], val[1], val[2], val[3]]); - } else if (!!val && val.X !== void 0 && val.Y !== void 0 && val.Z !== void 0 && val.W !== void 0) { - return new Quaternion([val.X, val.Y, val.Z, val.W]); +import { Undef } from "grimoirejs/ref/Tool/Types"; + + +export const Rotation3Converter = { + name: "Rotation3", + convert(val: any): Undef { + if (val instanceof Quaternion) { + return val; + } else if (Array.isArray(val)) { + return val.length === 4 ? new Quaternion(val[0], val[1], val[2], val[3]) : Quaternion.euler(val[0], val[1], val[2]); + } else if (typeof val === "string") { + return Quaternion.parse(val); + } else if (!!val && val[0] !== void 0 && val[1] !== void 0 && val[2] !== void 0 && val[3] !== void 0) { + return new Quaternion(val[0], val[1], val[2], val[3]); + } else if (!!val && val.X !== void 0 && val.Y !== void 0 && val.Z !== void 0 && val.W !== void 0) { + return new Quaternion(val.X, val.Y, val.Z, val.W); + } + return undefined; } } diff --git a/src/Converters/Vector2Converter.ts b/src/Converters/Vector2Converter.ts index 1087c82..0040441 100644 --- a/src/Converters/Vector2Converter.ts +++ b/src/Converters/Vector2Converter.ts @@ -1,19 +1,26 @@ import gr from "grimoirejs"; import Attribute from "grimoirejs/ref/Core/Attribute"; import Vector2 from "../Vector2"; -function Vector2Converter(this: Attribute, val: any): any { - if (val instanceof Vector2) { - return val; - } else if (typeof val === "string") { - return Vector2.parse(val); - } else if (typeof val === "number") { - return new Vector2(val, val); - } else if (Array.isArray(val)) { - return new Vector2(val[0], val[1]); - } else if (val[0] !== void 0 && val[1] !== void 0) { - return new Vector2(val[0], val[1]); - } else if (val.X !== void 0 && val.Y !== void 0) { - return new Vector2(val.X, val.Y); +import { Undef } from "grimoirejs/ref/Tool/Types"; + + +export const Vector2Converter = { + name: "Vector2", + convert(val: any): Undef { + if (val instanceof Vector2) { + return val; + } else if (typeof val === "string") { + return Vector2.parse(val); + } else if (typeof val === "number") { + return new Vector2(val, val); + } else if (Array.isArray(val)) { + return new Vector2(val[0], val[1]); + } else if (val[0] !== void 0 && val[1] !== void 0) { + return new Vector2(val[0], val[1]); + } else if (val.X !== void 0 && val.Y !== void 0) { + return new Vector2(val.X, val.Y); + } + return undefined; } } diff --git a/src/Converters/Vector3Converter.ts b/src/Converters/Vector3Converter.ts index b7741cf..87ed8d3 100644 --- a/src/Converters/Vector3Converter.ts +++ b/src/Converters/Vector3Converter.ts @@ -1,20 +1,25 @@ import gr from "grimoirejs"; import Attribute from "grimoirejs/ref/Core/Attribute"; import Vector3 from "../Vector3"; +import { Undef } from "grimoirejs/ref/Tool/Types"; -function Vector3Converter(this: Attribute, val: any): any { - if (val instanceof Vector3) { - return val; - } else if (typeof val === "string") { - return Vector3.parse(val); // TODO: to do not throws execptions. - } else if (typeof val === "number") { - return new Vector3(val, val, val); - } else if (Array.isArray(val)) { - return new Vector3(val[0], val[1], val[2]); - } else if (val[0] !== void 0 && val[1] !== void 0 && val[2] !== void 0) { - return new Vector3(val[0], val[1], val[2]); - } else if (val.X !== void 0 && val.Y !== void 0 && val.Z !== void 0) { - return new Vector3(val.X, val.Y, val.Z); +export const Vector3Converter = { + name: "Vector3", + convert(this: Attribute, val: any): Undef { + if (val instanceof Vector3) { + return val; + } else if (typeof val === "string") { + return Vector3.parse(val); // TODO: to do not throws execptions. + } else if (typeof val === "number") { + return new Vector3(val, val, val); + } else if (Array.isArray(val)) { + return new Vector3(val[0], val[1], val[2]); + } else if (val[0] !== void 0 && val[1] !== void 0 && val[2] !== void 0) { + return new Vector3(val[0], val[1], val[2]); + } else if (val.X !== void 0 && val.Y !== void 0 && val.Z !== void 0) { + return new Vector3(val.X, val.Y, val.Z); + } + return undefined; } } diff --git a/src/Converters/Vector4Converter.ts b/src/Converters/Vector4Converter.ts index b9a04e7..e73f3d7 100644 --- a/src/Converters/Vector4Converter.ts +++ b/src/Converters/Vector4Converter.ts @@ -1,19 +1,25 @@ import gr from "grimoirejs"; import Attribute from "grimoirejs/ref/Core/Attribute"; import Vector4 from "../Vector4"; -function Vector4Converter(this: Attribute, val: any): any { - if (val instanceof Vector4) { - return val; - } else if (typeof val === "string") { - return Vector4.parse(val); - } else if (typeof val === "number") { - return new Vector4(val, val, val, val); - } else if (Array.isArray(val)) { - return new Vector4(val[0], val[1], val[2], val[3]); - } else if (!!val && val[0] !== void 0 && val[1] !== void 0 && val[2] !== void 0 && val[3] !== void 0) { - return new Vector4(val[0], val[1], val[2], val[3]); - } else if (!!val && val.X !== void 0 && val.Y !== void 0 && val.Z !== void 0 && val.W !== void 0) { - return new Vector4(val.X, val.Y, val.Z, val.W); +import { Undef } from "grimoirejs/ref/Tool/Types"; + +export const Vector4Converter = { + name: "Vector4", + convert(this: Attribute, val: any): Undef { + if (val instanceof Vector4) { + return val; + } else if (typeof val === "string") { + return Vector4.parse(val); + } else if (typeof val === "number") { + return new Vector4(val, val, val, val); + } else if (Array.isArray(val)) { + return new Vector4(val[0], val[1], val[2], val[3]); + } else if (!!val && val[0] !== void 0 && val[1] !== void 0 && val[2] !== void 0 && val[3] !== void 0) { + return new Vector4(val[0], val[1], val[2], val[3]); + } else if (!!val && val.X !== void 0 && val.Y !== void 0 && val.Z !== void 0 && val.W !== void 0) { + return new Vector4(val.X, val.Y, val.Z, val.W); + } + return undefined; } } diff --git a/src/GLM.ts b/src/GLM.ts index c44c31c..cb274dd 100644 --- a/src/GLM.ts +++ b/src/GLM.ts @@ -1,12 +1,13 @@ -import {GLM, vec2, vec3, vec4, glMatrix, mat2d, mat3, mat4, quat } from "gl-matrix"; + +import { vec2, vec3, vec4, glMatrix, mat2d, mat3, mat4, quat } from "gl-matrix"; export default { - vec2: vec2, - vec3: vec3, - vec4: vec4, - glMatrix: glMatrix, - mat2d: mat2d, - mat3: mat3, - mat4: mat4, - quat: quat + vec2, + vec3, + vec4, + glMatrix, + mat2d, + mat3, + mat4, + quat, }; diff --git a/src/IVectorParseDescription.ts b/src/IVectorParseDescription.ts index 660a71e..7576dd9 100644 --- a/src/IVectorParseDescription.ts +++ b/src/IVectorParseDescription.ts @@ -1,7 +1,6 @@ -interface IVectorParseDescription { +export default interface IVectorParseDescription { needNormalize: boolean; needNegate: boolean; - coefficient: number; + coefficient?: number; elements: number[]; } -export default IVectorParseDescription; diff --git a/src/Matrix.ts b/src/Matrix.ts index 8027d52..a701fa9 100644 --- a/src/Matrix.ts +++ b/src/Matrix.ts @@ -1,20 +1,20 @@ -/// + import MatrixBase from "./MatrixBase"; import Vector3 from "./Vector3"; import Vector4 from "./Vector4"; import Quaternion from "./Quaternion"; -import {GLM, mat4, vec3, vec4, quat} from "gl-matrix"; +import { mat4, vec3, vec4, quat } from "gl-matrix"; /** * Represents 4x4 matrix. */ -class Matrix extends MatrixBase { +export default class Matrix extends MatrixBase { /** * Instanciate zero matrix. */ public static zero(): Matrix { - return new Matrix([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + return new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } /** @@ -28,8 +28,8 @@ class Matrix extends MatrixBase { * Instanciate matrix in row major. * @return {Matrix} [description] */ - public static fromElements(m00:number, m01:number, m02:number, m03:number, m10:number, m11:number, m12:number, m13:number, m20:number, m21:number, m22:number, m23:number, m30:number, m31:number, m32:number, m33:number): Matrix { - return new Matrix([m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33]); + public static fromElements(m00: number, m01: number, m02: number, m03: number, m10: number, m11: number, m12: number, m13: number, m20: number, m21: number, m22: number, m23: number, m30: number, m31: number, m32: number, m33: number): Matrix { + return new Matrix(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33); } /** @@ -38,7 +38,7 @@ class Matrix extends MatrixBase { * @return {[type]} A matrix instance. */ public static fromFunc(f: (w: number, h: number) => number): Matrix { - return new Matrix([f(0, 0), f(1, 0), f(2, 0), f(3, 0), f(0, 1), f(1, 1), f(2, 1), f(3, 1), f(0, 2), f(1, 2), f(2, 2), f(3, 2), f(0, 3), f(1, 3), f(2, 3), f(3, 3)]); + return new Matrix(f(0, 0), f(1, 0), f(2, 0), f(3, 0), f(0, 1), f(1, 1), f(2, 1), f(3, 1), f(0, 2), f(1, 2), f(2, 2), f(3, 2), f(0, 3), f(1, 3), f(2, 3), f(3, 3)); } /** @@ -62,7 +62,7 @@ class Matrix extends MatrixBase { for (let i = 0; i < 16; i++) { mat[i] = m1.rawElements[i] + m2.rawElements[i]; } - return new Matrix(mat); + return new Matrix(mat4.add(mat, m1.rawElements, m2.rawElements)); } /** @@ -72,7 +72,8 @@ class Matrix extends MatrixBase { * @return {Matrix} The result of calculation. */ public static subtract(m1: Matrix, m2: Matrix): Matrix { - return Matrix.add(m1, Matrix.negate(m2)); + const mat = mat4.create(); + return new Matrix(mat4.subtract(mat, m1.rawElements, m2.rawElements)); } /** @@ -83,8 +84,7 @@ class Matrix extends MatrixBase { */ public static scalarMultiply(s: number, m: Matrix): Matrix { const newMat = mat4.create(); - mat4.multiply(newMat, [s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, 0, 0, 0, s], m.rawElements); - return new Matrix(newMat); + return new Matrix(mat4.multiplyScalar(newMat, m.rawElements, s)); } /** @@ -176,9 +176,13 @@ class Matrix extends MatrixBase { /** * Compute inverted passed matrix. */ - public static inverse(m: Matrix): Matrix { + public static inverse(m: Matrix): Matrix | null { const newMat = mat4.create(); - return new Matrix(mat4.invert(newMat, m.rawElements)); + const mat = mat4.invert(newMat, m.rawElements) + if (!mat) { + return null; + } + return new Matrix(mat); } /** @@ -308,12 +312,16 @@ class Matrix extends MatrixBase { * Constructor to generate an instance * @param {GLM.IArray} arr Array of components */ - constructor(arr?: GLM.IArray) { + constructor(arr?: mat4) + constructor(m00: number, m01: number, m02: number, m03: number, m10: number, m11: number, m12: number, m13: number, m20: number, m21: number, m22: number, m23: number, m30: number, m31: number, m32: number, m33: number); + constructor(m00?: number | mat4, m01?: number, m02?: number, m03?: number, m10?: number, m11?: number, m12?: number, m13?: number, m20?: number, m21?: number, m22?: number, m23?: number, m30?: number, m31?: number, m32?: number, m33?: number) { super(); - if (arr) { - this.rawElements = arr; - } else { + if (m00 === undefined) { this.rawElements = mat4.create(); + } else if (m01 === undefined) { + this.rawElements = m00 as mat4; + } else { + this.rawElements = mat4.fromValues(m00 as number, m01!, m02!, m03!, m10!, m11!, m12!, m13!, m20!, m21!, m22!, m23!, m30!, m31!, m32!, m33!); } } @@ -387,7 +395,7 @@ class Matrix extends MatrixBase { * @return {Vector3} Translation represented in vector */ public getTranslation(): Vector3 { - const res = [0, 0, 0]; + const res = vec3.create(); mat4.getTranslation(res, this.rawElements); return new Vector3(res); } @@ -397,9 +405,7 @@ class Matrix extends MatrixBase { * @return {Vector3} Scaling represented in vector */ public getScaling(): Vector3 { - const res = [0, 0, 0]; - mat4.getScaling(res, this.rawElements); - return new Vector3(res); + return new Vector3(mat4.getScaling(vec3.create(), this.rawElements)); } /** @@ -407,10 +413,10 @@ class Matrix extends MatrixBase { * @return {Quaternion} Rotation represented in quaternion */ public getRotation(): Quaternion { - const res = [0, 0, 0, 0]; + const res = quat.fromValues(0, 0, 0, 1); const invScale = this.getScaling(); - mat4.getRotation(res, this.multiplyWith(Matrix.scale(new Vector3(1/invScale.X,1/invScale.Y,1/invScale.Z))).rawElements); - return new Quaternion(res); + mat4.getRotation(res, this.multiplyWith(Matrix.scale(new Vector3(1 / invScale.X, 1 / invScale.Y, 1 / invScale.Z))).rawElements); + return new Quaternion(res[0], res[1], res[2], res[3]); } /** @@ -427,17 +433,16 @@ class Matrix extends MatrixBase { * Element count of this matrix. Must be 16. * @return {number} [description] */ - public get ElementCount(): number { return 16; } + public get ElementCount(): 16 { return 16; } /** * Row count of this matrix. Must be 4. */ - public get RowCount(): number { return 4; } + public get RowCount(): 4 { return 4; } /** * Column count of this matrix. Must be 4. */ - public get ColmunCount(): number { return 4; } - + public get ColmunCount(): 4 { return 4; } } -export default Matrix; + diff --git a/src/MatrixBase.ts b/src/MatrixBase.ts index ab3fbaa..05a6131 100644 --- a/src/MatrixBase.ts +++ b/src/MatrixBase.ts @@ -1,11 +1,9 @@ -/// -import {GLM} from "gl-matrix"; -class MatrixBase { +export default abstract class MatrixBase { - public rawElements: GLM.IArray; + public rawElements: T; - protected static __elementEquals(m1: MatrixBase, m2: MatrixBase): boolean { + protected static __elementEquals(m1: MatrixBase, m2: MatrixBase): boolean { if (m1.RowCount !== m2.RowCount || m1.ColmunCount !== m2.ColmunCount) { return false; } @@ -18,20 +16,10 @@ class MatrixBase { return true; } - public get RowCount(): number { - return 0; - } - - public get ColmunCount(): number { - return 0; - } + abstract get RowCount(): number; + abstract get ColmunCount(): number; - public getAt(row: number, colmun: number): number { - throw new Error("Not implemented"); - } - - public getBySingleIndex(index: number): number { - throw new Error("Not implemented"); - } + abstract getAt(row: number, colmun: number): number; + abstract getBySingleIndex(index: number): number; } -export default MatrixBase; + diff --git a/src/Quaternion.ts b/src/Quaternion.ts index 0b3f794..ba59d62 100644 --- a/src/Quaternion.ts +++ b/src/Quaternion.ts @@ -1,9 +1,8 @@ -/// - import Vector3 from "./Vector3"; -import {GLM, vec3, quat} from "gl-matrix"; +import { vec3, quat } from "gl-matrix"; import Matrix from "./Matrix"; import Angle2DParser from "./Util/Angle2DParser"; +import { Undef } from "grimoirejs/ref/Tool/Types"; /** * The class to maniplate quaternion. @@ -14,9 +13,9 @@ import Angle2DParser from "./Util/Angle2DParser"; * (w;x,y,z) means w*1+x*i+y*j+z*k * */ -class Quaternion { +export default class Quaternion { - public rawElements: GLM.IArray; + public rawElements: quat; public static equals(q1: Quaternion, q2: Quaternion): boolean { for (let i = 0; i < 4; i++) { @@ -39,14 +38,14 @@ class Quaternion { * @param input the string to be parsed as angle in 3D. * @returns {Quaternion} parsed rotation in Quaternion. */ - public static parse(input: string): Quaternion { + public static parse(input: string): Undef { const reg1 = /^ *(x|y|z) *\(([^\(\)]+)\) *$/gm; const reg2 = /^ *axis *\(([^\(\),]+),([^\(\),]+),([^\(\),]+),([^\(\),]+)\) *$/gm; const reg3 = /^ *([^\(\),]+),([^\(\),]+),([^\(\),]+) *$/gm; const result = reg1.exec(input); if (result) { const angle = Angle2DParser.parseAngle(result[2]); - if(angle === void 0){ + if (angle === void 0) { return undefined; } if (result[1] === "x") { @@ -65,7 +64,7 @@ class Quaternion { let x = parseFloat(res2[2]); let y = parseFloat(res2[3]); let z = parseFloat(res2[4]); - if(rotation === undefined){ + if (rotation === undefined) { return undefined; } return Quaternion.angleAxis(rotation, new Vector3(x, y, z)); @@ -75,11 +74,12 @@ class Quaternion { const x = Angle2DParser.parseAngle(res3[1]); const y = Angle2DParser.parseAngle(res3[2]); const z = Angle2DParser.parseAngle(res3[3]); - if(x === undefined || y === undefined || z === undefined){ + if (x === undefined || y === undefined || z === undefined) { return undefined; } return Quaternion.euler(x, y, z); } + return undefined; } @@ -89,8 +89,9 @@ class Quaternion { */ public static add(q1: Quaternion, q2: Quaternion): Quaternion { const newQuat = quat.create(); + quat.add(newQuat, q1.rawElements, q2.rawElements) - return new Quaternion(quat.add(newQuat, q1.rawElements, q2.rawElements)); + return new Quaternion(newQuat[0], newQuat[1], newQuat[2], newQuat[3]); } /** @@ -98,7 +99,8 @@ class Quaternion { */ public static multiply(q1: Quaternion, q2: Quaternion): Quaternion { const newQuat = quat.create(); - return new Quaternion(quat.mul(newQuat, q1.rawElements, q2.rawElements)); + quat.mul(newQuat, q1.rawElements, q2.rawElements) + return new Quaternion(newQuat[0], newQuat[1], newQuat[2], newQuat[3]); } /** @@ -109,9 +111,10 @@ class Quaternion { axisVec[0] = axis.X; axisVec[1] = axis.Y; axisVec[2] = axis.Z; - vec3.normalize(axisVec,axisVec); + vec3.normalize(axisVec, axisVec); const newQuat = quat.create(); - return new Quaternion(quat.setAxisAngle(newQuat, axisVec, +angle)); + quat.setAxisAngle(newQuat, axisVec, +angle) + return new Quaternion(newQuat[0], newQuat[1], newQuat[2], newQuat[3]); } public static euler(x: number, y: number, z: number): Quaternion { @@ -125,7 +128,8 @@ class Quaternion { public static slerp(q1: Quaternion, q2: Quaternion, t: number): Quaternion { const newQuat = quat.create(); - return new Quaternion(quat.slerp(newQuat, q1.rawElements, q2.rawElements, +t)); + quat.slerp(newQuat, q1.rawElements, q2.rawElements, +t) + return new Quaternion(newQuat[0], newQuat[1], newQuat[2], newQuat[3]); } /** @@ -148,10 +152,10 @@ class Quaternion { * @param to * @param axisHint if no vector specified to this argument, [0,1,0] will be used for default */ - public static fromToRotation(from: Vector3, to: Vector3,axisHint:Vector3 = null): Quaternion { + public static fromToRotation(from: Vector3, to: Vector3, axisHint?: Vector3): Quaternion { let crossed = Vector3.cross(from.normalized, to.normalized); - if(crossed.magnitude < 0.5){ // If crossed vector magnitude is less than 1, that is from.to is 1 or -1 - crossed = axisHint?axisHint:new Vector3(0,1,0); + if (crossed.magnitude < 0.5) { // If crossed vector magnitude is less than 1, that is from.to is 1 or -1 + crossed = axisHint ? axisHint : new Vector3(0, 1, 0); } const angle = Math.acos(Vector3.dot(from.normalized, to.normalized)); return Quaternion.angleAxis(angle, crossed); @@ -176,29 +180,29 @@ class Quaternion { if (num8 > 0) { const num = Math.sqrt(1 + num8); - return new Quaternion([(m12 - m21) * 0.5 / num, (m20 - m02) * 0.5 / num, (m01 - m10) * 0.5 / num, num / 2]); + return new Quaternion((m12 - m21) * 0.5 / num, (m20 - m02) * 0.5 / num, (m01 - m10) * 0.5 / num, num / 2); } if (m00 >= m11 && m00 >= m22) { const num7 = Math.sqrt(1 + m00 - m11 - m22); - return new Quaternion([(m01 + m10) * 0.5 / num7, (m02 + m20) * 0.5 / num7, (m12 - m21) * 0.5 / num7, num7 / 2]); + return new Quaternion((m01 + m10) * 0.5 / num7, (m02 + m20) * 0.5 / num7, (m12 - m21) * 0.5 / num7, num7 / 2); } if (m11 > m22) { const num6 = Math.sqrt(1 + m11 - m00 - m22); - return new Quaternion([(m10 + m01) * 0.5 / num6, 0.5 * num6, (m21 + m12) * 0.5 / num6, (m20 - m02) * 0.5 / num6]); + return new Quaternion((m10 + m01) * 0.5 / num6, 0.5 * num6, (m21 + m12) * 0.5 / num6, (m20 - m02) * 0.5 / num6); } const num5 = Math.sqrt(1 + m22 - m00 - m11); - return new Quaternion([(m20 + m02) * 0.5 / num5, (m21 + m12) * 0.5 / num5, 0.5 * num5, (m01 - m10) * 0.5 / num5]); + return new Quaternion((m20 + m02) * 0.5 / num5, (m21 + m12) * 0.5 / num5, 0.5 * num5, (m01 - m10) * 0.5 / num5); } public static get Identity(): Quaternion { - return new Quaternion(quat.create()); + return new Quaternion(0, 0, 0, 1); } /** * Constructor by specifing each elements. */ - constructor(rawElements: GLM.IArray) { - this.rawElements = rawElements; + constructor(x: number, y: number, z: number, w: number) { + this.rawElements = quat.fromValues(x, y, z, w); } public get eularAngles() { @@ -251,7 +255,8 @@ class Quaternion { */ public get Conjugate(): Quaternion { const newQuat = quat.create(); - return new Quaternion(quat.conjugate(newQuat, this.rawElements)); + quat.conjugate(newQuat, this.rawElements) + return new Quaternion(newQuat[0], newQuat[1], newQuat[2], newQuat[3]); } /** @@ -270,13 +275,15 @@ class Quaternion { */ public normalize(): Quaternion { const newQuat = quat.create(); - return new Quaternion(quat.normalize(newQuat, this.rawElements)); + quat.normalize(newQuat, this.rawElements) + return new Quaternion(newQuat[0], newQuat[1], newQuat[2], newQuat[3]); } public inverse(): Quaternion { const newQuat = quat.create(); - return new Quaternion(quat.invert(newQuat, this.rawElements)); + quat.invert(newQuat, this.rawElements) + return new Quaternion(newQuat[0], newQuat[1], newQuat[2], newQuat[3]); } public toAngleAxisString(): string { @@ -328,5 +335,3 @@ class Quaternion { return result; } } - -export default Quaternion; diff --git a/src/Rectangle.ts b/src/Rectangle.ts index 8c6ad82..c04296c 100644 --- a/src/Rectangle.ts +++ b/src/Rectangle.ts @@ -1,5 +1,5 @@ import Vector2 from "./Vector2"; -class Rectangle { +export default class Rectangle { private _left: number; private _bottom: number; @@ -55,7 +55,7 @@ class Rectangle { } else { x = xOrPoint; } - return this.Left <= x && this.Right >= x && this.Top <= y && this.Bottom >= y; + return this.Left <= x && this.Right >= x && this.Top <= y! && this.Bottom >= y!; } /** @@ -63,7 +63,7 @@ class Rectangle { * @param {Vector2} x [description] * @return {Vector2} [description] */ - public toLocal(x: Vector2): Vector2; + public toLocal(point: Vector2): Vector2; public toLocal(x: number, y: number): number[]; public toLocal(xOrPoint: Vector2 | number, y?: number): any { let x; @@ -74,8 +74,8 @@ class Rectangle { x = xOrPoint; } x -= this.Left; - y -= this.Bottom; - return xOrPoint instanceof Vector2 ? new Vector2(x, y) : [x, y]; + y! -= this.Bottom; + return xOrPoint instanceof Vector2 ? new Vector2(x, y!) : [x, y]; } /** @@ -83,15 +83,15 @@ class Rectangle { * @param {Vector2} x [description] * @return {Vector2} [description] */ - public toLocalNormalized(x: Vector2): Vector2; + public toLocalNormalized(point: Vector2): Vector2; public toLocalNormalized(x: number, y: number): number[]; public toLocalNormalized(xOrPoint: Vector2 | number, y?: number): any { - if(xOrPoint instanceof Vector2){ + if (xOrPoint instanceof Vector2) { const v = this.toLocal(xOrPoint); return new Vector2(v.X / this.Width, v.Y / this.Height); - }else{ - const v = this.toLocal(xOrPoint,y); - return [v[0]/this.Width, v[1]/ this.Height]; + } else { + const v = this.toLocal(xOrPoint, y!); + return [v[0] / this.Width, v[1] / this.Height]; } } @@ -100,21 +100,17 @@ class Rectangle { * @param {Vector2} x [description] * @return {Vector2} [description] */ - public toAbsolute(x: Vector2): Vector2; + public toAbsolute(point: Vector2): Vector2; public toAbsolute(x: number, y: number): number[]; public toAbsolute(xOrPoint: Vector2 | number, y?: number): any { - if(xOrPoint instanceof Vector2){ + if (xOrPoint instanceof Vector2) { return new Vector2(xOrPoint.X + this.Left, xOrPoint.Y + this.Top); - }else{ - return [xOrPoint + this.Left, y + this.Top]; + } else { + return [xOrPoint + this.Left, y! + this.Top]; } } - - public toString(): string { return `Rectangle(${this.Left},${this.Top}-${this.Right},${this.Bottom})`; } - } -export default Rectangle; diff --git a/src/Util/Angle2DParser.ts b/src/Util/Angle2DParser.ts index 03aa108..15ef53e 100644 --- a/src/Util/Angle2DParser.ts +++ b/src/Util/Angle2DParser.ts @@ -1,3 +1,4 @@ + /** * Utility class to parse the arguments of attributes. */ @@ -9,7 +10,7 @@ export default class Angle2DParser { * @param input the string to parse. * @returns {number} parsed angle in radians. */ - public static parseAngle(input: string): number { + public static parseAngle(input: string): number | undefined { const regex = /^ *(-?[\de+-.]*) *(?:\/ *([\de+-.]*))? *(p|prad|deg|d|r|rad)? *$/gm; const result = regex.exec(input); diff --git a/src/Vector2.ts b/src/Vector2.ts index cbe8a3c..a7b21f7 100644 --- a/src/Vector2.ts +++ b/src/Vector2.ts @@ -1,8 +1,9 @@ -/// + import VectorBase from "./VectorBase"; -import {GLM, vec2} from "gl-matrix"; -class Vector2 extends VectorBase { +import { vec2 } from "gl-matrix"; +import { Undef } from "grimoirejs/ref/Tool/Types"; +export default class Vector2 extends VectorBase { public static get XUnit(): Vector2 { return new Vector2(1, 0); @@ -24,7 +25,7 @@ class Vector2 extends VectorBase { return new Vector2(vec.X, vec.Y); } - public static parse(str: string): Vector2 { + public static parse(str: string): Undef { const parseResult = VectorBase.__parse(str); const elements = parseResult.elements; if (elements.length !== 1 && elements.length !== 2) { @@ -85,11 +86,13 @@ class Vector2 extends VectorBase { } public static min(v1: Vector2, v2: Vector2): Vector2 { - return new Vector2(VectorBase.__fromGenerationFunction(v1, v2, (i, v1_, v2_) => Math.min(v1_.rawElements[i], v2_.rawElements[i]))); + const newVec = vec2.create(); + return new Vector2(vec2.min(newVec, v1.rawElements, v2.rawElements)); } public static max(v1: Vector2, v2: Vector2): Vector2 { - return new Vector2(VectorBase.__fromGenerationFunction(v1, v2, (i, v1_, v2_) => Math.max(v1_.rawElements[i], v2_.rawElements[i]))); + const newVec = vec2.create(); + return new Vector2(vec2.max(newVec, v1.rawElements, v2.rawElements)); } public static angle(v1: Vector2, v2: Vector2): number { @@ -97,20 +100,19 @@ class Vector2 extends VectorBase { } public static lerp(v1: Vector2, v2: Vector2, t: number): Vector2 { - return new Vector2(VectorBase.__fromGenerationFunction(v1, v2, (i, v1_, v2_) => { - return v1_.rawElements[i] + (v2_.rawElements[i] - v1_.rawElements[i]) * t; - })); + const newVec = vec2.create(); + return new Vector2(vec2.lerp(newVec, v1.rawElements, v2.rawElements, t)); } constructor(x: number, y: number); - constructor(x: GLM.IArray); - constructor(x: number | GLM.IArray, y?: number) { + constructor(x: vec2); + constructor(x: number | vec2, y?: number) { super(); - if (typeof y === "undefined") { - this.rawElements = x; + if (y === undefined) { + this.rawElements = x as vec2; return; } - this.rawElements = [x, y]; + this.rawElements = vec2.fromValues(x as number, y); } public get normalized() { @@ -173,7 +175,7 @@ class Vector2 extends VectorBase { return `Vector2${this.toString()}`; } - public get ElementCount(): number { return 2; } + public get ElementCount(): 2 { return 2; } } -export default Vector2; + diff --git a/src/Vector3.ts b/src/Vector3.ts index 92ca0f0..b1c095a 100644 --- a/src/Vector3.ts +++ b/src/Vector3.ts @@ -1,9 +1,9 @@ -/// + import VectorBase from "./VectorBase"; -import {GLM, vec3} from "gl-matrix"; +import { vec3 } from "gl-matrix"; -class Vector3 extends VectorBase { +export default class Vector3 extends VectorBase { public static get XUnit(): Vector3 { return new Vector3(1, 0, 0); @@ -72,17 +72,19 @@ class Vector3 extends VectorBase { public static min(v1: Vector3, v2: Vector3): Vector3 { - return new Vector3(VectorBase.__fromGenerationFunction(v1, v2, (i, _v1, _v2) => Math.min(_v1.rawElements[i], _v2.rawElements[i]))); + const newVec = vec3.create(); + return new Vector3(vec3.min(newVec, v1.rawElements, v2.rawElements)); } public static max(v1: Vector3, v2: Vector3): Vector3 { - return new Vector3(VectorBase.__fromGenerationFunction(v1, v2, (i, _v1, _v2) => Math.max(_v1.rawElements[i], _v2.rawElements[i]))); + const newVec = vec3.create(); + return new Vector3(vec3.max(newVec, v1.rawElements, v2.rawElements)); } public static angle(v1: Vector3, v2: Vector3): number { return Math.acos(Vector3.dot(v1.normalized, v2.normalized)); } - public static parse(str: string): Vector3 { + public static parse(str: string): Vector3 | undefined { const parseResult = VectorBase.__parse(str); const elements = parseResult.elements; @@ -107,21 +109,20 @@ class Vector3 extends VectorBase { return result; } - public static lerp(v1: Vector3,v2: Vector3, t: number): Vector3 { - return new Vector3(VectorBase.__fromGenerationFunction(v1, v2, (i, v1_, v2_) => { - return v1_.rawElements[i] + (v2_.rawElements[i] - v1_.rawElements[i]) * t; - })); + public static lerp(v1: Vector3, v2: Vector3, t: number): Vector3 { + const newVec = vec3.create(); + return new Vector3(vec3.lerp(newVec, v1.rawElements, v2.rawElements, t)); } constructor(x: number, y: number, z: number); - constructor(x: GLM.IArray); - constructor(x: number | GLM.IArray, y?: number, z?: number) { + constructor(x: vec3); + constructor(x: number | vec3, y?: number, z?: number) { super(); - if (typeof y === "undefined") { - this.rawElements = x; - return; + if (y === undefined) { + this.rawElements = x as vec3; + } else { + this.rawElements = vec3.fromValues(x as number, y, z!); } - this.rawElements = [x, y, z]; } public get normalized() { @@ -196,8 +197,5 @@ class Vector3 extends VectorBase { return `Vector3${this.toString()}`; } - public get ElementCount(): number { return 3; } - + public get ElementCount(): 3 { return 3; } } - -export default Vector3; diff --git a/src/Vector4.ts b/src/Vector4.ts index c052e24..950eb55 100644 --- a/src/Vector4.ts +++ b/src/Vector4.ts @@ -1,9 +1,8 @@ -/// - import VectorBase from "./VectorBase"; -import {GLM, vec4} from "gl-matrix"; +import { vec4 } from "gl-matrix"; +import { Undef } from "grimoirejs/ref/Tool/Types"; -class Vector4 extends VectorBase { +export default class Vector4 extends VectorBase { public static get XUnit(): Vector4 { return new Vector4(1, 0, 0, 0); @@ -71,18 +70,20 @@ class Vector4 extends VectorBase { public static min(v1: Vector4, v2: Vector4): Vector4 { - return new Vector4(VectorBase.__fromGenerationFunction(v1, v2, (i, _v1, _v2) => Math.min(_v1.rawElements[i], _v2.rawElements[i]))); + const newVec = vec4.create(); + return new Vector4(vec4.min(newVec, v1.rawElements, v2.rawElements)); } public static max(v1: Vector4, v2: Vector4): Vector4 { - return new Vector4(VectorBase.__fromGenerationFunction(v1, v2, (i, _v1, _v2) => Math.max(_v1.rawElements[i], _v2.rawElements[i]))); + const newVec = vec4.create(); + return new Vector4(vec4.max(newVec, v1.rawElements, v2.rawElements)); } public static angle(v1: Vector4, v2: Vector4): number { return Math.acos(Vector4.dot(v1.normalized, v2.normalized)); } - public static parse(str: string): Vector4 { + public static parse(str: string): Undef { const parseResult = VectorBase.__parse(str); const elements = parseResult.elements; if (!elements || (elements.length !== 1 && elements.length !== 4)) { @@ -106,23 +107,22 @@ class Vector4 extends VectorBase { return result; } public static lerp(v1: Vector4, v2: Vector4, t: number): Vector4 { - return new Vector4(VectorBase.__fromGenerationFunction(v1, v2, (i, v1_, v2_) => { - return v1_.rawElements[i] + (v2_.rawElements[i] - v1_.rawElements[i]) * t; - })); + const newVec = vec4.create(); + return new Vector4(vec4.lerp(newVec, v1.rawElements, v2.rawElements, t)); } /* * Static properties */ - constructor(x: GLM.IArray); + constructor(vec4: vec4); constructor(x: number, y: number, z: number, w: number); - constructor(x: number | GLM.IArray, y?: number, z?: number, w?: number) { + constructor(x: number | vec4, y?: number, z?: number, w?: number) { super(); - if (typeof y === "undefined") { - this.rawElements = x; - return; + if (y === undefined) { + this.rawElements = x as vec4; + } else { + this.rawElements = vec4.fromValues(x as number, y, z!, w!); } - this.rawElements = [x, y, z, w]; } public get normalized() { @@ -193,7 +193,7 @@ class Vector4 extends VectorBase { return Vector4.nearlyEquals(this, v); } - public get ElementCount(): number { return 4; } + public get ElementCount(): 4 { return 4; } public toString(): string { return `(${this.X}, ${this.Y}, ${this.Z}, ${this.W})`; @@ -202,8 +202,4 @@ class Vector4 extends VectorBase { public toDisplayString(): string { return `Vector4${this.toString()}`; } - } - - -export default Vector4; diff --git a/src/VectorBase.ts b/src/VectorBase.ts index 1ecbd35..89d7504 100644 --- a/src/VectorBase.ts +++ b/src/VectorBase.ts @@ -1,18 +1,15 @@ -/// - -import {GLM} from "gl-matrix"; import IVectorParseDescription from "./IVectorParseDescription"; /** * Base class of vector. */ -class VectorBase { +export default abstract class VectorBase { /** * Actual array represents components of this instance. */ - public rawElements: GLM.IArray; - private _magnitudeSquaredCache: number = -1; - private _magnitudeCache: number = -1; + public rawElements: T; + private _magnitudeSquaredCache = -1; + private _magnitudeCache = -1; /** * Length of this vector. @@ -29,10 +26,7 @@ class VectorBase { * This is for override. * @return {number} [description] */ - public get ElementCount(): number { - return 0; - } - + public abstract get ElementCount(): number; /** * Get squred length of this elements. */ @@ -48,7 +42,7 @@ class VectorBase { return this._magnitudeSquaredCache; } - protected static __elementEquals(v1: VectorBase, v2: VectorBase): boolean { + protected static __elementEquals(v1: VectorBase, v2: VectorBase): boolean { if (v1.ElementCount !== v2.ElementCount) { return false; } @@ -60,7 +54,7 @@ class VectorBase { return true; } - protected static __nearlyElementEquals(v1: VectorBase, v2: VectorBase): boolean { + protected static __nearlyElementEquals(v1: VectorBase, v2: VectorBase): boolean { if (v1.ElementCount !== v2.ElementCount) { return false; } @@ -73,14 +67,6 @@ class VectorBase { return true; } - protected static __fromGenerationFunction(v1: T, v2: T, gen: (i: number, v1: T, v2: T) => number): GLM.IArray { - let f = new Float32Array(v1.ElementCount); - for (let i = 0; i < f.length; i++) { - f[i] = gen(i, v1, v2); - } - return f; - } - protected static __parse(str: string): IVectorParseDescription { const checkRegex = /(-?)([\d,Ee\+\-\.]+)?(n)?\(([-\d,Ee\+\.\s]+)\)/g; const matches = checkRegex.exec(str); @@ -118,4 +104,4 @@ class VectorBase { } } -export default VectorBase; + diff --git a/src/gl-matrix.d.ts b/src/gl-matrix.d.ts deleted file mode 100644 index f43bebf..0000000 --- a/src/gl-matrix.d.ts +++ /dev/null @@ -1,2169 +0,0 @@ -// Type definitions for gl-matrix 2.2.2 -// Project: https://github.com/toji/gl-matrix -// Definitions by: Tat -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module "gl-matrix" { - export module GLM { - interface IArray { - /** - * Must be indexable like an array - */ - [index: number]: number; - } - } - - // Common - export module glMatrix { - /** - * Convert Degree To Radian - * - * @param a Angle in Degrees - */ - export function toRadian(a: number): number; - } - - // vec2 - export module vec2 { - /** - * Creates a new, empty vec2 - * - * @returns a new 2D vector - */ - export function create(): GLM.IArray; - - /** - * Creates a new vec2 initialized with values from an existing vector - * - * @param a a vector to clone - * @returns a new 2D vector - */ - export function clone(a: GLM.IArray): GLM.IArray; - - /** - * Creates a new vec2 initialized with the given values - * - * @param x X component - * @param y Y component - * @returns a new 2D vector - */ - export function fromValues(x: number, y: number): GLM.IArray; - - /** - * Copy the values from one vec2 to another - * - * @param out the receiving vector - * @param a the source vector - * @returns out - */ - export function copy(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Set the components of a vec2 to the given values - * - * @param out the receiving vector - * @param x X component - * @param y Y component - * @returns out - */ - export function set(out: GLM.IArray, x: number, y: number): GLM.IArray; - - /** - * Adds two vec2's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function add(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Subtracts vector b from vector a - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function subtract(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Subtracts vector b from vector a - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function sub(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Multiplies two vec2's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function multiply(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Multiplies two vec2's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function mul(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Divides two vec2's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function divide(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Divides two vec2's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function div(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Returns the minimum of two vec2's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function min(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Returns the maximum of two vec2's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function max(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Scales a vec2 by a scalar number - * - * @param out the receiving vector - * @param a the vector to scale - * @param b amount to scale the vector by - * @returns out - */ - export function scale(out: GLM.IArray, a: GLM.IArray, b: number): GLM.IArray; - - /** - * Adds two vec2's after scaling the second operand by a scalar value - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @param scale the amount to scale b by before adding - * @returns out - */ - export function scaleAndAdd(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray, scale: number): GLM.IArray; - - /** - * Calculates the euclidian distance between two vec2's - * - * @param a the first operand - * @param b the second operand - * @returns distance between a and b - */ - export function distance(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Calculates the euclidian distance between two vec2's - * - * @param a the first operand - * @param b the second operand - * @returns distance between a and b - */ - export function dist(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Calculates the squared euclidian distance between two vec2's - * - * @param a the first operand - * @param b the second operand - * @returns squared distance between a and b - */ - export function squaredDistance(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Calculates the squared euclidian distance between two vec2's - * - * @param a the first operand - * @param b the second operand - * @returns squared distance between a and b - */ - export function sqrDist(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Calculates the length of a vec2 - * - * @param a vector to calculate length of - * @returns length of a - */ - export function length(a: GLM.IArray): number; - - /** - * Calculates the length of a vec2 - * - * @param a vector to calculate length of - * @returns length of a - */ - export function len(a: GLM.IArray): number; - - /** - * Calculates the squared length of a vec2 - * - * @param a vector to calculate squared length of - * @returns squared length of a - */ - export function squaredLength(a: GLM.IArray): number; - - /** - * Calculates the squared length of a vec2 - * - * @param a vector to calculate squared length of - * @returns squared length of a - */ - export function sqrLen(a: GLM.IArray): number; - - /** - * Negates the components of a vec2 - * - * @param out the receiving vector - * @param a vector to negate - * @returns out - */ - export function negate(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Returns the inverse of the components of a vec2 - * - * @param out the receiving vector - * @param a vector to invert - * @returns out - */ - export function inverse(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Normalize a vec2 - * - * @param out the receiving vector - * @param a vector to normalize - * @returns out - */ - export function normalize(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates the dot product of two vec2's - * - * @param a the first operand - * @param b the second operand - * @returns dot product of a and b - */ - export function dot(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Computes the cross product of two vec2's - * Note that the cross product must by definition produce a 3D vector - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function cross(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Performs a linear interpolation between two vec2's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @param t interpolation amount between the two inputs - * @returns out - */ - export function lerp(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray, t: number): GLM.IArray; - - /** - * Generates a random unit vector - * - * @param out the receiving vector - * @returns out - */ - export function random(out: GLM.IArray): GLM.IArray; - - /** - * Generates a random vector with the given scale - * - * @param out the receiving vector - * @param scale Length of the resulting vector. If ommitted, a unit vector will be returned - * @returns out - */ - export function random(out: GLM.IArray, scale: number): GLM.IArray; - - /** - * Transforms the vec2 with a mat2 - * - * @param out the receiving vector - * @param a the vector to transform - * @param m matrix to transform with - * @returns out - */ - export function transformMat2(out: GLM.IArray, a: GLM.IArray, m: GLM.IArray): GLM.IArray; - - /** - * Transforms the vec2 with a mat2d - * - * @param out the receiving vector - * @param a the vector to transform - * @param m matrix to transform with - * @returns out - */ - export function transformMat2d(out: GLM.IArray, a: GLM.IArray, m: GLM.IArray): GLM.IArray; - - /** - * Transforms the vec2 with a mat3 - * 3rd vector component is implicitly '1' - * - * @param out the receiving vector - * @param a the vector to transform - * @param m matrix to transform with - * @returns out - */ - export function transformMat3(out: GLM.IArray, a: GLM.IArray, m: GLM.IArray): GLM.IArray; - - /** - * Transforms the vec2 with a mat4 - * 3rd vector component is implicitly '0' - * 4th vector component is implicitly '1' - * - * @param out the receiving vector - * @param a the vector to transform - * @param m matrix to transform with - * @returns out - */ - export function transformMat4(out: GLM.IArray, a: GLM.IArray, m: GLM.IArray): GLM.IArray; - - /** - * Perform some operation over an array of vec2s. - * - * @param a the array of vectors to iterate over - * @param stride Number of elements between the start of each vec2. If 0 assumes tightly packed - * @param offset Number of elements to skip at the beginning of the array - * @param count Number of vec2s to iterate over. If 0 iterates over entire array - * @param fn Function to call for each vector in the array - * @param arg additional argument to pass to fn - * @returns a - */ - export function forEach(a: GLM.IArray, stride: number, offset: number, count: number, - fn: (a: GLM.IArray, b: GLM.IArray, arg: any) => void, arg: any): GLM.IArray; - - /** - * Perform some operation over an array of vec2s. - * - * @param a the array of vectors to iterate over - * @param stride Number of elements between the start of each vec2. If 0 assumes tightly packed - * @param offset Number of elements to skip at the beginning of the array - * @param count Number of vec2s to iterate over. If 0 iterates over entire array - * @param fn Function to call for each vector in the array - * @returns a - */ - export function forEach(a: GLM.IArray, stride: number, offset: number, count: number, - fn: (a: GLM.IArray, b: GLM.IArray) => void): GLM.IArray; - - /** - * Returns a string representation of a vector - * - * @param vec vector to represent as a string - * @returns string representation of the vector - */ - export function str(a: GLM.IArray): string; - } - - // vec3 - export module vec3 { - - /** - * Creates a new, empty vec3 - * - * @returns a new 3D vector - */ - export function create(): GLM.IArray; - - /** - * Creates a new vec3 initialized with values from an existing vector - * - * @param a vector to clone - * @returns a new 3D vector - */ - export function clone(a: GLM.IArray): GLM.IArray; - - /** - * Creates a new vec3 initialized with the given values - * - * @param x X component - * @param y Y component - * @param z Z component - * @returns a new 3D vector - */ - export function fromValues(x: number, y: number, z: number): GLM.IArray; - - /** - * Copy the values from one vec3 to another - * - * @param out the receiving vector - * @param a the source vector - * @returns out - */ - export function copy(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Set the components of a vec3 to the given values - * - * @param out the receiving vector - * @param x X component - * @param y Y component - * @param z Z component - * @returns out - */ - export function set(out: GLM.IArray, x: number, y: number, z: number): GLM.IArray; - - /** - * Adds two vec3's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function add(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Subtracts vector b from vector a - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function subtract(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Subtracts vector b from vector a - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function sub(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray - - /** - * Multiplies two vec3's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function multiply(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Multiplies two vec3's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function mul(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Divides two vec3's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function divide(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Divides two vec3's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function div(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Returns the minimum of two vec3's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function min(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Returns the maximum of two vec3's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function max(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Scales a vec3 by a scalar number - * - * @param out the receiving vector - * @param a the vector to scale - * @param b amount to scale the vector by - * @returns out - */ - export function scale(out: GLM.IArray, a: GLM.IArray, b: number): GLM.IArray; - - /** - * Adds two vec3's after scaling the second operand by a scalar value - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @param scale the amount to scale b by before adding - * @returns out - */ - export function scaleAndAdd(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray, scale: number): GLM.IArray; - - /** - * Calculates the euclidian distance between two vec3's - * - * @param a the first operand - * @param b the second operand - * @returns distance between a and b - */ - export function distance(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Calculates the euclidian distance between two vec3's - * - * @param a the first operand - * @param b the second operand - * @returns distance between a and b - */ - export function dist(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Calculates the squared euclidian distance between two vec3's - * - * @param a the first operand - * @param b the second operand - * @returns squared distance between a and b - */ - export function squaredDistance(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Calculates the squared euclidian distance between two vec3's - * - * @param a the first operand - * @param b the second operand - * @returns squared distance between a and b - */ - export function sqrDist(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Calculates the length of a vec3 - * - * @param a vector to calculate length of - * @returns length of a - */ - export function length(a: GLM.IArray): number; - - /** - * Calculates the length of a vec3 - * - * @param a vector to calculate length of - * @returns length of a - */ - export function len(a: GLM.IArray): number; - - /** - * Calculates the squared length of a vec3 - * - * @param a vector to calculate squared length of - * @returns squared length of a - */ - export function squaredLength(a: GLM.IArray): number; - - /** - * Calculates the squared length of a vec3 - * - * @param a vector to calculate squared length of - * @returns squared length of a - */ - export function sqrLen(a: GLM.IArray): number; - - /** - * Negates the components of a vec3 - * - * @param out the receiving vector - * @param a vector to negate - * @returns out - */ - export function negate(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Returns the inverse of the components of a vec3 - * - * @param out the receiving vector - * @param a vector to invert - * @returns out - */ - export function inverse(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Normalize a vec3 - * - * @param out the receiving vector - * @param a vector to normalize - * @returns out - */ - export function normalize(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates the dot product of two vec3's - * - * @param a the first operand - * @param b the second operand - * @returns dot product of a and b - */ - export function dot(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Computes the cross product of two vec3's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function cross(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Performs a linear interpolation between two vec3's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @param t interpolation amount between the two inputs - * @returns out - */ - export function lerp(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray, t: number): GLM.IArray; - - /** - * Generates a random unit vector - * - * @param out the receiving vector - * @returns out - */ - export function random(out: GLM.IArray): GLM.IArray; - - /** - * Generates a random vector with the given scale - * - * @param out the receiving vector - * @param [scale] Length of the resulting vector. If ommitted, a unit vector will be returned - * @returns out - */ - export function random(out: GLM.IArray, scale: number): GLM.IArray; - - /** - * Rotate a 3D vector around the x-axis - * @param out The receiving vec3 - * @param a The vec3 point to rotate - * @param b The origin of the rotation - * @param c The angle of rotation - * @returns out - */ - export function rotateX(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray, c: number): GLM.IArray; - - /** - * Rotate a 3D vector around the y-axis - * @param out The receiving vec3 - * @param a The vec3 point to rotate - * @param b The origin of the rotation - * @param c The angle of rotation - * @returns out - */ - export function rotateY(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray, c: number): GLM.IArray; - - /** - * Rotate a 3D vector around the z-axis - * @param out The receiving vec3 - * @param a The vec3 point to rotate - * @param b The origin of the rotation - * @param c The angle of rotation - * @returns out - */ - export function rotateZ(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray, c: number): GLM.IArray; - - /** - * Transforms the vec3 with a mat3. - * - * @param out the receiving vector - * @param a the vector to transform - * @param m the 3x3 matrix to transform with - * @returns out - */ - export function transformMat3(out: GLM.IArray, a: GLM.IArray, m: GLM.IArray): GLM.IArray; - - /** - * Transforms the vec3 with a mat4. - * 4th vector component is implicitly '1' - * - * @param out the receiving vector - * @param a the vector to transform - * @param m matrix to transform with - * @returns out - */ - export function transformMat4(out: GLM.IArray, a: GLM.IArray, m: GLM.IArray): GLM.IArray; - - /** - * Transforms the vec3 with a quat - * - * @param out the receiving vector - * @param a the vector to transform - * @param q quaternion to transform with - * @returns out - */ - export function transformQuat(out: GLM.IArray, a: GLM.IArray, q: GLM.IArray): GLM.IArray; - - - /** - * Perform some operation over an array of vec3s. - * - * @param a the array of vectors to iterate over - * @param stride Number of elements between the start of each vec3. If 0 assumes tightly packed - * @param offset Number of elements to skip at the beginning of the array - * @param count Number of vec3s to iterate over. If 0 iterates over entire array - * @param fn Function to call for each vector in the array - * @param arg additional argument to pass to fn - * @returns a - * @function - */ - export function forEach(out: GLM.IArray, string: number, offset: number, count: number, - fn: (a: GLM.IArray, b: GLM.IArray, arg: any) => void, arg: any): GLM.IArray; - - /** - * Perform some operation over an array of vec3s. - * - * @param a the array of vectors to iterate over - * @param stride Number of elements between the start of each vec3. If 0 assumes tightly packed - * @param offset Number of elements to skip at the beginning of the array - * @param count Number of vec3s to iterate over. If 0 iterates over entire array - * @param fn Function to call for each vector in the array - * @returns a - * @function - */ - export function forEach(out: GLM.IArray, string: number, offset: number, count: number, - fn: (a: GLM.IArray, b: GLM.IArray) => void): GLM.IArray; - - /** - * Get the angle between two 3D vectors - * @param a The first operand - * @param b The second operand - * @returns The angle in radians - */ - export function angle(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Returns a string representation of a vector - * - * @param vec vector to represent as a string - * @returns string representation of the vector - */ - export function str(a: GLM.IArray): string; - } - - // vec4 - export module vec4 { - - /** - * Creates a new, empty vec4 - * - * @returns a new 4D vector - */ - export function create(): GLM.IArray; - - /** - * Creates a new vec4 initialized with values from an existing vector - * - * @param a vector to clone - * @returns a new 4D vector - */ - export function clone(a: GLM.IArray): GLM.IArray; - - /** - * Creates a new vec4 initialized with the given values - * - * @param x X component - * @param y Y component - * @param z Z component - * @param w W component - * @returns a new 4D vector - */ - export function fromValues(x: number, y: number, z: number, w: number): GLM.IArray; - - /** - * Copy the values from one vec4 to another - * - * @param out the receiving vector - * @param a the source vector - * @returns out - */ - export function copy(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Set the components of a vec4 to the given values - * - * @param out the receiving vector - * @param x X component - * @param y Y component - * @param z Z component - * @param w W component - * @returns out - */ - export function set(out: GLM.IArray, x: number, y: number, z: number, w: number): GLM.IArray; - - /** - * Adds two vec4's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function add(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Subtracts vector b from vector a - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function subtract(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Subtracts vector b from vector a - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function sub(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Multiplies two vec4's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function multiply(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Multiplies two vec4's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function mul(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Divides two vec4's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function divide(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Divides two vec4's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function div(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Returns the minimum of two vec4's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function min(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Returns the maximum of two vec4's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function max(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Scales a vec4 by a scalar number - * - * @param out the receiving vector - * @param a the vector to scale - * @param b amount to scale the vector by - * @returns out - */ - export function scale(out: GLM.IArray, a: GLM.IArray, b: number): GLM.IArray; - - /** - * Adds two vec4's after scaling the second operand by a scalar value - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @param scale the amount to scale b by before adding - * @returns out - */ - export function scaleAndAdd(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray, scale: number): GLM.IArray; - - /** - * Calculates the euclidian distance between two vec4's - * - * @param a the first operand - * @param b the second operand - * @returns distance between a and b - */ - export function distance(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Calculates the euclidian distance between two vec4's - * - * @param a the first operand - * @param b the second operand - * @returns distance between a and b - */ - export function dist(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Calculates the squared euclidian distance between two vec4's - * - * @param a the first operand - * @param b the second operand - * @returns squared distance between a and b - */ - export function squaredDistance(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Calculates the squared euclidian distance between two vec4's - * - * @param a the first operand - * @param b the second operand - * @returns squared distance between a and b - */ - export function sqrDist(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Calculates the length of a vec4 - * - * @param a vector to calculate length of - * @returns length of a - */ - export function length(a: GLM.IArray): number; - - /** - * Calculates the length of a vec4 - * - * @param a vector to calculate length of - * @returns length of a - */ - export function len(a: GLM.IArray): number; - - /** - * Calculates the squared length of a vec4 - * - * @param a vector to calculate squared length of - * @returns squared length of a - */ - export function squaredLength(a: GLM.IArray): number; - - /** - * Calculates the squared length of a vec4 - * - * @param a vector to calculate squared length of - * @returns squared length of a - */ - export function sqrLen(a: GLM.IArray): number; - - /** - * Negates the components of a vec4 - * - * @param out the receiving vector - * @param a vector to negate - * @returns out - */ - export function negate(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Returns the inverse of the components of a vec4 - * - * @param out the receiving vector - * @param a vector to invert - * @returns out - */ - export function inverse(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Normalize a vec4 - * - * @param out the receiving vector - * @param a vector to normalize - * @returns out - */ - export function normalize(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates the dot product of two vec4's - * - * @param a the first operand - * @param b the second operand - * @returns dot product of a and b - */ - export function dot(a: GLM.IArray, b: GLM.IArray): number; - - /** - * Performs a linear interpolation between two vec4's - * - * @param out the receiving vector - * @param a the first operand - * @param b the second operand - * @param t interpolation amount between the two inputs - * @returns out - */ - export function lerp(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray, t: number): GLM.IArray; - - /** - * Generates a random unit vector - * - * @param out the receiving vector - * @returns out - */ - export function random(out: GLM.IArray): GLM.IArray; - - /** - * Generates a random vector with the given scale - * - * @param out the receiving vector - * @param Length of the resulting vector. If ommitted, a unit vector will be returned - * @returns out - */ - export function random(out: GLM.IArray, scale: number): GLM.IArray; - - /** - * Transforms the vec4 with a mat4. - * - * @param out the receiving vector - * @param a the vector to transform - * @param m matrix to transform with - * @returns out - */ - export function transformMat4(out: GLM.IArray, a: GLM.IArray, mat: GLM.IArray): GLM.IArray; - - /** - * Transforms the vec4 with a quat - * - * @param out the receiving vector - * @param a the vector to transform - * @param q quaternion to transform with - * @returns out - */ - export function transformQuat(out: GLM.IArray, a: GLM.IArray, quat: GLM.IArray): GLM.IArray; - - /** - * Perform some operation over an array of vec4s. - * - * @param a the array of vectors to iterate over - * @param stride Number of elements between the start of each vec4. If 0 assumes tightly packed - * @param offset Number of elements to skip at the beginning of the array - * @param count Number of vec4s to iterate over. If 0 iterates over entire array - * @param fn Function to call for each vector in the array - * @param additional argument to pass to fn - * @returns a - * @function - */ - export function forEach(out: GLM.IArray, string: number, offset: number, count: number, - callback: (a: GLM.IArray, b: GLM.IArray, arg: any) => void, arg: any): GLM.IArray; - - /** - * Perform some operation over an array of vec4s. - * - * @param a the array of vectors to iterate over - * @param stride Number of elements between the start of each vec4. If 0 assumes tightly packed - * @param offset Number of elements to skip at the beginning of the array - * @param count Number of vec4s to iterate over. If 0 iterates over entire array - * @param fn Function to call for each vector in the array - * @returns a - * @function - */ - export function forEach(out: GLM.IArray, string: number, offset: number, count: number, - callback: (a: GLM.IArray, b: GLM.IArray) => void): GLM.IArray; - - /** - * Returns a string representation of a vector - * - * @param vec vector to represent as a string - * @returns string representation of the vector - */ - export function str(a: GLM.IArray): string; - } - - // mat2 - export module mat2 { - - /** - * Creates a new identity mat2 - * - * @returns a new 2x2 matrix - */ - export function create(): GLM.IArray; - - /** - * Creates a new mat2 initialized with values from an existing matrix - * - * @param a matrix to clone - * @returns a new 2x2 matrix - */ - export function clone(a: GLM.IArray): GLM.IArray; - - /** - * Copy the values from one mat2 to another - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function copy(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Set a mat2 to the identity matrix - * - * @param out the receiving matrix - * @returns out - */ - export function identity(out: GLM.IArray): GLM.IArray; - - /** - * Transpose the values of a mat2 - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function transpose(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Inverts a mat2 - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function invert(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates the adjugate of a mat2 - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function adjoint(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates the determinant of a mat2 - * - * @param a the source matrix - * @returns determinant of a - */ - export function determinant(a: GLM.IArray): number; - - /** - * Multiplies two mat2's - * - * @param out the receiving matrix - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function multiply(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Multiplies two mat2's - * - * @param out the receiving matrix - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function mul(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Rotates a mat2 by the given angle - * - * @param out the receiving matrix - * @param a the matrix to rotate - * @param rad the angle to rotate the matrix by - * @returns out - */ - export function rotate(out: GLM.IArray, a: GLM.IArray, rad: number): GLM.IArray; - - /** - * Scales the mat2 by the dimensions in the given vec2 - * - * @param out the receiving matrix - * @param a the matrix to rotate - * @param v the vec2 to scale the matrix by - * @returns out - **/ - export function scale(out: GLM.IArray, a: GLM.IArray, v: GLM.IArray): GLM.IArray; - - /** - * Returns a string representation of a mat2 - * - * @param a matrix to represent as a string - * @returns string representation of the matrix - */ - export function str(a: GLM.IArray): string; - - /** - * Returns Frobenius norm of a mat2 - * - * @param a the matrix to calculate Frobenius norm of - * @returns Frobenius norm - */ - export function frob(a: GLM.IArray): number; - - /** - * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix - * @param L the lower triangular matrix - * @param D the diagonal matrix - * @param U the upper triangular matrix - * @param a the input matrix to factorize - */ - export function LDU(L: GLM.IArray, D: GLM.IArray, U: GLM.IArray, a: GLM.IArray): GLM.IArray; - } - - // mat2d - export module mat2d { - - /** - * Creates a new identity mat2d - * - * @returns a new 2x3 matrix - */ - export function create(): GLM.IArray; - - /** - * Creates a new mat2d initialized with values from an existing matrix - * - * @param a matrix to clone - * @returns a new 2x3 matrix - */ - export function clone(a: GLM.IArray): GLM.IArray; - - /** - * Copy the values from one mat2d to another - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function copy(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Set a mat2d to the identity matrix - * - * @param out the receiving matrix - * @returns out - */ - export function identity(out: GLM.IArray): GLM.IArray; - - /** - * Inverts a mat2d - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function invert(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates the determinant of a mat2d - * - * @param a the source matrix - * @returns determinant of a - */ - export function determinant(a: GLM.IArray): number; - - /** - * Multiplies two mat2d's - * - * @param out the receiving matrix - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function multiply(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Multiplies two mat2d's - * - * @param out the receiving matrix - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function mul(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Rotates a mat2d by the given angle - * - * @param out the receiving matrix - * @param a the matrix to rotate - * @param rad the angle to rotate the matrix by - * @returns out - */ - export function rotate(out: GLM.IArray, a: GLM.IArray, rad: number): GLM.IArray; - - /** - * Scales the mat2d by the dimensions in the given vec2 - * - * @param out the receiving matrix - * @param a the matrix to translate - * @param v the vec2 to scale the matrix by - * @returns out - **/ - export function scale(out: GLM.IArray, a: GLM.IArray, v: GLM.IArray): GLM.IArray; - - /** - * Translates the mat2d by the dimensions in the given vec2 - * - * @param out the receiving matrix - * @param a the matrix to translate - * @param v the vec2 to translate the matrix by - * @returns out - **/ - export function translate(out: GLM.IArray, a: GLM.IArray, v: GLM.IArray): GLM.IArray; - - /** - * Returns a string representation of a mat2d - * - * @param a matrix to represent as a string - * @returns string representation of the matrix - */ - export function str(a: GLM.IArray): string; - - /** - * Returns Frobenius norm of a mat2d - * - * @param a the matrix to calculate Frobenius norm of - * @returns Frobenius norm - */ - export function frob(a: GLM.IArray): number; - } - - // mat3 - export module mat3 { - - /** - * Creates a new identity mat3 - * - * @returns a new 3x3 matrix - */ - export function create(): GLM.IArray; - - /** - * Creates a new mat3 initialized with values from an existing matrix - * - * @param a matrix to clone - * @returns a new 3x3 matrix - */ - export function clone(a: GLM.IArray): GLM.IArray; - - /** - * Copy the values from one mat3 to another - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function copy(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Set a mat3 to the identity matrix - * - * @param out the receiving matrix - * @returns out - */ - export function identity(out: GLM.IArray): GLM.IArray; - - /** - * Transpose the values of a mat3 - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function transpose(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Inverts a mat3 - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function invert(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates the adjugate of a mat3 - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function adjoint(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates the determinant of a mat3 - * - * @param a the source matrix - * @returns determinant of a - */ - export function determinant(a: GLM.IArray): number; - - /** - * Multiplies two mat3's - * - * @param out the receiving matrix - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function multiply(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Multiplies two mat3's - * - * @param out the receiving matrix - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function mul(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Returns a string representation of a mat3 - * - * @param mat matrix to represent as a string - * @returns string representation of the matrix - */ - export function str(mat: GLM.IArray): string; - - /** - * Returns Frobenius norm of a mat3 - * - * @param a the matrix to calculate Frobenius norm of - * @returns Frobenius norm - */ - export function frob(a: GLM.IArray): number; - - /** - * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix - * - * @param out mat3 receiving operation result - * @param a Mat4 to derive the normal matrix from - * - * @returns out - */ - export function normalFromMat4(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates a 3x3 matrix from the given quaternion - * - * @param out mat3 receiving operation result - * @param q Quaternion to create matrix from - * - * @returns out - */ - export function fromQuat(out: GLM.IArray, q: GLM.IArray): GLM.IArray; - - /** - * Copies the upper-left 3x3 values into the given mat3. - * - * @param out the receiving 3x3 matrix - * @param a the source 4x4 matrix - * @returns out - */ - export function fromMat4(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Scales the mat3 by the dimensions in the given vec2 - * - * @param out the receiving matrix - * @param a the matrix to rotate - * @param v the vec2 to scale the matrix by - * @returns out - **/ - export function scale(out: GLM.IArray, a: GLM.IArray, v: GLM.IArray): GLM.IArray; - - /** - * Copies the values from a mat2d into a mat3 - * - * @param out the receiving matrix - * @param {mat2d} a the matrix to copy - * @returns out - **/ - export function fromMat2d(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Translate a mat3 by the given vector - * - * @param out the receiving matrix - * @param a the matrix to translate - * @param v vector to translate by - * @returns out - */ - export function translate(out: GLM.IArray, a: GLM.IArray, v: GLM.IArray): GLM.IArray; - - /** - * Rotates a mat3 by the given angle - * - * @param out the receiving matrix - * @param a the matrix to rotate - * @param rad the angle to rotate the matrix by - * @returns out - */ - export function rotate(out: GLM.IArray, a: GLM.IArray, rad: number): GLM.IArray; - } - - // mat4 - export module mat4 { - - export function getScaling(out: GLM.IArray, mat: GLM.IArray): GLM.IArray; - - export function getRotation(out: GLM.IArray, mat: GLM.IArray): GLM.IArray; - - export function getTranslation(out: GLM.IArray, mat: GLM.IArray): GLM.IArray; - - /** - * Creates a new identity mat4 - * - * @returns a new 4x4 matrix - */ - export function create(): GLM.IArray; - - /** - * Creates a new mat4 initialized with values from an existing matrix - * - * @param a matrix to clone - * @returns a new 4x4 matrix - */ - export function clone(a: GLM.IArray): GLM.IArray; - - /** - * Copy the values from one mat4 to another - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function copy(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Set a mat4 to the identity matrix - * - * @param out the receiving matrix - * @returns out - */ - export function identity(a: GLM.IArray): GLM.IArray; - - /** - * Transpose the values of a mat4 - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function transpose(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Inverts a mat4 - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function invert(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates the adjugate of a mat4 - * - * @param out the receiving matrix - * @param a the source matrix - * @returns out - */ - export function adjoint(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates the determinant of a mat4 - * - * @param a the source matrix - * @returns determinant of a - */ - export function determinant(a: GLM.IArray): number; - - /** - * Multiplies two mat4's - * - * @param out the receiving matrix - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function multiply(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Multiplies two mat4's - * - * @param out the receiving matrix - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function mul(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Translate a mat4 by the given vector - * - * @param out the receiving matrix - * @param a the matrix to translate - * @param v vector to translate by - * @returns out - */ - export function translate(out: GLM.IArray, a: GLM.IArray, v: GLM.IArray): GLM.IArray; - - /** - * Scales the mat4 by the dimensions in the given vec3 - * - * @param out the receiving matrix - * @param a the matrix to scale - * @param v the vec3 to scale the matrix by - * @returns out - **/ - export function scale(out: GLM.IArray, a: GLM.IArray, v: GLM.IArray): GLM.IArray; - - /** - * Rotates a mat4 by the given angle - * - * @param out the receiving matrix - * @param a the matrix to rotate - * @param rad the angle to rotate the matrix by - * @param axis the axis to rotate around - * @returns out - */ - export function rotate(out: GLM.IArray, a: GLM.IArray, rad: number, axis: GLM.IArray): GLM.IArray; - - /** - * Rotates a matrix by the given angle around the X axis - * - * @param out the receiving matrix - * @param a the matrix to rotate - * @param rad the angle to rotate the matrix by - * @returns out - */ - export function rotateX(out: GLM.IArray, a: GLM.IArray, rad: number): GLM.IArray; - - /** - * Rotates a matrix by the given angle around the Y axis - * - * @param out the receiving matrix - * @param a the matrix to rotate - * @param rad the angle to rotate the matrix by - * @returns out - */ - export function rotateY(out: GLM.IArray, a: GLM.IArray, rad: number): GLM.IArray; - - /** - * Rotates a matrix by the given angle around the Z axis - * - * @param out the receiving matrix - * @param a the matrix to rotate - * @param rad the angle to rotate the matrix by - * @returns out - */ - export function rotateZ(out: GLM.IArray, a: GLM.IArray, rad: number): GLM.IArray; - - /** - * Generates a frustum matrix with the given bounds - * - * @param out mat4 frustum matrix will be written into - * @param left Left bound of the frustum - * @param right Right bound of the frustum - * @param bottom Bottom bound of the frustum - * @param top Top bound of the frustum - * @param near Near bound of the frustum - * @param far Far bound of the frustum - * @returns out - */ - export function frustum(out: GLM.IArray, left: number, right: number, - bottom: number, top: number, near: number, far: number): GLM.IArray; - - /** - * Generates a perspective projection matrix with the given bounds - * - * @param out mat4 frustum matrix will be written into - * @param fovy Vertical field of view in radians - * @param aspect Aspect ratio. typically viewport width/height - * @param near Near bound of the frustum - * @param far Far bound of the frustum - * @returns out - */ - export function perspective(out: GLM.IArray, fovy: number, aspect: number, - near: number, far: number): GLM.IArray; - - /** - * Generates a orthogonal projection matrix with the given bounds - * - * @param out mat4 frustum matrix will be written into - * @param left Left bound of the frustum - * @param right Right bound of the frustum - * @param bottom Bottom bound of the frustum - * @param top Top bound of the frustum - * @param near Near bound of the frustum - * @param far Far bound of the frustum - * @returns out - */ - export function ortho(out: GLM.IArray, left: number, right: number, - bottom: number, top: number, near: number, far: number): GLM.IArray; - - /** - * Generates a look-at matrix with the given eye position, focal point, and up axis - * - * @param out mat4 frustum matrix will be written into - * @param eye Position of the viewer - * @param center Point the viewer is looking at - * @param up vec3 pointing up - * @returns out - */ - export function lookAt(out: GLM.IArray, eye: GLM.IArray, - center: GLM.IArray, up: GLM.IArray): GLM.IArray; - - /** - * Returns a string representation of a mat4 - * - * @param mat matrix to represent as a string - * @returns string representation of the matrix - */ - export function str(mat: GLM.IArray): string; - - /** - * Returns Frobenius norm of a mat4 - * - * @param a the matrix to calculate Frobenius norm of - * @returns Frobenius norm - */ - export function frob(a: GLM.IArray): number; - - /** - * Creates a matrix from a quaternion rotation and vector translation - * This is equivalent to (but much faster than): - * - * mat4.identity(dest); - * mat4.translate(dest, vec); - * var quatMat = mat4.create(); - * quat4.toMat4(quat, quatMat); - * mat4.multiply(dest, quatMat); - * - * @param out mat4 receiving operation result - * @param q Rotation quaternion - * @param v Translation vector - * @returns out - */ - export function fromRotationTranslation(out: GLM.IArray, q: GLM.IArray, v: GLM.IArray): GLM.IArray; - - /** - * Creates a matrix from a quaternion rotation, vector translation and vector scale. - * - * This is equivalent to (but much faster than): - * - * mat4.identity(dest); - * mat4.translate(dest, vec); - * var quatMat = mat4.create(); - * quat4.toMat4(quat, quatMat); - * mat4.multiply(dest, quatMat); - * mat4.scale(dest, scale) - * - * @param out mat4 receiving operation result - * @param q Rotation quaternion - * @param v Translation vector - * @param s Scale vector - * @returns out - */ - export function fromRotationTranslationScale(out: GLM.IArray, q: GLM.IArray, v: GLM.IArray, s: GLM.IArray): GLM.IArray - - /** - * Creates a matrix from a quaternion - * - * @param out mat4 receiving operation result - * @param q Rotation quaternion - * @returns out - */ - export function fromQuat(out: GLM.IArray, q: GLM.IArray): GLM.IArray; - } - - // quat - export module quat { - - /** - * Creates a new identity quat - * - * @returns a new quaternion - */ - export function create(): GLM.IArray; - - /** - * Creates a new quat initialized with values from an existing quaternion - * - * @param a quaternion to clone - * @returns a new quaternion - * @function - */ - export function clone(a: GLM.IArray): GLM.IArray; - - /** - * Creates a new quat initialized with the given values - * - * @param x X component - * @param y Y component - * @param z Z component - * @param w W component - * @returns a new quaternion - * @function - */ - export function fromValues(x: number, y: number, z: number, w: number): GLM.IArray; - - /** - * Copy the values from one quat to another - * - * @param out the receiving quaternion - * @param a the source quaternion - * @returns out - * @function - */ - export function copy(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Set the components of a quat to the given values - * - * @param out the receiving quaternion - * @param x X component - * @param y Y component - * @param z Z component - * @param w W component - * @returns out - * @function - */ - export function set(out: GLM.IArray, x: number, y: number, z: number, w: number): GLM.IArray; - - /** - * Set a quat to the identity quaternion - * - * @param out the receiving quaternion - * @returns out - */ - export function identity(out: GLM.IArray): GLM.IArray; - - /** - * Sets a quat from the given angle and rotation axis, - * then returns it. - * - * @param out the receiving quaternion - * @param axis the axis around which to rotate - * @param rad the angle in radians - * @returns out - **/ - export function setAxisAngle(out: GLM.IArray, axis: GLM.IArray, rad: number): GLM.IArray; - - /** - * Adds two quat's - * - * @param out the receiving quaternion - * @param a the first operand - * @param b the second operand - * @returns out - * @function - */ - export function add(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Multiplies two quat's - * - * @param out the receiving quaternion - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function multiply(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Multiplies two quat's - * - * @param out the receiving quaternion - * @param a the first operand - * @param b the second operand - * @returns out - */ - export function mul(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Scales a quat by a scalar number - * - * @param out the receiving vector - * @param a the vector to scale - * @param b amount to scale the vector by - * @returns out - * @function - */ - export function scale(out: GLM.IArray, a: GLM.IArray, b: number): GLM.IArray; - - /** - * Calculates the length of a quat - * - * @param a vector to calculate length of - * @returns length of a - * @function - */ - export function length(a: GLM.IArray): number; - - /** - * Calculates the length of a quat - * - * @param a vector to calculate length of - * @returns length of a - * @function - */ - export function len(a: GLM.IArray): number; - - /** - * Calculates the squared length of a quat - * - * @param a vector to calculate squared length of - * @returns squared length of a - * @function - */ - export function squaredLength(a: GLM.IArray): number; - - /** - * Calculates the squared length of a quat - * - * @param a vector to calculate squared length of - * @returns squared length of a - * @function - */ - export function sqrLen(a: GLM.IArray): number; - - /** - * Normalize a quat - * - * @param out the receiving quaternion - * @param a quaternion to normalize - * @returns out - * @function - */ - export function normalize(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates the dot product of two quat's - * - * @param a the first operand - * @param b the second operand - * @returns dot product of a and b - * @function - */ - export function dot(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): number; - - /** - * Performs a linear interpolation between two quat's - * - * @param out the receiving quaternion - * @param a the first operand - * @param b the second operand - * @param t interpolation amount between the two inputs - * @returns out - * @function - */ - export function lerp(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray, t: number): GLM.IArray; - - /** - * Performs a spherical linear interpolation between two quat - * - * @param out the receiving quaternion - * @param a the first operand - * @param b the second operand - * @param t interpolation amount between the two inputs - * @returns out - */ - export function slerp(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray, t: number): GLM.IArray; - - /** - * Calculates the inverse of a quat - * - * @param out the receiving quaternion - * @param a quat to calculate inverse of - * @returns out - */ - export function invert(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Calculates the conjugate of a quat - * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result. - * - * @param out the receiving quaternion - * @param a quat to calculate conjugate of - * @returns out - */ - export function conjugate(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - - /** - * Returns a string representation of a quatenion - * - * @param vec vector to represent as a string - * @returns string representation of the vector - */ - export function str(a: GLM.IArray): string; - - /** - * Rotates a quaternion by the given angle about the X axis - * - * @param out quat receiving operation result - * @param a quat to rotate - * @param rad angle (in radians) to rotate - * @returns out - */ - export function rotateX(out: GLM.IArray, a: GLM.IArray, rad: number): GLM.IArray; - - /** - * Rotates a quaternion by the given angle about the Y axis - * - * @param out quat receiving operation result - * @param a quat to rotate - * @param rad angle (in radians) to rotate - * @returns out - */ - export function rotateY(out: GLM.IArray, a: GLM.IArray, rad: number): GLM.IArray; - - /** - * Rotates a quaternion by the given angle about the Z axis - * - * @param out quat receiving operation result - * @param a quat to rotate - * @param rad angle (in radians) to rotate - * @returns out - */ - export function rotateZ(out: GLM.IArray, a: GLM.IArray, rad: number): GLM.IArray; - - /** - * Creates a quaternion from the given 3x3 rotation matrix. - * - * NOTE: The resultant quaternion is not normalized, so you should be sure - * to renormalize the quaternion yourself where necessary. - * - * @param out the receiving quaternion - * @param m rotation matrix - * @returns out - * @function - */ - export function fromMat3(out: GLM.IArray, m: GLM.IArray): GLM.IArray; - - /** - * Sets the specified quaternion with values corresponding to the given - * axes. Each axis is a vec3 and is expected to be unit length and - * perpendicular to all other specified axes. - * - * @param view the vector representing the viewing direction - * @param right the vector representing the local "right" direction - * @param up the vector representing the local "up" direction - * @returns out - */ - export function setAxes(out: GLM.IArray, view: GLM.IArray, right: GLM.IArray, - up: GLM.IArray): GLM.IArray; - - /** - * Sets a quaternion to represent the shortest rotation from one - * vector to another. - * - * Both vectors are assumed to be unit length. - * - * @param out the receiving quaternion. - * @param a the initial vector - * @param b the destination vector - * @returns out - */ - export function rotationTo(out: GLM.IArray, a: GLM.IArray, b: GLM.IArray): GLM.IArray; - - /** - * Calculates the W component of a quat from the X, Y, and Z components. - * Assumes that quaternion is 1 unit in length. - * Any existing W component will be ignored. - * - * @param out the receiving quaternion - * @param a quat to calculate W component of - * @returns out - */ - export function calculateW(out: GLM.IArray, a: GLM.IArray): GLM.IArray; - } -} diff --git a/src/main.ts b/src/main.ts index b71c6d1..a7838ef 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,17 +6,15 @@ import Rotation3Converter from "./Converters/Rotation3Converter"; import Angle2DConverter from "./Converters/Angle2DConverter"; import Color3Converter from "./Converters/Color3Converter"; import Color4Converter from "./Converters/Color4Converter"; -// import NumberArrayConverter from "./Converters/NumberArrayConverter"; export default () => { gr.register(async () => { - gr.registerConverter("Vector2", Vector2Converter); - gr.registerConverter("Vector3", Vector3Converter); - gr.registerConverter("Vector4", Vector4Converter); - gr.registerConverter("Color3", Color3Converter); - gr.registerConverter("Color4", Color4Converter); - gr.registerConverter("Rotation3", Rotation3Converter); - gr.registerConverter("Angle2D", Angle2DConverter); - //gr.registerConverter("NumberArray",NumberArrayConverter); + gr.registerConverter(Vector2Converter); + gr.registerConverter(Vector3Converter); + gr.registerConverter(Vector4Converter); + gr.registerConverter(Color3Converter); + gr.registerConverter(Color4Converter); + gr.registerConverter(Rotation3Converter); + gr.registerConverter(Angle2DConverter); }); } diff --git a/test/MatrixTest.js b/test/MatrixTest.js index df6013f..c222c64 100644 --- a/test/MatrixTest.js +++ b/test/MatrixTest.js @@ -101,8 +101,8 @@ test('determinant', (t) => { test('inverse', (t) => { t.truthy(Matrix.equals( - Matrix.inverse(new Matrix([1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 4])), - new Matrix([1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.25]))); + Matrix.inverse(new Matrix(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 4)), + new Matrix(1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.25))); }); test('translate', (t) => { diff --git a/test/NumberArrayTest.js b/test/NumberArrayTest.js deleted file mode 100644 index dc03fb5..0000000 --- a/test/NumberArrayTest.js +++ /dev/null @@ -1,28 +0,0 @@ -import test from 'ava'; -import NumberArrayConverter from '../lib-es5/Converters/NumberArrayConverter'; - -test('parse from string', (t) => { - const arr = NumberArrayConverter("1,2,3,4,5"); - const correct = [1,2,3,4,5]; - t.true(arr instanceof Float32Array); - t.true(correct.filter((v,i)=>arr[i] !== v).length === 0); - t.true(arr.length === correct.length); -}); - - -test('parse from raw array', (t) => { - const arr = NumberArrayConverter([1,2,3,4,5]); - const correct = [1,2,3,4,5]; - t.true(arr instanceof Float32Array); - t.true(correct.filter((v,i)=>arr[i] !== v).length === 0); - t.true(arr.length === correct.length); -}); - - -test('parse from Float32Array', (t) => { - const arr = NumberArrayConverter(new Float32Array([1,2,3,4,5])); - const correct = [1,2,3,4,5]; - t.true(arr instanceof Float32Array); - t.true(correct.filter((v,i)=>arr[i] !== v).length === 0); - t.true(arr.length === correct.length); -}); \ No newline at end of file diff --git a/test/QuaternionTest.js b/test/QuaternionTest.js index a4f3372..cb3d5f8 100644 --- a/test/QuaternionTest.js +++ b/test/QuaternionTest.js @@ -9,18 +9,18 @@ test('equals', (t) => { }); test('add', (t) => { - t.truthy(Quaternion.equals(Quaternion.add(new Quaternion([10, 10, 10, 10]), - new Quaternion([10, 10, 10, 10])), new Quaternion([20, 20, 20, 20]))); + t.truthy(Quaternion.equals(Quaternion.add(new Quaternion(10, 10, 10, 10), + new Quaternion(10, 10, 10, 10)), new Quaternion(20, 20, 20, 20))); }); test('multiply', (t) => { - t.truthy(Quaternion.equals(Quaternion.multiply(new Quaternion([10, 10, 10, 10]), - new Quaternion([10, 10, 10, 10])), new Quaternion([200, 200, 200, -200]))); + t.truthy(Quaternion.equals(Quaternion.multiply(new Quaternion(10, 10, 10, 10), + new Quaternion(10, 10, 10, 10)), new Quaternion(200, 200, 200, -200))); }); test('euler', (t) => { - t.truthy(Quaternion.equals(Quaternion.euler(0, 0, 0), new Quaternion([0, 0, 0, 1]))); + t.truthy(Quaternion.equals(Quaternion.euler(0, 0, 0), new Quaternion(0, 0, 0, 1))); }); test('Angle', (t) => { @@ -28,12 +28,12 @@ test('Angle', (t) => { }); test('FromToRotation', (t) => { - let difference = Quaternion.angle(Quaternion.Identity,Quaternion.fromToRotation(new Vector3(0,0,1),new Vector3(0,0,1))); + let difference = Quaternion.angle(Quaternion.Identity, Quaternion.fromToRotation(new Vector3(0, 0, 1), new Vector3(0, 0, 1))); t.truthy(difference === 0); - difference = Quaternion.angle(Quaternion.Identity,Quaternion.fromToRotation(new Vector3(0,0,1),new Vector3(1,0,0))); - t.truthy(Math.abs(difference-Math.PI / 2) < 0.0001); - difference = Quaternion.angle(Quaternion.Identity,Quaternion.fromToRotation(new Vector3(0,0,-1),new Vector3(0,0,1))); - t.truthy(Math.abs(difference-Math.PI) < 0.0001); + difference = Quaternion.angle(Quaternion.Identity, Quaternion.fromToRotation(new Vector3(0, 0, 1), new Vector3(1, 0, 0))); + t.truthy(Math.abs(difference - Math.PI / 2) < 0.0001); + difference = Quaternion.angle(Quaternion.Identity, Quaternion.fromToRotation(new Vector3(0, 0, -1), new Vector3(0, 0, 1))); + t.truthy(Math.abs(difference - Math.PI) < 0.0001); }); test('identity', (t) => { @@ -41,39 +41,39 @@ test('identity', (t) => { }); test('get X', (t) => { - t.truthy(new Quaternion([10, 20, 20, 10]).X === 10); + t.truthy(new Quaternion(10, 20, 20, 10).X === 10); }); test('get Y', (t) => { - t.truthy(new Quaternion([10, 20, 20, 10]).Y === 20); + t.truthy(new Quaternion(10, 20, 20, 10).Y === 20); }); test('get Z', (t) => { - t.truthy(new Quaternion([10, 20, 20, 10]).Z === 20); + t.truthy(new Quaternion(10, 20, 20, 10).Z === 20); }); test('get W', (t) => { - t.truthy(new Quaternion([10, 20, 20, 10]).W === 10); + t.truthy(new Quaternion(10, 20, 20, 10).W === 10); }); test('get ImaginaryPart', (t) => { - t.truthy(Vector3.equals(new Quaternion([10, 20, 20, 10]).ImaginaryPart, - new Vector3([10, 20, 20]))); + t.truthy(Vector3.equals(new Quaternion(10, 20, 20, 10).ImaginaryPart, + new Vector3([10, 20, 20]))); }); test('get Conjugate', (t) => { - t.truthy(Quaternion.equals(new Quaternion([10, 20, 20, 10]).Conjugate, - new Quaternion([-10, -20, -20, 10]))); + t.truthy(Quaternion.equals(new Quaternion(10, 20, 20, 10).Conjugate, + new Quaternion(-10, -20, -20, 10))); }); test('get Length', (t) => { - t.truthy(new Quaternion([1, 1, 1, 1]).Length === 2); + t.truthy(new Quaternion(1, 1, 1, 1).Length === 2); }); test('get Normalize', (t) => { - t.truthy(Quaternion.equals(new Quaternion([1, 1, 1, 1]).normalize(), new Quaternion([0.5, 0.5, 0.5, 0.5]))); + t.truthy(Quaternion.equals(new Quaternion(1, 1, 1, 1).normalize(), new Quaternion(0.5, 0.5, 0.5, 0.5))); }); test('get Normalize', (t) => { - t.truthy(Quaternion.equals(new Quaternion([1, 1, 1, 1]).inverse(), new Quaternion([-0.25, -0.25, -0.25, 0.25]))); + t.truthy(Quaternion.equals(new Quaternion(1, 1, 1, 1).inverse(), new Quaternion(-0.25, -0.25, -0.25, 0.25))); }); diff --git a/tsconfig.json b/tsconfig.json index 7c38bce..8ff3cb3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,44 +2,15 @@ "compilerOptions": { "target": "es6", "module": "es6", - "noImplicitAny": false, "outDir": "lib", "declarationDir": "ref", "declaration": true, - "moduleResolution": "node" + "moduleResolution": "node", + "noImplicitReturns": true, + "noUnusedParameters": true, + "strict": true }, - "filesGlob": [ - "./src/**/*.ts" - ], - "files": [ - "./src/AABB.ts", - "./src/Color3.ts", - "./src/Color4.ts", - "./src/Colors.ts", - "./src/Converters/Angle2DConverter.ts", - "./src/Converters/Color3Converter.ts", - "./src/Converters/Color4Converter.ts", - "./src/Converters/Rotation3Converter.ts", - "./src/Converters/Vector2Converter.ts", - "./src/Converters/Vector3Converter.ts", - "./src/Converters/Vector4Converter.ts", - "./src/gl-matrix.d.ts", - "./src/GLM.ts", - "./src/index.ts", - "./src/IVectorParseDescription.ts", - "./src/main.ts", - "./src/Matrix.ts", - "./src/MatrixBase.ts", - "./src/Quaternion.ts", - "./src/Rectangle.ts", - "./src/Util/Angle2DParser.ts", - "./src/Vector2.ts", - "./src/Vector3.ts", - "./src/Vector4.ts", - "./src/VectorBase.ts" - ], - "exclude": [], - "atom": { - "rewriteTsconfig": true - } + "include": [ + "src/**/*.ts" + ] } \ No newline at end of file From 206421bf1b6e0bc4f6949548c68a375981a6cdf8 Mon Sep 17 00:00:00 2001 From: moajo Date: Sun, 21 Jan 2018 12:23:17 +0900 Subject: [PATCH 10/38] fix: convert tests to TypeScript --- .gitignore | 3 +- package.json | 31 ++- test/{AABBTest_.js => AABBTest_.ts} | 0 test/{Color3Test.js => Color3Test.ts} | 2 +- test/{Color4Test.js => Color4Test.ts} | 2 +- ...atrixArrayTest_.js => MatrixArrayTest_.ts} | 0 test/MatrixTest.js | 212 ----------------- test/MatrixTest.ts | 216 ++++++++++++++++++ test/{QuaternionTest.js => QuaternionTest.ts} | 8 +- test/{Vector2Test.js => Vector2Test.ts} | 2 +- test/{Vector3Test.js => Vector3Test.ts} | 2 +- test/{Vector4Test.js => Vector4Test.ts} | 2 +- ...ectorArrayTest_.js => VectorArrayTest_.ts} | 0 test/{VectorBaseTest.js => VectorBaseTest.ts} | 8 +- tsconfig.test.json | 14 ++ webpack.config.js | 2 +- 16 files changed, 270 insertions(+), 234 deletions(-) rename test/{AABBTest_.js => AABBTest_.ts} (100%) rename test/{Color3Test.js => Color3Test.ts} (95%) rename test/{Color4Test.js => Color4Test.ts} (97%) rename test/{MatrixArrayTest_.js => MatrixArrayTest_.ts} (100%) delete mode 100644 test/MatrixTest.js create mode 100644 test/MatrixTest.ts rename test/{QuaternionTest.js => QuaternionTest.ts} (93%) rename test/{Vector2Test.js => Vector2Test.ts} (98%) rename test/{Vector3Test.js => Vector3Test.ts} (99%) rename test/{Vector4Test.js => Vector4Test.ts} (99%) rename test/{VectorArrayTest_.js => VectorArrayTest_.ts} (100%) rename test/{VectorBaseTest.js => VectorBaseTest.ts} (80%) create mode 100644 tsconfig.test.json diff --git a/.gitignore b/.gitignore index 899a23d..391aa6e 100644 --- a/.gitignore +++ b/.gitignore @@ -116,4 +116,5 @@ yarn.lock src/index.ts src/metaInfo.ts docs -package-lock.json \ No newline at end of file +package-lock.json +test-lib \ No newline at end of file diff --git a/package.json b/package.json index 58a274c..bb69258 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grimoirejs-math", - "version": "2.1.0-beta", + "version": "2.1.0-beta1", "description": "The basement library for math of grimoire.js", "main": "./ref/index.js", "typings": "./ref/index.d.ts", @@ -14,16 +14,17 @@ "grimoire" ], "dependencies": { + "@types/gl-matrix": "^2.4.0", "gl-matrix": "git+https://github.com/GrimoireGL/gl-matrix.git" }, "devDependencies": { - "@types/gl-matrix": "^2.4.0", - "ava": "^0.22.0", + "ava": "^0.24.0", "babel-cli": "^6.26.0", "babel-loader": "^7.1.2", "babel-plugin-transform-runtime": "^6.23.0", - "babel-preset-es2015": "^6.24.1", + "babel-preset-env": "^1.6.1", "babel-preset-stage-2": "^6.24.1", + "babel-register": "^6.26.0", "condition-circle": "^1.5.0", "grimoirejs": "^1.0.9-beta17", "grimoirejs-cauldron": "^4.1.5-beta2", @@ -43,8 +44,8 @@ "url": "https://github.com/GrimoireGL/grimoirejs-math.git" }, "scripts": { - "test": "tsc --outDir ./lib && babel ./lib --presets es2015 --plugins transform-runtime --out-dir ./lib-es5 && babel ./test --presets es2015 --plugins transform-runtime --out-dir ./test-es5 && ava ./test-es5/**/*Test.js --verbose ", - "prepublish": "npm run build -- --env.prod&& npm test", + "test": "tsc -p tsconfig.test.json && ava --verbose --serial", + "prepare": "npm run build -- --env.prod&& npm test", "start": "webpack --progress --watch", "lint": "tslint -c tslint.json ./src/**/*.ts --project ./ --type-check --exclude ./src/index.ts", "lint:fix": "tslint -c tslint.json ./src/**/*.ts --project ./ --type-check --exclude ./src/index.ts --fix", @@ -58,5 +59,21 @@ "release": { "verifyConditions": "condition-circle" }, - "api-reference": "https://api.grimoire.gl/grimoirejs-math" + "api-reference": "https://api.grimoire.gl/grimoirejs-math", + "ava": { + "failWithoutAssertions": false, + "files": [ + "./test-lib/**/*Test.js" + ], + "require": [ + "babel-register" + ], + "babel": "inherit" + }, + "babel": { + "presets": [ + "env", + "stage-2" + ] + } } diff --git a/test/AABBTest_.js b/test/AABBTest_.ts similarity index 100% rename from test/AABBTest_.js rename to test/AABBTest_.ts diff --git a/test/Color3Test.js b/test/Color3Test.ts similarity index 95% rename from test/Color3Test.js rename to test/Color3Test.ts index 35901dd..c6e1aff 100644 --- a/test/Color3Test.js +++ b/test/Color3Test.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import Color3 from '../lib-es5/Color3'; +import Color3 from '../src/Color3'; test('parse is correct', (t) => { diff --git a/test/Color4Test.js b/test/Color4Test.ts similarity index 97% rename from test/Color4Test.js rename to test/Color4Test.ts index 510bfa0..3f802e0 100644 --- a/test/Color4Test.js +++ b/test/Color4Test.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import Color4 from '../lib-es5/Color4'; +import Color4 from '../src/Color4'; test('parse is correct', (t) => { t.truthy(!!Color4.parse("green", true)); diff --git a/test/MatrixArrayTest_.js b/test/MatrixArrayTest_.ts similarity index 100% rename from test/MatrixArrayTest_.js rename to test/MatrixArrayTest_.ts diff --git a/test/MatrixTest.js b/test/MatrixTest.js deleted file mode 100644 index c222c64..0000000 --- a/test/MatrixTest.js +++ /dev/null @@ -1,212 +0,0 @@ -import test from 'ava'; - -import Matrix from '../lib-es5/Matrix'; -import Vector3 from '../lib-es5/Vector3'; -import Vector4 from '../lib-es5/Vector4'; -import Quaternion from '../lib-es5/Quaternion'; - -test('zero', (t) => { - t.truthy(Matrix.equals( - Matrix.zero(), - new Matrix([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]))); -}); - -test('identity', (t) => { - t.truthy(Matrix.equals( - Matrix.identity(), - new Matrix([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]))); -}); - -test('fromElements', (t) => { - t.truthy(Matrix.equals( - Matrix.fromElements(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), - new Matrix([1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16]))); -}); - -test('fromFunc', (t) => { - function f(a, b) { - return a + b; - } - t.truthy(Matrix.equals(Matrix.fromFunc(f), new Matrix([0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6]))); -}); - -test('equals', (t) => { - t.truthy(Matrix.equals(Matrix.zero(), Matrix.zero())); -}); - -test('add', (t) => { - t.truthy(Matrix.equals( - Matrix.add(new Matrix([1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16]), - new Matrix([1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16])), - new Matrix([2, 10, 18, 26, 4, 12, 20, 28, 6, 14, 22, 30, 8, 16, 24, 32]))); -}); - -test('subtract', (t) => { - t.truthy(Matrix.equals( - Matrix.subtract(new Matrix([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]), new Matrix([1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4])), - new Matrix([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]))); -}); - -test('scalarMultiply', (t) => { - t.truthy(Matrix.equals( - Matrix.scalarMultiply(2, - new Matrix([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8])), - new Matrix([2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16]))); -}); - -test('multiply', (t) => { - t.truthy(Matrix.equals( - Matrix.multiply( - new Matrix([1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 4]), - new Matrix([1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 4])), - new Matrix([1, 0, 0, 0, 0, 4, 0, 0, 0, 0, 9, 0, 0, 0, 0, 16]))); -}); - -test('tRS', (t) => { - t.truthy(Matrix.equals(Matrix.trs(new Vector3([1, 2, 3]), Quaternion.euler(0, 0, 0), new Vector3([1, 2, 3])), - new Matrix([1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 1, 2, 3, 1]))); -}); - -test('negate', (t) => { - t.truthy(Matrix.equals( - Matrix.negate(new Matrix([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8])), - new Matrix([-1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6, -7, -7, -8, -8]))); -}); - -test('transpose', (t) => { - t.truthy(Matrix.equals( - Matrix.transpose(new Matrix([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8])), - new Matrix([1, 3, 5, 7, 1, 3, 5, 7, 2, 4, 6, 8, 2, 4, 6, 8]))); -}); - -test('transformPoint', (t) => { - t.truthy(Vector3.equals(Matrix.transformPoint(Matrix.translate(new Vector3([1, 2, 3])), new Vector3([1, 2, 3])), - new Vector3([2, 4, 6]))); -}); - -test('transformNormal', (t) => { - t.truthy(Vector3.equals(Matrix.transformNormal(Matrix.translate(new Vector3([1, 2, 3])), new Vector3([1, 2, 3])), - new Vector3([1, 2, 3]))); -}); - -test('transform', (t) => { - t.truthy(Vector3.equals(Matrix.transform(Matrix.translate(new Vector3([1, 2, 3])), new Vector4([1, 2, 3, 1])), - new Vector4([2, 4, 6, 1]))); -}); - -test('determinant', (t) => { - t.truthy( - Matrix.determinant(new Matrix([1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 4])) === 24); -}); - -test('inverse', (t) => { - t.truthy(Matrix.equals( - Matrix.inverse(new Matrix(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 4)), - new Matrix(1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.25))); -}); - -test('translate', (t) => { - t.truthy(Matrix.equals( - Matrix.translate(new Vector3([1, 2, 3])), - new Matrix([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1]))); -}); - -test('scale', (t) => { - t.truthy(Matrix.equals( - Matrix.scale(new Vector3([1, 2, 3])), - new Matrix([1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1]))); -}); - -test('rotateX', (t) => { - t.truthy(Matrix.equals( - Matrix.rotateX(0), - new Matrix([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]))); -}); - -test('rotateY', (t) => { - t.truthy(Matrix.equals( - Matrix.rotateY(0), - new Matrix([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]))); -}); - -test('rotateZ', (t) => { - t.truthy(Matrix.equals( - Matrix.rotateZ(0), - new Matrix([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]))); -}); - -test('rotationQuaternion', (t) => { - t.truthy(Matrix.equals(Matrix.rotationQuaternion(Quaternion.euler(0, 0, 0)), Matrix.scale(new Vector3([1, 1, 1])))); -}); - -test('frustum', (t) => { - t.truthy(Matrix.equals(new Matrix([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, -1, -1, 0, 0, 0, 0]), Matrix.frustum(0, 1, 0, 1, 0, 1))); -}); - -test('ortho', (t) => { - t.truthy(Matrix.equals(new Matrix([2, 0, 0, 0, 0, 2, 0, 0, 0, 0, -2, 0, -1, -1, -1, 1]), Matrix.ortho(0, 1, 0, 1, 0, 1))); -}); - -test('perspective', (t) => { - let m1 = Matrix.perspective(Math.PI / 4, 1, 0, 1); - let m2 = new Matrix([2.414, 0, 0, 0, 0, 2.414, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0]); - let count = 0; - for (let i = 0; i < 16; i++) { - if (Math.abs(m1.getBySingleIndex(i) - m2.getBySingleIndex(i)) < 0.01) { - count += 1; - } - } - t.truthy(count === 16); -}); - -test('lookAt', (t) => { - t.truthy(Matrix.equals(Matrix.lookAt(new Vector3([0, 0, 0]), new Vector3([0, 0, 1]), new Vector3([0, 1, 0])), - new Matrix([-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1]))); -}); - -test('getAt', (t) => { - let matrix = new Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - t.truthy(matrix.getAt(1, 1) === 6); -}); - -test('setAt', (t) => { - let matrix = new Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - matrix.setAt(1, 1, 100); - t.truthy(matrix.getAt(1, 1) === 100); -}); - -test('getBySingleIndex', (t) => { - let matrix = new Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - t.truthy(matrix.getBySingleIndex(5) === 6); -}); - -test('getColmun', (t) => { - let matrix = new Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - t.truthy(new Vector4([1, 2, 3, 4]).equalWith(matrix.getColmun(0))); -}); - -test('getRow', (t) => { - let matrix = new Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - t.truthy(new Vector4([1, 5, 9, 13]).equalWith(matrix.getRow(0))); -}); - -test('multiplyWith', (t) => { - let matrix = new Matrix([1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]); - t.truthy(Matrix.equals(new Matrix([2, 4, 6, 8, 2, 4, 6, 8, 2, 4, 6, 8, 2, 4, 6, 8]), - matrix.multiplyWith(Matrix.scalarMultiply(2, Matrix.identity())))); -}); - -test('elementCount', (t) => { - let matrix = new Matrix([1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]); - t.truthy(matrix.ElementCount === 16); -}); - -test('rowCount', (t) => { - let matrix = new Matrix([1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]); - t.truthy(matrix.RowCount === 4); -}); - -test('colmunCount', (t) => { - let matrix = new Matrix([1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]); - t.truthy(matrix.ColmunCount === 4); -}); diff --git a/test/MatrixTest.ts b/test/MatrixTest.ts new file mode 100644 index 0000000..5da0d6e --- /dev/null +++ b/test/MatrixTest.ts @@ -0,0 +1,216 @@ +import test from 'ava'; + +import Matrix from '../src/Matrix'; +import Vector3 from '../src/Vector3'; +import Vector4 from '../src/Vector4'; +import Quaternion from '../src/Quaternion'; + +test('zero', (t) => { + t.truthy(Matrix.equals( + Matrix.zero(), + new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))); +}); + +test('identity', (t) => { + t.truthy(Matrix.equals( + Matrix.identity(), + new Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1))); +}); + +test('fromElements', (t) => { + t.truthy(Matrix.equals( + Matrix.fromElements(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), + new Matrix(1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16))); +}); + +test('fromFunc', (t) => { + function f(a, b) { + return a + b; + } + t.truthy(Matrix.equals(Matrix.fromFunc(f), new Matrix(0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6))); +}); + +test('equals', (t) => { + t.truthy(Matrix.equals(Matrix.zero(), Matrix.zero())); +}); + +test('add', (t) => { + t.truthy(Matrix.equals( + Matrix.add(new Matrix(1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16), + new Matrix(1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16)), + new Matrix(2, 10, 18, 26, 4, 12, 20, 28, 6, 14, 22, 30, 8, 16, 24, 32))); +}); + +test('subtract', (t) => { + t.truthy(Matrix.equals( + Matrix.subtract(new Matrix(0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3), new Matrix(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)), + new Matrix(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1))); +}); + +test('scalarMultiply', (t) => { + t.truthy(Matrix.equals( + Matrix.scalarMultiply(2, + new Matrix(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8)), + new Matrix(2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16))); +}); + +test('multiply', (t) => { + t.truthy(Matrix.equals( + Matrix.multiply( + new Matrix(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 4), + new Matrix(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 4)), + new Matrix(1, 0, 0, 0, 0, 4, 0, 0, 0, 0, 9, 0, 0, 0, 0, 16))); +}); + +test('tRS', (t) => { + t.truthy(Matrix.equals(Matrix.trs(new Vector3(1, 2, 3), Quaternion.euler(0, 0, 0), new Vector3(1, 2, 3)), + new Matrix(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 1, 2, 3, 1))); +}); + +test('negate', (t) => { + t.truthy(Matrix.equals( + Matrix.negate(new Matrix(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8)), + new Matrix(-1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6, -7, -7, -8, -8))); +}); + +test('transpose', (t) => { + t.truthy(Matrix.equals( + Matrix.transpose(new Matrix(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8)), + new Matrix(1, 3, 5, 7, 1, 3, 5, 7, 2, 4, 6, 8, 2, 4, 6, 8))); +}); + +test('transformPoint', (t) => { + t.truthy(Vector3.equals(Matrix.transformPoint(Matrix.translate(new Vector3(1, 2, 3)), new Vector3(1, 2, 3)), + new Vector3(2, 4, 6))); +}); + +test('transformNormal', (t) => { + t.truthy(Vector3.equals(Matrix.transformNormal(Matrix.translate(new Vector3(1, 2, 3)), new Vector3(1, 2, 3)), + new Vector3(1, 2, 3))); +}); + +test('transform', (t) => { + t.truthy(Vector4.equals( + Matrix.transform( + Matrix.translate(new Vector3(1, 2, 3)), + new Vector4(1, 2, 3, 1) + ), + new Vector4(2, 4, 6, 1))); +}); + +test('determinant', (t) => { + t.truthy( + Matrix.determinant(new Matrix(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 4)) === 24); +}); + +test('inverse', (t) => { + t.truthy(Matrix.equals( + Matrix.inverse(new Matrix(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 4)), + new Matrix(1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.25))); +}); + +test('translate', (t) => { + t.truthy(Matrix.equals( + Matrix.translate(new Vector3(1, 2, 3)), + new Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1))); +}); + +test('scale', (t) => { + t.truthy(Matrix.equals( + Matrix.scale(new Vector3(1, 2, 3)), + new Matrix(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1))); +}); + +test('rotateX', (t) => { + t.truthy(Matrix.equals( + Matrix.rotateX(0), + new Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1))); +}); + +test('rotateY', (t) => { + t.truthy(Matrix.equals( + Matrix.rotateY(0), + new Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1))); +}); + +test('rotateZ', (t) => { + t.truthy(Matrix.equals( + Matrix.rotateZ(0), + new Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1))); +}); + +test('rotationQuaternion', (t) => { + t.truthy(Matrix.equals(Matrix.rotationQuaternion(Quaternion.euler(0, 0, 0)), Matrix.scale(new Vector3(1, 1, 1)))); +}); + +test('frustum', (t) => { + t.truthy(Matrix.equals(new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, -1, -1, 0, 0, 0, 0), Matrix.frustum(0, 1, 0, 1, 0, 1))); +}); + +test('ortho', (t) => { + t.truthy(Matrix.equals(new Matrix(2, 0, 0, 0, 0, 2, 0, 0, 0, 0, -2, 0, -1, -1, -1, 1), Matrix.ortho(0, 1, 0, 1, 0, 1))); +}); + +test('perspective', (t) => { + let m1 = Matrix.perspective(Math.PI / 4, 1, 0, 1); + let m2 = new Matrix(2.414, 0, 0, 0, 0, 2.414, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0); + let count = 0; + for (let i = 0; i < 16; i++) { + if (Math.abs(m1.getBySingleIndex(i) - m2.getBySingleIndex(i)) < 0.01) { + count += 1; + } + } + t.truthy(count === 16); +}); + +test('lookAt', (t) => { + t.truthy(Matrix.equals(Matrix.lookAt(new Vector3(0, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 1, 0)), + new Matrix(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1))); +}); + +test('getAt', (t) => { + let matrix = new Matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + t.truthy(matrix.getAt(1, 1) === 6); +}); + +test('setAt', (t) => { + let matrix = new Matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + matrix.setAt(1, 1, 100); + t.truthy(matrix.getAt(1, 1) === 100); +}); + +test('getBySingleIndex', (t) => { + let matrix = new Matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + t.truthy(matrix.getBySingleIndex(5) === 6); +}); + +test('getColmun', (t) => { + let matrix = new Matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + t.truthy(new Vector4(1, 2, 3, 4).equalWith(matrix.getColmun(0))); +}); + +test('getRow', (t) => { + let matrix = new Matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + t.truthy(new Vector4(1, 5, 9, 13).equalWith(matrix.getRow(0))); +}); + +test('multiplyWith', (t) => { + let matrix = new Matrix(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4); + t.truthy(Matrix.equals(new Matrix(2, 4, 6, 8, 2, 4, 6, 8, 2, 4, 6, 8, 2, 4, 6, 8), + matrix.multiplyWith(Matrix.scalarMultiply(2, Matrix.identity())))); +}); + +test('elementCount', (t) => { + let matrix = new Matrix(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4); + t.truthy(matrix.ElementCount === 16); +}); + +test('rowCount', (t) => { + let matrix = new Matrix(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4); + t.truthy(matrix.RowCount === 4); +}); + +test('colmunCount', (t) => { + let matrix = new Matrix(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4); + t.truthy(matrix.ColmunCount === 4); +}); diff --git a/test/QuaternionTest.js b/test/QuaternionTest.ts similarity index 93% rename from test/QuaternionTest.js rename to test/QuaternionTest.ts index cb3d5f8..763534e 100644 --- a/test/QuaternionTest.js +++ b/test/QuaternionTest.ts @@ -1,8 +1,8 @@ import test from 'ava'; -import Quaternion from '../lib-es5/Quaternion'; -import Vector3 from '../lib-es5/Vector3'; -import Matrix from '../lib-es5/Matrix'; +import Quaternion from '../src/Quaternion'; +import Vector3 from '../src/Vector3'; +import Matrix from '../src/Matrix'; test('equals', (t) => { t.truthy(Quaternion.equals(Quaternion.euler(10, 20, 30), Quaternion.euler(10, 20, 30))); @@ -58,7 +58,7 @@ test('get W', (t) => { test('get ImaginaryPart', (t) => { t.truthy(Vector3.equals(new Quaternion(10, 20, 20, 10).ImaginaryPart, - new Vector3([10, 20, 20]))); + new Vector3(10, 20, 20))); }); test('get Conjugate', (t) => { diff --git a/test/Vector2Test.js b/test/Vector2Test.ts similarity index 98% rename from test/Vector2Test.js rename to test/Vector2Test.ts index 8656d4b..72ce6d2 100644 --- a/test/Vector2Test.js +++ b/test/Vector2Test.ts @@ -1,6 +1,6 @@ import test from 'ava'; -import Vector2 from '../lib-es5/Vector2'; +import Vector2 from '../src/Vector2'; test('equal with is correct', (t) => { t.truthy((new Vector2(1, 0)).equalWith(new Vector2(1, 0))); diff --git a/test/Vector3Test.js b/test/Vector3Test.ts similarity index 99% rename from test/Vector3Test.js rename to test/Vector3Test.ts index d8218f1..8fc8eec 100644 --- a/test/Vector3Test.js +++ b/test/Vector3Test.ts @@ -1,6 +1,6 @@ import test from 'ava'; -import Vector3 from '../lib-es5/Vector3'; +import Vector3 from '../src/Vector3'; test('equal with is correct', (t) => { t.truthy((new Vector3(1, 1, 0)).equalWith(new Vector3(1, 1, 0))); diff --git a/test/Vector4Test.js b/test/Vector4Test.ts similarity index 99% rename from test/Vector4Test.js rename to test/Vector4Test.ts index c835a8b..25442af 100644 --- a/test/Vector4Test.js +++ b/test/Vector4Test.ts @@ -1,6 +1,6 @@ import test from 'ava'; -import Vector4 from '../lib-es5/Vector4'; +import Vector4 from '../src/Vector4'; const BLOCK = 'Vector4'; diff --git a/test/VectorArrayTest_.js b/test/VectorArrayTest_.ts similarity index 100% rename from test/VectorArrayTest_.js rename to test/VectorArrayTest_.ts diff --git a/test/VectorBaseTest.js b/test/VectorBaseTest.ts similarity index 80% rename from test/VectorBaseTest.js rename to test/VectorBaseTest.ts index d14210b..a90b68a 100644 --- a/test/VectorBaseTest.js +++ b/test/VectorBaseTest.ts @@ -1,9 +1,9 @@ import test from 'ava'; -import VectorBase from '../lib-es5/VectorBase'; -import Vector2 from '../lib-es5/Vector2'; -import Vector3 from '../lib-es5/Vector3'; -import Vector4 from '../lib-es5/Vector4'; +import VectorBase from '../src/VectorBase'; +import Vector2 from '../src/Vector2'; +import Vector3 from '../src/Vector3'; +import Vector4 from '../src/Vector4'; let error = 0.01; diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 0000000..32607c1 --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "es6", + "outDir":"./test-lib", + "moduleResolution": "node", + "inlineSourceMap": true + }, + "include": [ + "src/**/*.ts", + "test/**/*.ts" + ] + } + \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 9e5de7d..50d9078 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -54,7 +54,7 @@ const getBuildTask = (fileName, plugins, needPolyfill) => { loaders: [{ test: /\.ts$/, exclude: /node_modules/, - loader: "babel-loader?presets[]=es2015,presets[]=stage-2!ts-loader" + loader: "babel-loader?presets[]=env,presets[]=stage-2!ts-loader" }] }, resolve: { From ed480ddb7f8f4c7cb9ad199d9cc647c7d4d72886 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Fri, 26 Jan 2018 01:50:44 +0900 Subject: [PATCH 11/38] fix: AABB constructor bug --- package.json | 8 ++++---- src/AABB.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index bb69258..4faf635 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grimoirejs-math", - "version": "2.1.0-beta1", + "version": "2.1.0-beta4", "description": "The basement library for math of grimoire.js", "main": "./ref/index.js", "typings": "./ref/index.d.ts", @@ -26,8 +26,8 @@ "babel-preset-stage-2": "^6.24.1", "babel-register": "^6.26.0", "condition-circle": "^1.5.0", - "grimoirejs": "^1.0.9-beta17", - "grimoirejs-cauldron": "^4.1.5-beta2", + "grimoirejs": "^1.0.9-beta23", + "grimoirejs-cauldron": "^4.2.0-beta1", "semantic-release": "^7.0.2", "ts-loader": "^2.3.3", "tslint": "^5.7.0", @@ -76,4 +76,4 @@ "stage-2" ] } -} +} \ No newline at end of file diff --git a/src/AABB.ts b/src/AABB.ts index c998961..b988d89 100644 --- a/src/AABB.ts +++ b/src/AABB.ts @@ -9,7 +9,7 @@ export default class AABB { constructor(initialPoints?: Vector3[]) { if (initialPoints) { - initialPoints.forEach(this.expand); + initialPoints.forEach((p) => this.expand(p)); } } /** From 29b5ca5e03d779cfead7816edc9e5240662ce484 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Fri, 26 Jan 2018 15:43:56 +0000 Subject: [PATCH 12/38] chore(package): update ava to version 0.25.0 Closes #57 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b4af466..d99d919 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "gl-matrix": "https://github.com/GrimoireGL/gl-matrix.git" }, "devDependencies": { - "ava": "^0.22.0", + "ava": "^0.25.0", "babel-cli": "^6.26.0", "babel-loader": "^7.1.2", "babel-plugin-transform-runtime": "^6.23.0", From 78e7e3d639d6ace05454736fb4fa15e05cde221a Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sun, 28 Jan 2018 00:10:29 +0000 Subject: [PATCH 13/38] chore(package): update semantic-release to version 12.4.1 Closes #52 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b4af466..24ab018 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "condition-circle": "^1.5.0", "grimoirejs": "^0.19.5", "grimoirejs-cauldron": "^3.1.6", - "semantic-release": "^7.0.2", + "semantic-release": "^12.4.1", "ts-loader": "^2.3.3", "typedoc": "^0.8.0", "typescript": "^2.4.2", From ad74f4449b9c2945e618ed0dd3c6a722255c5609 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 1 Feb 2018 11:48:25 +0000 Subject: [PATCH 14/38] chore(package): update typedoc to version 0.10.0 Closes #55 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b4af466..ef95e82 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "grimoirejs-cauldron": "^3.1.6", "semantic-release": "^7.0.2", "ts-loader": "^2.3.3", - "typedoc": "^0.8.0", + "typedoc": "^0.10.0", "typescript": "^2.4.2", "webpack": "^3.5.5", "webpack-shell-plugin": "^0.5.0" From f6c3ed72581c2a0c07fce6fa59798638ec95bae3 Mon Sep 17 00:00:00 2001 From: moajo Date: Sun, 18 Feb 2018 13:42:39 +0900 Subject: [PATCH 15/38] update dependencies --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fa8bb56..a90c256 100644 --- a/package.json +++ b/package.json @@ -25,11 +25,11 @@ "babel-preset-env": "^1.6.1", "babel-preset-stage-2": "^6.24.1", "babel-register": "^6.26.0", - "condition-circle": "^1.5.0", + "condition-circle": "^2.0.1", "grimoirejs": "^1.0.9-beta17", "grimoirejs-cauldron": "^4.1.5-beta2", "semantic-release": "^12.4.1", - "ts-loader": "^2.3.3", + "ts-loader": "^3.5.0", "tslint": "^5.7.0", "typedoc": "^0.10.0", "typescript": "^2.6.2", From aada50144a3799d0924db1668375ede759f942fb Mon Sep 17 00:00:00 2001 From: moajo Date: Sun, 18 Feb 2018 14:10:02 +0900 Subject: [PATCH 16/38] fix: webpack.config --- webpack.config.js | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 50d9078..65721c6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -65,41 +65,42 @@ const getBuildTask = (fileName, plugins, needPolyfill) => { } }; -module.exports = (env) => { +module.exports = (env = {}) => { + // This line might need to be modified for each plugin build environment. + // If the plugin containing grimoirejs directly(calling require("grimoirejs/register")), + // browser build and production build should contain babel-polyfill. + // Make sure this is not require("grimoirejs") let includeCore = false; - // if this package was preset including core or core package, - // Script for browser needs babel-polyfill - let polyfills = includeCore ? [true, false, true] : [false, false, false]; - env = env || {}; + // + // + // + if (!env.browser && !env.npm && !env.prod) { + env.browser = true; + } + const productPlugins = [new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }), new webpack.optimize.OccurrenceOrderPlugin(), new webpack.optimize.AggressiveMergingPlugin()]; let buildTasks = []; - let isDefault = !env.browser && !env.npm && !env.prod; let skipIndex = false; let cauldron = new CauldronPlugin(); if (env.browser || env.prod) { - const plugins = [cauldron]; + const plugins = []; // if needs index also and it was not including core, index.js must be copied from fnPrefix.js // since these are completely same build task. Yeah, optimization. if (!includeCore && (env.prod || env.npm)) { plugins.push(new CopyPlugin(`./register/${fnPrefix}.js`, './register/index.js')); plugins.push(new CopyPlugin(`./register/${fnPrefix}.js.map`, './register/index.js.map')); skipIndex = true; + console.log(`index.js will be generated for NPM environment by copy`); } - buildTasks.push(getBuildTask(`${fnPrefix}.js`, plugins, polyfills[0])); + buildTasks.push(getBuildTask(`${fnPrefix}.js`, [cauldron, ...plugins], includeCore)); + console.log(`${fnPrefix}.js will be generated for browser environment`); } - if (!skipIndex && (isDefault || env.npm || env.prod)) { - buildTasks.push(getBuildTask("index.js", [cauldron], polyfills[1])); + if (!skipIndex && (env.npm || env.prod)) { + buildTasks.push(getBuildTask("index.js", [cauldron], false)); + console.log(`index.js will be generated for NPM environment`); } if (env.prod) { - buildTasks.push(getBuildTask(fnPrefix + ".min.js", [ - cauldron, - new webpack.optimize.UglifyJsPlugin({ - compress: { - warnings: false - } - }), - new webpack.optimize.OccurrenceOrderPlugin(), - new webpack.optimize.AggressiveMergingPlugin() - ], polyfills[2])); + buildTasks.push(getBuildTask(fnPrefix + ".min.js", [cauldron, ...productPlugins], includeCore)); + console.log(`${fnPrefix}.min.js will be generated for browser environment`); } return buildTasks; }; From 4a8d627bcefd815108379cb7263eab3929f66f6e Mon Sep 17 00:00:00 2001 From: moajo Date: Sun, 18 Feb 2018 15:15:05 +0900 Subject: [PATCH 17/38] adopt typescript2.7 --- package.json | 6 +++--- src/AABB.ts | 6 +++--- src/MatrixBase.ts | 2 +- src/VectorBase.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index a90c256..8719977 100644 --- a/package.json +++ b/package.json @@ -30,10 +30,10 @@ "grimoirejs-cauldron": "^4.1.5-beta2", "semantic-release": "^12.4.1", "ts-loader": "^3.5.0", - "tslint": "^5.7.0", + "tslint": "^5.9.1", "typedoc": "^0.10.0", - "typescript": "^2.6.2", - "webpack": "^3.5.5", + "typescript": "^2.7.2", + "webpack": "^3.11.0", "webpack-shell-plugin": "^0.5.0" }, "peerDependencies": { diff --git a/src/AABB.ts b/src/AABB.ts index c998961..65b5a4c 100644 --- a/src/AABB.ts +++ b/src/AABB.ts @@ -16,19 +16,19 @@ export default class AABB { * AABB's vertex in most left,most bottom,most far. * @type {Vector3} */ - public pointLBF: Vector3; + public pointLBF!: Vector3; /** * AABB's vertex in most right,most top,most near. * @type {Vector3} */ - public pointRTN: Vector3; + public pointRTN!: Vector3; /** * Center of this AABB * @type {Vector3} */ - private _center: Nullable; + private _center!: Nullable; /** * Width of this AABB diff --git a/src/MatrixBase.ts b/src/MatrixBase.ts index 05a6131..0a2e726 100644 --- a/src/MatrixBase.ts +++ b/src/MatrixBase.ts @@ -1,7 +1,7 @@ export default abstract class MatrixBase { - public rawElements: T; + public rawElements!: T; protected static __elementEquals(m1: MatrixBase, m2: MatrixBase): boolean { if (m1.RowCount !== m2.RowCount || m1.ColmunCount !== m2.ColmunCount) { diff --git a/src/VectorBase.ts b/src/VectorBase.ts index 89d7504..1f88edf 100644 --- a/src/VectorBase.ts +++ b/src/VectorBase.ts @@ -7,7 +7,7 @@ export default abstract class VectorBase { /** * Actual array represents components of this instance. */ - public rawElements: T; + public rawElements!: T; private _magnitudeSquaredCache = -1; private _magnitudeCache = -1; From 31c111cd76f6cd3374820c96e1943099635fe846 Mon Sep 17 00:00:00 2001 From: moajo Date: Sun, 18 Feb 2018 15:17:44 +0900 Subject: [PATCH 18/38] publish beta --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8719977..13c05fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grimoirejs-math", - "version": "2.1.0-beta1", + "version": "2.1.0-beta6", "description": "The basement library for math of grimoire.js", "main": "./ref/index.js", "typings": "./ref/index.d.ts", From 252570af2344bf1bba7fd6ec34c38a14b8cbb21c Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Sun, 18 Feb 2018 15:19:51 +0900 Subject: [PATCH 19/38] publish beta --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4faf635..3370520 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grimoirejs-math", - "version": "2.1.0-beta4", + "version": "2.1.0-beta5", "description": "The basement library for math of grimoire.js", "main": "./ref/index.js", "typings": "./ref/index.d.ts", From 0ccf475dece7b9c05e78c5942e465791a5412abb Mon Sep 17 00:00:00 2001 From: moajo Date: Sun, 18 Feb 2018 15:38:19 +0900 Subject: [PATCH 20/38] publish beta --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4910ed6..a6e7f87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grimoirejs-math", - "version": "2.1.0-beta6", + "version": "2.1.0-beta7", "description": "The basement library for math of grimoire.js", "main": "./ref/index.js", "typings": "./ref/index.d.ts", From 724dfe5812ddc00fbad25a3b3e548a569339fdc5 Mon Sep 17 00:00:00 2001 From: m2wasabi Date: Fri, 2 Mar 2018 06:10:26 +0900 Subject: [PATCH 21/38] [CI] CircleCI 2.0 migration --- .circleci/config.yml | 92 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..54aa713 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,92 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/node:9.6 + environment: + TZ: /usr/share/zoneinfo/UTC + steps: + - checkout + - restore_cache: + key: dependency-cache-{{ checksum "package.json" }} + - run: sudo apt update && sudo apt install python-pip python-dev + - run: pip install awscli --upgrade --user + - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV + - run: yarn --version + - run: yarn install + - run: npm run build + - save-cache: + key: dependency-cache-{{ checksum "package.json" }} + paths: + - ~/.local + - ~/.npm/_cacache + - ~/.cache/yarn + - node_modules/ + - save-cache: + key: artifact-cache-{{ .Environment.CIRCLE_SHA1 }} + paths: + - lib/ + - lib-es5/ + - ref/ + - register/ + - test-es5/ + - yarn.lock + - src/index.ts + test: + docker: + - image: circleci/node:9.6 + environment: + TZ: /usr/share/zoneinfo/UTC + steps: + - checkout + - restore_cache: + key: dependency-cache-{{ checksum "package.json" }} + - restore_cache: + key: artifact-cache-{{ .Environment.CIRCLE_SHA1 }} + - run: npm test + - run: sh ./common/e2e.sh + - run: sh release.sh + - run: + name: Move Artifacts + command: mv register /tmp/artifacts/ + - store_artifacts: + path: /tmp/artifacts/register + deploy_master: + docker: + - image: circleci/node:9.6 + environment: + TZ: /usr/share/zoneinfo/UTC + steps: + - checkout + - restore_cache: + key: dependency-cache-{{ checksum "package.json" }} + - restore_cache: + key: artifact-cache-{{ .Environment.CIRCLE_SHA1 }} + - run: sudo apt update && sudo apt install python-pip python-dev + - run: pip install awscli --upgrade --user + - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV + - run: npm run doc + - run: + name: Move Artifacts + command: mv docs /tmp/artifacts/ + - store_artifacts: + path: /tmp/artifacts/docs + - run: + name: document deploy + command: aws s3 cp /tmp/artifacts/docs/ s3://api.grimoire.gl/$CIRCLE_PROJECT_REPONAME --recursive --acl public-read + +workflows: + version: 2 + workflow: + jobs: + - build + - test: + requires: + - build + - deploy_master: + requires: + - build + - test + filters: + branches: + only: master From 0f822705fba5fce7d614d4067f1ccb073b1257e5 Mon Sep 17 00:00:00 2001 From: m2wasabi Date: Fri, 2 Mar 2018 06:14:10 +0900 Subject: [PATCH 22/38] [CI] CircleCI 2.0 migration (install awscli on test) --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 54aa713..bee0f96 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -43,6 +43,9 @@ jobs: key: dependency-cache-{{ checksum "package.json" }} - restore_cache: key: artifact-cache-{{ .Environment.CIRCLE_SHA1 }} + - run: sudo apt update && sudo apt install python-pip python-dev + - run: pip install awscli --upgrade --user + - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: npm test - run: sh ./common/e2e.sh - run: sh release.sh From 1e4bbd993dd2838c22c03935f194eb573723069d Mon Sep 17 00:00:00 2001 From: m2wasabi Date: Fri, 2 Mar 2018 06:20:39 +0900 Subject: [PATCH 23/38] [CI] CircleCI 2.0 migration (checkout submodules) --- .circleci/config.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index bee0f96..0ddca63 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,6 +7,8 @@ jobs: TZ: /usr/share/zoneinfo/UTC steps: - checkout + - run: git submodule sync + - run: git submodule update --init - restore_cache: key: dependency-cache-{{ checksum "package.json" }} - run: sudo apt update && sudo apt install python-pip python-dev @@ -39,6 +41,8 @@ jobs: TZ: /usr/share/zoneinfo/UTC steps: - checkout + - run: git submodule sync + - run: git submodule update --init - restore_cache: key: dependency-cache-{{ checksum "package.json" }} - restore_cache: @@ -61,6 +65,8 @@ jobs: TZ: /usr/share/zoneinfo/UTC steps: - checkout + - run: git submodule sync + - run: git submodule update --init - restore_cache: key: dependency-cache-{{ checksum "package.json" }} - restore_cache: From 16a6cbc9fcef2af74f210c9fe466ee3136b43515 Mon Sep 17 00:00:00 2001 From: m2wasabi Date: Fri, 2 Mar 2018 06:29:25 +0900 Subject: [PATCH 24/38] [CI] CircleCI 2.0 migration (upload articacts in directory) --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0ddca63..68f3596 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -55,7 +55,7 @@ jobs: - run: sh release.sh - run: name: Move Artifacts - command: mv register /tmp/artifacts/ + command: mv register/ /tmp/artifacts/ - store_artifacts: path: /tmp/artifacts/register deploy_master: @@ -77,7 +77,7 @@ jobs: - run: npm run doc - run: name: Move Artifacts - command: mv docs /tmp/artifacts/ + command: mv docs/ /tmp/artifacts/ - store_artifacts: path: /tmp/artifacts/docs - run: From 7416042e0642f4447dfc4e8deae6ed0ca174a0f7 Mon Sep 17 00:00:00 2001 From: m2wasabi Date: Fri, 2 Mar 2018 07:35:21 +0900 Subject: [PATCH 25/38] [CI] CircleCI 2.0 migration (npm and docs parallel release) --- .circleci/config.yml | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 68f3596..749a3ec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -51,13 +51,26 @@ jobs: - run: pip install awscli --upgrade --user - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: npm test + - store_artifacts: + path: /home/circleci/project/register + e2e_release: + docker: + - image: circleci/node:9.6 + environment: + TZ: /usr/share/zoneinfo/UTC + steps: + - checkout + - run: git submodule sync + - run: git submodule update --init + - restore_cache: + key: dependency-cache-{{ checksum "package.json" }} + - restore_cache: + key: artifact-cache-{{ .Environment.CIRCLE_SHA1 }} + - run: sudo apt update && sudo apt install python-pip python-dev + - run: pip install awscli --upgrade --user + - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: sh ./common/e2e.sh - run: sh release.sh - - run: - name: Move Artifacts - command: mv register/ /tmp/artifacts/ - - store_artifacts: - path: /tmp/artifacts/register deploy_master: docker: - image: circleci/node:9.6 @@ -75,11 +88,8 @@ jobs: - run: pip install awscli --upgrade --user - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: npm run doc - - run: - name: Move Artifacts - command: mv docs/ /tmp/artifacts/ - store_artifacts: - path: /tmp/artifacts/docs + path: /home/circleci/project/docs - run: name: document deploy command: aws s3 cp /tmp/artifacts/docs/ s3://api.grimoire.gl/$CIRCLE_PROJECT_REPONAME --recursive --acl public-read @@ -92,6 +102,10 @@ workflows: - test: requires: - build + - e2e_release: + requires: + - build + - test - deploy_master: requires: - build From 3decc5e08bbbf9f99e03e548c41693137a349667 Mon Sep 17 00:00:00 2001 From: m2wasabi Date: Fri, 2 Mar 2018 14:49:50 +0900 Subject: [PATCH 26/38] [CI] CircleCI 2.0 migration (parallel release and artifacts test : dry run) --- .circleci/config.yml | 51 +++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 749a3ec..9e14e77 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -51,9 +51,7 @@ jobs: - run: pip install awscli --upgrade --user - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: npm test - - store_artifacts: - path: /home/circleci/project/register - e2e_release: + common_e2e: docker: - image: circleci/node:9.6 environment: @@ -70,8 +68,27 @@ jobs: - run: pip install awscli --upgrade --user - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: sh ./common/e2e.sh + - run: mkdir /tmp/artifacts/register && mv register /tmp/artifacts/register + - store_artifacts: + path: /tmp/artifacts/register + npm_release: + docker: + - image: circleci/node:9.6 + environment: + TZ: /usr/share/zoneinfo/UTC + steps: + - checkout + - run: git submodule sync + - run: git submodule update --init + - restore_cache: + key: dependency-cache-{{ checksum "package.json" }} + - restore_cache: + key: artifact-cache-{{ .Environment.CIRCLE_SHA1 }} + - run: sudo apt update && sudo apt install python-pip python-dev + - run: pip install awscli --upgrade --user + - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: sh release.sh - deploy_master: + deploy_docs: docker: - image: circleci/node:9.6 environment: @@ -88,11 +105,12 @@ jobs: - run: pip install awscli --upgrade --user - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: npm run doc + - run: mkdir /tmp/artifacts/docs && mv docs /tmp/artifacts/docs - store_artifacts: - path: /home/circleci/project/docs - - run: - name: document deploy - command: aws s3 cp /tmp/artifacts/docs/ s3://api.grimoire.gl/$CIRCLE_PROJECT_REPONAME --recursive --acl public-read + path: /tmp/artifacts/docs + # - run: + # name: document deploy + # command: aws s3 cp /tmp/artifacts/docs/ s3://api.grimoire.gl/$CIRCLE_PROJECT_REPONAME --recursive --acl public-read workflows: version: 2 @@ -102,14 +120,21 @@ workflows: - test: requires: - build - - e2e_release: + - common_e2e: + requires: + - build + - test + - npm_release: requires: - build - test - - deploy_master: + # filters: + # branches: + # only: master + - deploy_docs: requires: - build - test - filters: - branches: - only: master + # filters: + # branches: + # only: master From 93a6c7c5ccba728f0f5b8fe5a558c22450345114 Mon Sep 17 00:00:00 2001 From: m2wasabi Date: Fri, 2 Mar 2018 14:57:44 +0900 Subject: [PATCH 27/38] [CI] CircleCI 2.0 migration (fix: create directory recursive) --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9e14e77..e360e38 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -68,7 +68,7 @@ jobs: - run: pip install awscli --upgrade --user - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: sh ./common/e2e.sh - - run: mkdir /tmp/artifacts/register && mv register /tmp/artifacts/register + - run: mkdir -p /tmp/artifacts/register && mv register /tmp/artifacts/register - store_artifacts: path: /tmp/artifacts/register npm_release: @@ -105,7 +105,7 @@ jobs: - run: pip install awscli --upgrade --user - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: npm run doc - - run: mkdir /tmp/artifacts/docs && mv docs /tmp/artifacts/docs + - run: mkdir -p /tmp/artifacts/docs && mv docs /tmp/artifacts/docs - store_artifacts: path: /tmp/artifacts/docs # - run: From 03b6a0b74d8a425dad262822f890afc2fe4cce44 Mon Sep 17 00:00:00 2001 From: m2wasabi Date: Fri, 2 Mar 2018 15:05:03 +0900 Subject: [PATCH 28/38] [CI] CircleCI 2.0 migration (fix: directory depth) --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e360e38..0de2876 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -68,7 +68,7 @@ jobs: - run: pip install awscli --upgrade --user - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: sh ./common/e2e.sh - - run: mkdir -p /tmp/artifacts/register && mv register /tmp/artifacts/register + - run: mkdir -p /tmp/artifacts && mv register /tmp/artifacts/ - store_artifacts: path: /tmp/artifacts/register npm_release: @@ -105,7 +105,7 @@ jobs: - run: pip install awscli --upgrade --user - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: npm run doc - - run: mkdir -p /tmp/artifacts/docs && mv docs /tmp/artifacts/docs + - run: mkdir -p /tmp/artifacts && mv docs /tmp/artifacts/ - store_artifacts: path: /tmp/artifacts/docs # - run: From a27303c4ea643aa1298530520126b36cf64743e8 Mon Sep 17 00:00:00 2001 From: m2wasabi Date: Fri, 2 Mar 2018 15:12:52 +0900 Subject: [PATCH 29/38] [CI] CircleCI 2.0 migration (unlock upload docs) --- .circleci/config.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0de2876..7285ada 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -108,9 +108,9 @@ jobs: - run: mkdir -p /tmp/artifacts && mv docs /tmp/artifacts/ - store_artifacts: path: /tmp/artifacts/docs - # - run: - # name: document deploy - # command: aws s3 cp /tmp/artifacts/docs/ s3://api.grimoire.gl/$CIRCLE_PROJECT_REPONAME --recursive --acl public-read + - run: + name: document deploy + command: aws s3 cp /tmp/artifacts/docs/ s3://api.grimoire.gl/$CIRCLE_PROJECT_REPONAME --recursive --acl public-read workflows: version: 2 @@ -128,13 +128,13 @@ workflows: requires: - build - test - # filters: - # branches: - # only: master + filters: + branches: + only: master - deploy_docs: requires: - build - test - # filters: - # branches: - # only: master + filters: + branches: + only: master From 7023bc557a1fe4a449957894af5f6bb53863aa55 Mon Sep 17 00:00:00 2001 From: m2wasabi Date: Wed, 7 Mar 2018 16:07:02 +0900 Subject: [PATCH 30/38] [CI] CircleCI 2.0 Yarn skip npm-scripts --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7285ada..8fa3cce 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,7 +15,7 @@ jobs: - run: pip install awscli --upgrade --user - run: echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - run: yarn --version - - run: yarn install + - run: yarn install --ignore-scripts --no-progress - run: npm run build - save-cache: key: dependency-cache-{{ checksum "package.json" }} From f254d96bdaa9d45732a5376553f7e097f81b3f95 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Tue, 13 Mar 2018 18:10:10 +0900 Subject: [PATCH 31/38] update common --- common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common b/common index 7cb3fe2..4dce05a 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 7cb3fe2bcbbea238e4090024820ff7c2c3213187 +Subproject commit 4dce05a3156b9fd65a1683f7018eda92737151c4 From 3ed90f2a5304d36df94351e669b63483edd774ce Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Tue, 13 Mar 2018 18:13:34 +0900 Subject: [PATCH 32/38] Updated cauldron dependency --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a6e7f87..9a478c3 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "babel-register": "^6.26.0", "condition-circle": "^2.0.1", "grimoirejs": "^1.0.9-beta17", - "grimoirejs-cauldron": "^4.1.5-beta2", + "grimoirejs-cauldron": "^4.2.0-beta3", "semantic-release": "^12.4.1", "ts-loader": "^3.5.0", "tslint": "^5.9.1", @@ -76,4 +76,4 @@ "stage-2" ] } -} \ No newline at end of file +} From 8cb59e81c0760a44dd09e64e675dd943e9ae5223 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Tue, 13 Mar 2018 22:20:45 +0900 Subject: [PATCH 33/38] include metaInfo.ts inside of circleci cache --- .circleci/config.yml | 1 + circle.yml | 21 --------------------- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 circle.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index 8fa3cce..99fba78 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,6 +34,7 @@ jobs: - test-es5/ - yarn.lock - src/index.ts + - src/metaInfo.ts test: docker: - image: circleci/node:9.6 diff --git a/circle.yml b/circle.yml deleted file mode 100644 index e3c3ffe..0000000 --- a/circle.yml +++ /dev/null @@ -1,21 +0,0 @@ -machine: - node: - version: 9.3.0 -test: - post: - - sh release.sh - override: - - npm run build && npm test - - sh ./common/e2e.sh -checkout: - post: - - git submodule init - - git submodule update -deployment: - deploy: - branch: master - commands: - - npm run doc - - >- - aws s3 cp ./docs/ s3://api.grimoire.gl/$CIRCLE_PROJECT_REPONAME - --recursive --acl public-read From d8fc66c173e2cf608d127bd953dab9f081371188 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Tue, 13 Mar 2018 22:24:31 +0900 Subject: [PATCH 34/38] rewrite dependent grimore version --- package.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9a478c3..2033874 100644 --- a/package.json +++ b/package.json @@ -75,5 +75,14 @@ "env", "stage-2" ] + }, + "e2e": { + "dependencies": { + "grimoirejs": "beta", + "fundamental": "beta", + "forward-shading": "beta", + "animation": "beta", + "gltf": "beta" + } } -} +} \ No newline at end of file From eee96dacf547958b9c5ba5751e124062d6a70818 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Tue, 13 Mar 2018 23:13:41 +0900 Subject: [PATCH 35/38] updated grimoirejs dependency --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2033874..6e17f2a 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "babel-preset-stage-2": "^6.24.1", "babel-register": "^6.26.0", "condition-circle": "^2.0.1", - "grimoirejs": "^1.0.9-beta17", + "grimoirejs": "^1.0.9-beta41", "grimoirejs-cauldron": "^4.2.0-beta3", "semantic-release": "^12.4.1", "ts-loader": "^3.5.0", @@ -85,4 +85,4 @@ "gltf": "beta" } } -} \ No newline at end of file +} From b884754c4987ca47e9136774fb8fe6679eda05f0 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Wed, 14 Mar 2018 08:53:58 +0900 Subject: [PATCH 36/38] WIP try to list packages --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 99fba78..c147c93 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,6 +24,7 @@ jobs: - ~/.npm/_cacache - ~/.cache/yarn - node_modules/ + - run: yarn list - save-cache: key: artifact-cache-{{ .Environment.CIRCLE_SHA1 }} paths: From b0bc8dfe1dee47d5de81ae597f0e407ba5250dd7 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Wed, 14 Mar 2018 08:55:58 +0900 Subject: [PATCH 37/38] rewrite dependency --- package.json | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 6e17f2a..05b95d2 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ ], "dependencies": { "@types/gl-matrix": "^2.4.0", - "gl-matrix": "git+https://github.com/GrimoireGL/gl-matrix.git" + "gl-matrix": "git+https://github.com/GrimoireGL/gl-matrix.git", + "grimoirejs": "^1.0.9-beta41" }, "devDependencies": { "ava": "^0.25.0", @@ -26,7 +27,6 @@ "babel-preset-stage-2": "^6.24.1", "babel-register": "^6.26.0", "condition-circle": "^2.0.1", - "grimoirejs": "^1.0.9-beta41", "grimoirejs-cauldron": "^4.2.0-beta3", "semantic-release": "^12.4.1", "ts-loader": "^3.5.0", @@ -36,9 +36,6 @@ "webpack": "^3.11.0", "webpack-shell-plugin": "^0.5.0" }, - "peerDependencies": { - "grimoirejs": "^0.16.0" - }, "repository": { "type": "git", "url": "https://github.com/GrimoireGL/grimoirejs-math.git" @@ -85,4 +82,4 @@ "gltf": "beta" } } -} +} \ No newline at end of file From 7b011ab5074f12e67539d96461d4d7fbede063e9 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Wed, 14 Mar 2018 09:03:52 +0900 Subject: [PATCH 38/38] replace grimoire version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 05b95d2..324d8b6 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "dependencies": { "@types/gl-matrix": "^2.4.0", "gl-matrix": "git+https://github.com/GrimoireGL/gl-matrix.git", - "grimoirejs": "^1.0.9-beta41" + "grimoirejs": "1.0.9-beta41" }, "devDependencies": { "ava": "^0.25.0",