mirror of
https://github.com/openglobus/openglobus.git
synced 2025-12-08 19:25:27 +00:00
#698 Migrated a few math modules to typescript
This commit is contained in:
parent
5cacdd8908
commit
ac9eff110d
@ -4,6 +4,8 @@ module.exports = {
|
||||
jest: true,
|
||||
es2021: true
|
||||
},
|
||||
parser: "@typescript-eslint/parser",
|
||||
plugins: ["@typescript-eslint"],
|
||||
extends: "eslint:recommended",
|
||||
parserOptions: {
|
||||
ecmaVersion: 13,
|
||||
|
||||
420
package-lock.json
generated
420
package-lock.json
generated
@ -16,6 +16,8 @@
|
||||
"@rollup/plugin-json": "^6.0.0",
|
||||
"@rollup/plugin-terser": "^0.4.1",
|
||||
"@types/jest": "^29.5.1",
|
||||
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
||||
"@typescript-eslint/parser": "^6.2.1",
|
||||
"clean-jsdoc-theme": "^4.2.7",
|
||||
"eslint": "^8.39.0",
|
||||
"jest": "^29.5.0",
|
||||
@ -2898,6 +2900,12 @@
|
||||
"parse5": "^7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/json-schema": {
|
||||
"version": "7.0.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.12.tgz",
|
||||
"integrity": "sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/linkify-it": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-3.0.2.tgz",
|
||||
@ -2932,6 +2940,12 @@
|
||||
"integrity": "sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/semver": {
|
||||
"version": "7.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.0.tgz",
|
||||
"integrity": "sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/stack-utils": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz",
|
||||
@ -2959,6 +2973,295 @@
|
||||
"integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.2.1.tgz",
|
||||
"integrity": "sha512-iZVM/ALid9kO0+I81pnp1xmYiFyqibAHzrqX4q5YvvVEyJqY+e6rfTXSCsc2jUxGNqJqTfFSSij/NFkZBiBzLw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/regexpp": "^4.5.1",
|
||||
"@typescript-eslint/scope-manager": "6.2.1",
|
||||
"@typescript-eslint/type-utils": "6.2.1",
|
||||
"@typescript-eslint/utils": "6.2.1",
|
||||
"@typescript-eslint/visitor-keys": "6.2.1",
|
||||
"debug": "^4.3.4",
|
||||
"graphemer": "^1.4.0",
|
||||
"ignore": "^5.2.4",
|
||||
"natural-compare": "^1.4.0",
|
||||
"natural-compare-lite": "^1.4.0",
|
||||
"semver": "^7.5.4",
|
||||
"ts-api-utils": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^16.0.0 || >=18.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@typescript-eslint/parser": "^6.0.0 || ^6.0.0-alpha",
|
||||
"eslint": "^7.0.0 || ^8.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin/node_modules/lru-cache": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
||||
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"yallist": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin/node_modules/semver": {
|
||||
"version": "7.5.4",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
|
||||
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"lru-cache": "^6.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin/node_modules/yallist": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.2.1.tgz",
|
||||
"integrity": "sha512-Ld+uL1kYFU8e6btqBFpsHkwQ35rw30IWpdQxgOqOh4NfxSDH6uCkah1ks8R/RgQqI5hHPXMaLy9fbFseIe+dIg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "6.2.1",
|
||||
"@typescript-eslint/types": "6.2.1",
|
||||
"@typescript-eslint/typescript-estree": "6.2.1",
|
||||
"@typescript-eslint/visitor-keys": "6.2.1",
|
||||
"debug": "^4.3.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^16.0.0 || >=18.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^7.0.0 || ^8.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/scope-manager": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.2.1.tgz",
|
||||
"integrity": "sha512-UCqBF9WFqv64xNsIEPfBtenbfodPXsJ3nPAr55mGPkQIkiQvgoWNo+astj9ZUfJfVKiYgAZDMnM6dIpsxUMp3Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "6.2.1",
|
||||
"@typescript-eslint/visitor-keys": "6.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^16.0.0 || >=18.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/type-utils": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.2.1.tgz",
|
||||
"integrity": "sha512-fTfCgomBMIgu2Dh2Or3gMYgoNAnQm3RLtRp+jP7A8fY+LJ2+9PNpi5p6QB5C4RSP+U3cjI0vDlI3mspAkpPVbQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/typescript-estree": "6.2.1",
|
||||
"@typescript-eslint/utils": "6.2.1",
|
||||
"debug": "^4.3.4",
|
||||
"ts-api-utils": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^16.0.0 || >=18.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^7.0.0 || ^8.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/types": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.2.1.tgz",
|
||||
"integrity": "sha512-528bGcoelrpw+sETlyM91k51Arl2ajbNT9L4JwoXE2dvRe1yd8Q64E4OL7vHYw31mlnVsf+BeeLyAZUEQtqahQ==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^16.0.0 || >=18.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/typescript-estree": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.2.1.tgz",
|
||||
"integrity": "sha512-G+UJeQx9AKBHRQBpmvr8T/3K5bJa485eu+4tQBxFq0KoT22+jJyzo1B50JDT9QdC1DEmWQfdKsa8ybiNWYsi0Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "6.2.1",
|
||||
"@typescript-eslint/visitor-keys": "6.2.1",
|
||||
"debug": "^4.3.4",
|
||||
"globby": "^11.1.0",
|
||||
"is-glob": "^4.0.3",
|
||||
"semver": "^7.5.4",
|
||||
"ts-api-utils": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^16.0.0 || >=18.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/typescript-estree/node_modules/lru-cache": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
||||
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"yallist": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/typescript-estree/node_modules/semver": {
|
||||
"version": "7.5.4",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
|
||||
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"lru-cache": "^6.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/typescript-estree/node_modules/yallist": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@typescript-eslint/utils": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.2.1.tgz",
|
||||
"integrity": "sha512-eBIXQeupYmxVB6S7x+B9SdBeB6qIdXKjgQBge2J+Ouv8h9Cxm5dHf/gfAZA6dkMaag+03HdbVInuXMmqFB/lKQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.4.0",
|
||||
"@types/json-schema": "^7.0.12",
|
||||
"@types/semver": "^7.5.0",
|
||||
"@typescript-eslint/scope-manager": "6.2.1",
|
||||
"@typescript-eslint/types": "6.2.1",
|
||||
"@typescript-eslint/typescript-estree": "6.2.1",
|
||||
"semver": "^7.5.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^16.0.0 || >=18.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^7.0.0 || ^8.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/utils/node_modules/lru-cache": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
||||
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"yallist": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/utils/node_modules/semver": {
|
||||
"version": "7.5.4",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
|
||||
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"lru-cache": "^6.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/utils/node_modules/yallist": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@typescript-eslint/visitor-keys": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.2.1.tgz",
|
||||
"integrity": "sha512-iTN6w3k2JEZ7cyVdZJTVJx2Lv7t6zFA8DCrJEHD2mwfc16AEvvBWVhbFh34XyG2NORCd0viIgQY1+u7kPI0WpA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "6.2.1",
|
||||
"eslint-visitor-keys": "^3.4.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^16.0.0 || >=18.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/abab": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz",
|
||||
@ -3141,6 +3444,15 @@
|
||||
"node": ">=12.17"
|
||||
}
|
||||
},
|
||||
"node_modules/array-union": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz",
|
||||
"integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/astral-regex": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz",
|
||||
@ -4337,6 +4649,18 @@
|
||||
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/dir-glob": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
|
||||
"integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"path-type": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/doctrine": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz",
|
||||
@ -4650,9 +4974,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint-visitor-keys": {
|
||||
"version": "3.4.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.0.tgz",
|
||||
"integrity": "sha512-HPpKPUBQcAsZOsHAFwTtIKcYlCje62XB7SEAcxjtmW6TD1WVpkS6i6/hOVtTZIl4zGj/mBqpFVGvaDneik+VoQ==",
|
||||
"version": "3.4.2",
|
||||
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.2.tgz",
|
||||
"integrity": "sha512-8drBzUEyZ2llkpCA67iYrgEssKDUu68V8ChqqOfFupIaG/LCVPUT+CoGJpT77zJprs4T/W7p07LP7zAIMuweVw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
@ -4916,6 +5240,34 @@
|
||||
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/fast-glob": {
|
||||
"version": "3.3.1",
|
||||
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz",
|
||||
"integrity": "sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@nodelib/fs.stat": "^2.0.2",
|
||||
"@nodelib/fs.walk": "^1.2.3",
|
||||
"glob-parent": "^5.1.2",
|
||||
"merge2": "^1.3.0",
|
||||
"micromatch": "^4.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fast-glob/node_modules/glob-parent": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
|
||||
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"is-glob": "^4.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/fast-json-stable-stringify": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
|
||||
@ -5200,6 +5552,26 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/globby": {
|
||||
"version": "11.1.0",
|
||||
"resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz",
|
||||
"integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"array-union": "^2.1.0",
|
||||
"dir-glob": "^3.0.1",
|
||||
"fast-glob": "^3.2.9",
|
||||
"ignore": "^5.2.0",
|
||||
"merge2": "^1.4.1",
|
||||
"slash": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.11",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
||||
@ -5212,6 +5584,12 @@
|
||||
"integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/graphemer": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz",
|
||||
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/has": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
|
||||
@ -8751,6 +9129,15 @@
|
||||
"integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/merge2": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz",
|
||||
"integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/methods": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
|
||||
@ -8926,6 +9313,12 @@
|
||||
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/natural-compare-lite": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz",
|
||||
"integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/negotiator": {
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
|
||||
@ -9311,6 +9704,15 @@
|
||||
"integrity": "sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/path-type": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz",
|
||||
"integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/picocolors": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
|
||||
@ -11435,6 +11837,18 @@
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/ts-api-utils": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.0.1.tgz",
|
||||
"integrity": "sha512-lC/RGlPmwdrIBFTX59wwNzqh7aR2otPNPR/5brHZm/XKFYKsfqxihXUe9pU3JI+3vGkl+vyCoNNnPhJn3aLK1A==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=16.13.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz",
|
||||
|
||||
11
package.json
11
package.json
@ -1,13 +1,12 @@
|
||||
{
|
||||
"name": "@openglobus/og",
|
||||
"version": "0.17.1",
|
||||
"description": "[OpenGlobus](https://www.openglobus.org/) is a javascript library designed to display interactive 3d maps and planets with map tiles, imagery and vector data, markers and 3d objects. It uses the WebGL technology, open source and completely free.",
|
||||
"description": "[openglobus](https://www.openglobus.org/) is a javascript library designed to display interactive 3d maps and planets with map tiles, imagery and vector data, markers and 3d objects. It uses the WebGL technology, open source and completely free.",
|
||||
"directories": {
|
||||
"example": "./sandbox"
|
||||
},
|
||||
"main": "./src/og/index.js",
|
||||
"main": "./src/og/index.ts",
|
||||
"style": "./css/og.css",
|
||||
"types": "./types/index.d.ts",
|
||||
"scripts": {
|
||||
"docs": "jsdoc -r ./src/ -c ./jsdoc.conf.json -d ./docs",
|
||||
"serve": "ws",
|
||||
@ -15,7 +14,6 @@
|
||||
"test": "jest --env=jsdom --runInBand --ci --coverage=false",
|
||||
"test_watch": "jest --env=jsdom --watch",
|
||||
"lint": "eslint -c ./.eslintrc.js src/og",
|
||||
"compile_js_as_ts": "tsc src/og/index.js --AllowJs --checkJs --outDir dist/@openglobus/src/",
|
||||
"font": "node ./fonts/index.js"
|
||||
},
|
||||
"repository": {
|
||||
@ -45,6 +43,8 @@
|
||||
"@rollup/plugin-json": "^6.0.0",
|
||||
"@rollup/plugin-terser": "^0.4.1",
|
||||
"@types/jest": "^29.5.1",
|
||||
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
||||
"@typescript-eslint/parser": "^6.2.1",
|
||||
"clean-jsdoc-theme": "^4.2.7",
|
||||
"eslint": "^8.39.0",
|
||||
"jest": "^29.5.0",
|
||||
@ -67,8 +67,7 @@
|
||||
"files": [
|
||||
"src/**/*",
|
||||
"dist/**/*",
|
||||
"css/**/*",
|
||||
"types/**/*"
|
||||
"css/**/*"
|
||||
],
|
||||
"keywords": [
|
||||
"map",
|
||||
|
||||
@ -1,352 +1,329 @@
|
||||
"use strict";
|
||||
|
||||
import { LonLat } from "./LonLat.js";
|
||||
import * as math from "./math.js";
|
||||
import * as mercator from "./mercator.js";
|
||||
|
||||
/**
|
||||
* Represents geographical coordinates extent.
|
||||
* @class
|
||||
* @param {LonLat} [sw] - South West extent corner coordinates.
|
||||
* @param {LonLat} [ne] - North East extent corner coordinates.
|
||||
*/
|
||||
export class Extent {
|
||||
/**
|
||||
* @param {LonLat} [sw] - South West extent corner coordinates.
|
||||
* @param {LonLat} [ne] - North East extent corner coordinates.
|
||||
*/
|
||||
constructor(sw = new LonLat(), ne = new LonLat()) {
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
this.southWest = sw;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
this.northEast = ne;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whole mercator extent.
|
||||
* @const
|
||||
*/
|
||||
static get FULL_MERC() {
|
||||
return new Extent(LonLat.SW_MERC, LonLat.NE_MERC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Degrees extent from north mercator limit to north pole.
|
||||
* @const
|
||||
*/
|
||||
static get NORTH_POLE_DEG() {
|
||||
return new Extent(LonLat.NW_MERC_DEG, new LonLat(180.0, 90.0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Degrees extent from south pole to south mercator limit.
|
||||
* @const
|
||||
*/
|
||||
static get SOUTH_POLE_DEG() {
|
||||
return new Extent(new LonLat(-180.0, -90.0), LonLat.SE_MERC_DEG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates extent instance from values in array.
|
||||
* @static
|
||||
* @param {Array.<number>} arr - South west and north east longitude and latidudes packed in array. (exactly 4 entries)
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createFromArray(arr) {
|
||||
return new Extent(new LonLat(arr[0], arr[1]), new LonLat(arr[2], arr[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates bound extent instance by coordinate array.
|
||||
* @static
|
||||
* @param {Array.<LonLat>} arr - Coordinate array.
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createByCoordinates(arr) {
|
||||
let lonmin = math.MAX,
|
||||
lonmax = math.MIN,
|
||||
latmin = math.MAX,
|
||||
latmax = math.MIN;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const vi = arr[i];
|
||||
if (vi.lon < lonmin) lonmin = vi.lon;
|
||||
if (vi.lon > lonmax) lonmax = vi.lon;
|
||||
if (vi.lat < latmin) latmin = vi.lat;
|
||||
if (vi.lat > latmax) latmax = vi.lat;
|
||||
}
|
||||
return new Extent(new LonLat(lonmin, latmin), new LonLat(lonmax, latmax));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates bound extent instance by coordinates array.
|
||||
* @static
|
||||
* @param {Array.<Array<number>>} arr - Coordinate array. (exactly 2 entries)
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createByCoordinatesArr(arr) {
|
||||
let lonmin = math.MAX,
|
||||
lonmax = math.MIN,
|
||||
latmin = math.MAX,
|
||||
latmax = math.MIN;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const vi = arr[i];
|
||||
if (vi[0] < lonmin) lonmin = vi[0];
|
||||
if (vi[0] > lonmax) lonmax = vi[0];
|
||||
if (vi[1] < latmin) latmin = vi[1];
|
||||
if (vi[1] > latmax) latmax = vi[1];
|
||||
}
|
||||
return new Extent(new LonLat(lonmin, latmin), new LonLat(lonmax, latmax));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates extent by meractor grid tile coordinates.
|
||||
* @static
|
||||
* @param {number} x -
|
||||
* @param {number} y -
|
||||
* @param {number} z -
|
||||
* @param {number} width -
|
||||
* @param {number} height -
|
||||
* @returns {Extent} -
|
||||
*/
|
||||
static fromTile(x, y, z, width, height) {
|
||||
width = width || mercator.POLE_DOUBLE;
|
||||
height = height || mercator.POLE_DOUBLE;
|
||||
const H = Math.pow(2, z),
|
||||
W = Math.pow(2, z),
|
||||
lnSize = width / W,
|
||||
ltSize = height / H;
|
||||
|
||||
const left = -width * 0.5 + x * lnSize,
|
||||
top = height * 0.5 - y * ltSize,
|
||||
bottom = top - ltSize,
|
||||
right = left + lnSize;
|
||||
|
||||
return new Extent(new LonLat(left, bottom), new LonLat(right, top));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current bounding extent object by coordinate array.
|
||||
* @public
|
||||
* @param {Array.<LonLat>} arr - Coordinate array.
|
||||
* @return {Extent} Current extent.
|
||||
*/
|
||||
setByCoordinates(arr) {
|
||||
let lonmin = math.MAX,
|
||||
lonmax = math.MIN,
|
||||
latmin = math.MAX,
|
||||
latmax = math.MIN;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const vi = arr[i];
|
||||
if (vi.lon < lonmin) lonmin = vi.lon;
|
||||
if (vi.lon > lonmax) lonmax = vi.lon;
|
||||
if (vi.lat < latmin) latmin = vi.lat;
|
||||
if (vi.lat > latmax) latmax = vi.lat;
|
||||
}
|
||||
this.southWest.lon = lonmin;
|
||||
this.southWest.lat = latmin;
|
||||
this.northEast.lon = lonmax;
|
||||
this.northEast.lat = latmax;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if point inside extent.
|
||||
* @public
|
||||
* @param {LonLat} lonlat - Coordinate point.
|
||||
* @return {boolean} Returns true if point inside extent.
|
||||
*/
|
||||
isInside(lonlat) {
|
||||
const sw = this.southWest,
|
||||
ne = this.northEast;
|
||||
return (
|
||||
lonlat.lon >= sw.lon &&
|
||||
lonlat.lon <= ne.lon &&
|
||||
lonlat.lat >= sw.lat &&
|
||||
lonlat.lat <= ne.lat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if two extent overlap each other.
|
||||
* @public
|
||||
* @param {Extent} e - Another extent.
|
||||
* @return {boolean} -
|
||||
*/
|
||||
overlaps(e) {
|
||||
const sw = this.southWest,
|
||||
ne = this.northEast;
|
||||
return (
|
||||
sw.lon <= e.northEast.lon &&
|
||||
ne.lon >= e.southWest.lon &&
|
||||
sw.lat <= e.northEast.lat &&
|
||||
ne.lat >= e.southWest.lat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extent width.
|
||||
* @public
|
||||
* @return {number} Extent width.
|
||||
*/
|
||||
getWidth() {
|
||||
return this.northEast.lon - this.southWest.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extent height.
|
||||
* @public
|
||||
* @return {number} Extent height.
|
||||
*/
|
||||
getHeight() {
|
||||
return this.northEast.lat - this.southWest.lat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates clone instance of the current extent.
|
||||
* @public
|
||||
* @return {Extent} Extent clone.
|
||||
*/
|
||||
clone() {
|
||||
return new Extent(this.southWest.clone(), this.northEast.clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the center coordinate of the extent.
|
||||
* @public
|
||||
* @return {number} Center coordinate.
|
||||
*/
|
||||
getCenter() {
|
||||
const sw = this.southWest,
|
||||
ne = this.northEast;
|
||||
return new LonLat(sw.lon + (ne.lon - sw.lon) * 0.5, sw.lat + (ne.lat - sw.lat) * 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getNorthWest() {
|
||||
return new LonLat(this.southWest.lon, this.northEast.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getNorthEast() {
|
||||
return new LonLat(this.northEast.lon, this.northEast.lat);
|
||||
}
|
||||
|
||||
getSouthWest() {
|
||||
return new LonLat(this.southWest.lon, this.southWest.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getSouthEast() {
|
||||
return new LonLat(this.northEast.lon, this.southWest.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getNorth() {
|
||||
return this.northEast.lat;
|
||||
}
|
||||
|
||||
getEast() {
|
||||
return this.northEast.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getWest() {
|
||||
return this.southWest.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getSouth() {
|
||||
return this.southWest.lat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns extents are equals.
|
||||
* @param {Extent} extent - Extent.
|
||||
* @returns {boolean} -
|
||||
*/
|
||||
equals(extent) {
|
||||
return (
|
||||
this.southWest.lon === extent.southWest.lon &&
|
||||
this.southWest.lat === extent.southWest.lat &&
|
||||
this.northEast.lon === extent.northEast.lon &&
|
||||
this.northEast.lat === extent.northEast.lat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts extent coordinates to mercator projection coordinates.
|
||||
* @public
|
||||
* @return {Extent} New instance of the current extent.
|
||||
*/
|
||||
forwardMercator() {
|
||||
return new Extent(this.southWest.forwardMercator(), this.northEast.forwardMercator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts extent coordinates from mercator projection to degrees.
|
||||
* @public
|
||||
* @return {Extent} New instance of the current extent.
|
||||
*/
|
||||
inverseMercator() {
|
||||
return new Extent(this.southWest.inverseMercator(), this.northEast.inverseMercator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets cartesian bounding bounds of the current ellipsoid.
|
||||
* @public
|
||||
* @param {Ellipsoid} ellipsoid - Ellipsoid.
|
||||
* @return {Array.<number>} Cartesian 3d coordinate array. (exactly 6 entries)
|
||||
*/
|
||||
getCartesianBounds(ellipsoid) {
|
||||
let xmin = math.MAX,
|
||||
xmax = math.MIN,
|
||||
ymin = math.MAX,
|
||||
ymax = math.MIN,
|
||||
zmin = math.MAX,
|
||||
zmax = math.MIN;
|
||||
|
||||
const v = [
|
||||
new LonLat(this.southWest.lon, this.southWest.lat),
|
||||
new LonLat(this.southWest.lon, this.northEast.lat),
|
||||
new LonLat(this.northEast.lon, this.northEast.lat),
|
||||
new LonLat(this.northEast.lon, this.southWest.lat)
|
||||
];
|
||||
|
||||
for (let i = 0; i < v.length; i++) {
|
||||
const coord = ellipsoid.lonLatToCartesian(v[i]);
|
||||
const x = coord.x,
|
||||
y = coord.y,
|
||||
z = coord.z;
|
||||
if (x < xmin) xmin = x;
|
||||
if (x > xmax) xmax = x;
|
||||
if (y < ymin) ymin = y;
|
||||
if (y > ymax) ymax = y;
|
||||
if (z < zmin) zmin = z;
|
||||
if (z > zmax) zmax = z;
|
||||
}
|
||||
|
||||
return [xmin, ymin, zmin, xmax, ymax, zmax];
|
||||
}
|
||||
|
||||
toString() {
|
||||
return (
|
||||
`[${this.southWest.lon.toFixed(5)}, ${this.southWest.lat.toFixed(5)}, ${this.northEast.lon.toFixed(5)}, ${this.northEast.lat.toFixed(5)}]`
|
||||
);
|
||||
}
|
||||
}
|
||||
"use strict";
|
||||
|
||||
import * as mercator from "./mercator";
|
||||
import {Ellipsoid} from "./ellipsoid/Ellipsoid";
|
||||
import {LonLat} from "./LonLat";
|
||||
|
||||
//@ts-ignore
|
||||
import * as math from "./math.js";
|
||||
|
||||
|
||||
/**
|
||||
* Represents geographical coordinates extent.
|
||||
* @class
|
||||
* @param {LonLat} [sw] - South West extent corner coordinates.
|
||||
* @param {LonLat} [ne] - North East extent corner coordinates.
|
||||
*/
|
||||
export class Extent {
|
||||
public southWest: LonLat;
|
||||
public northEast: LonLat;
|
||||
|
||||
constructor(sw: LonLat = new LonLat(), ne: LonLat = new LonLat()) {
|
||||
this.southWest = sw;
|
||||
this.northEast = ne;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates extent instance from values in array.
|
||||
* @static
|
||||
* @param {Array.<number>} arr - South west and north east longitude and latidudes packed in array. (exactly 4 entries)
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createFromArray(arr: [number, number, number, number]): Extent {
|
||||
return new Extent(new LonLat(arr[0], arr[1]), new LonLat(arr[2], arr[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates bound extent instance by coordinate array.
|
||||
* @static
|
||||
* @param {Array.<LonLat>} arr - Coordinate array.
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createByCoordinates(arr: LonLat[]): Extent {
|
||||
let lonmin = math.MAX,
|
||||
lonmax = math.MIN,
|
||||
latmin = math.MAX,
|
||||
latmax = math.MIN;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const vi = arr[i];
|
||||
if (vi.lon < lonmin) lonmin = vi.lon;
|
||||
if (vi.lon > lonmax) lonmax = vi.lon;
|
||||
if (vi.lat < latmin) latmin = vi.lat;
|
||||
if (vi.lat > latmax) latmax = vi.lat;
|
||||
}
|
||||
return new Extent(new LonLat(lonmin, latmin), new LonLat(lonmax, latmax));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates bound extent instance by coordinates array.
|
||||
* @static
|
||||
* @param {Array.<Array<number>>} arr - Coordinate array. (exactly 2 entries)
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createByCoordinatesArr(arr: [number, number][]): Extent {
|
||||
let lonmin = math.MAX,
|
||||
lonmax = math.MIN,
|
||||
latmin = math.MAX,
|
||||
latmax = math.MIN;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const vi = arr[i];
|
||||
if (vi[0] < lonmin) lonmin = vi[0];
|
||||
if (vi[0] > lonmax) lonmax = vi[0];
|
||||
if (vi[1] < latmin) latmin = vi[1];
|
||||
if (vi[1] > latmax) latmax = vi[1];
|
||||
}
|
||||
return new Extent(new LonLat(lonmin, latmin), new LonLat(lonmax, latmax));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates extent by meractor grid tile coordinates.
|
||||
* @static
|
||||
* @param {number} x -
|
||||
* @param {number} y -
|
||||
* @param {number} z -
|
||||
* @param {number} width -
|
||||
* @param {number} height -
|
||||
* @returns {Extent} -
|
||||
*/
|
||||
static fromTile(
|
||||
x: number,
|
||||
y: number,
|
||||
z: number,
|
||||
width: number = mercator.POLE_DOUBLE,
|
||||
height: number = mercator.POLE_DOUBLE): Extent {
|
||||
const H = Math.pow(2, z);
|
||||
const W = Math.pow(2, z);
|
||||
const lnSize = width / W;
|
||||
const ltSize = height / H;
|
||||
|
||||
const left = -width * 0.5 + x * lnSize,
|
||||
top = height * 0.5 - y * ltSize,
|
||||
bottom = top - ltSize,
|
||||
right = left + lnSize;
|
||||
|
||||
return new Extent(new LonLat(left, bottom), new LonLat(right, top));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current bounding extent object by coordinate array.
|
||||
* @public
|
||||
* @param {Array.<LonLat>} arr - Coordinate array.
|
||||
* @return {Extent} Current extent.
|
||||
*/
|
||||
public setByCoordinates(arr: LonLat[]): Extent {
|
||||
let lonmin = math.MAX,
|
||||
lonmax = math.MIN,
|
||||
latmin = math.MAX,
|
||||
latmax = math.MIN;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const vi = arr[i];
|
||||
if (vi.lon < lonmin) lonmin = vi.lon;
|
||||
if (vi.lon > lonmax) lonmax = vi.lon;
|
||||
if (vi.lat < latmin) latmin = vi.lat;
|
||||
if (vi.lat > latmax) latmax = vi.lat;
|
||||
}
|
||||
this.southWest.lon = lonmin;
|
||||
this.southWest.lat = latmin;
|
||||
this.northEast.lon = lonmax;
|
||||
this.northEast.lat = latmax;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if point inside extent.
|
||||
* @public
|
||||
* @param {LonLat} lonlat - Coordinate point.
|
||||
* @return {boolean} Returns true if point inside extent.
|
||||
*/
|
||||
public isInside(lonlat: LonLat): boolean {
|
||||
const sw = this.southWest;
|
||||
const ne = this.northEast;
|
||||
return (
|
||||
lonlat.lon >= sw.lon && lonlat.lon <= ne.lon &&
|
||||
lonlat.lat >= sw.lat && lonlat.lat <= ne.lat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if two extent overlap each other.
|
||||
* @public
|
||||
* @param {Extent} e - Another extent.
|
||||
* @return {boolean} -
|
||||
*/
|
||||
public overlaps(e: Extent): boolean {
|
||||
const sw = this.southWest;
|
||||
const ne = this.northEast;
|
||||
return (
|
||||
sw.lon <= e.northEast.lon &&
|
||||
ne.lon >= e.southWest.lon &&
|
||||
sw.lat <= e.northEast.lat &&
|
||||
ne.lat >= e.southWest.lat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extent width.
|
||||
* @public
|
||||
* @return {number} Extent width.
|
||||
*/
|
||||
public getWidth(): number {
|
||||
return this.northEast.lon - this.southWest.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extent height.
|
||||
* @public
|
||||
* @return {number} Extent height.
|
||||
*/
|
||||
public getHeight(): number {
|
||||
return this.northEast.lat - this.southWest.lat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates clone instance of the current extent.
|
||||
* @public
|
||||
* @return {Extent} Extent clone.
|
||||
*/
|
||||
public clone(): Extent {
|
||||
return new Extent(this.southWest.clone(), this.northEast.clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the center coordinate of the extent.
|
||||
* @public
|
||||
* @return {number} Center coordinate.
|
||||
*/
|
||||
public getCenter(): LonLat {
|
||||
const sw = this.southWest;
|
||||
const ne = this.northEast;
|
||||
return new LonLat(sw.lon + (ne.lon - sw.lon) * 0.5, sw.lat + (ne.lat - sw.lat) * 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
public getNorthWest(): LonLat {
|
||||
return new LonLat(this.southWest.lon, this.northEast.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
public getNorthEast(): LonLat {
|
||||
return new LonLat(this.northEast.lon, this.northEast.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
public getSouthWest(): LonLat {
|
||||
return new LonLat(this.southWest.lon, this.southWest.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
public getSouthEast(): LonLat {
|
||||
return new LonLat(this.northEast.lon, this.southWest.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
public getNorth(): number {
|
||||
return this.northEast.lat;
|
||||
}
|
||||
|
||||
public getEast(): number {
|
||||
return this.northEast.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
public getWest(): number {
|
||||
return this.southWest.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
public getSouth(): number {
|
||||
return this.southWest.lat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns extents are equals.
|
||||
* @param {Extent} extent - Extent.
|
||||
* @returns {boolean} -
|
||||
*/
|
||||
public equals(extent: Extent): boolean {
|
||||
return (
|
||||
this.southWest.lon === extent.southWest.lon &&
|
||||
this.southWest.lat === extent.southWest.lat &&
|
||||
this.northEast.lon === extent.northEast.lon &&
|
||||
this.northEast.lat === extent.northEast.lat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts extent coordinates to mercator projection coordinates.
|
||||
* @public
|
||||
* @return {Extent} New instance of the current extent.
|
||||
*/
|
||||
public forwardMercator(): Extent {
|
||||
return new Extent(this.southWest.forwardMercator(), this.northEast.forwardMercator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts extent coordinates from mercator projection to degrees.
|
||||
* @public
|
||||
* @return {Extent} New instance of the current extent.
|
||||
*/
|
||||
public inverseMercator(): Extent {
|
||||
return new Extent(this.southWest.inverseMercator(), this.northEast.inverseMercator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets cartesian bounding bounds of the current ellipsoid.
|
||||
* @public
|
||||
* @param {Ellipsoid} ellipsoid - Ellipsoid.
|
||||
* @return {Array.<number>} Cartesian 3d coordinate array. (exactly 6 entries)
|
||||
*/
|
||||
public getCartesianBounds(ellipsoid: Ellipsoid): [number, number, number, number, number, number] {
|
||||
let xmin = math.MAX,
|
||||
xmax = math.MIN,
|
||||
ymin = math.MAX,
|
||||
ymax = math.MIN,
|
||||
zmin = math.MAX,
|
||||
zmax = math.MIN;
|
||||
|
||||
const v = [
|
||||
new LonLat(this.southWest.lon, this.southWest.lat),
|
||||
new LonLat(this.southWest.lon, this.northEast.lat),
|
||||
new LonLat(this.northEast.lon, this.northEast.lat),
|
||||
new LonLat(this.northEast.lon, this.southWest.lat)
|
||||
];
|
||||
|
||||
for (let i = 0; i < v.length; i++) {
|
||||
const coord = ellipsoid.lonLatToCartesian(v[i]);
|
||||
const x = coord.x;
|
||||
const y = coord.y;
|
||||
const z = coord.z;
|
||||
if (x < xmin) xmin = x;
|
||||
if (x > xmax) xmax = x;
|
||||
if (y < ymin) ymin = y;
|
||||
if (y > ymax) ymax = y;
|
||||
if (z < zmin) zmin = z;
|
||||
if (z > zmax) zmax = z;
|
||||
}
|
||||
|
||||
return [xmin, ymin, zmin, xmax, ymax, zmax];
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return (
|
||||
`[${this.southWest.lon.toFixed(5)}, ${this.southWest.lat.toFixed(5)}, ${this.northEast.lon.toFixed(5)}, ${this.northEast.lat.toFixed(5)}]`
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,21 @@
|
||||
"use strict";
|
||||
|
||||
import { LonLat } from "../LonLat.js";
|
||||
import { DEGREES, EPS1, EPS12, EPS15, RADIANS, zeroTwoPI } from "../math.js";
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
import { Quat } from "../math/Quat.js";
|
||||
import {LonLat} from "../LonLat";
|
||||
import {Quat} from "../math/Quat";
|
||||
import {Vec3} from "../math/Vec3";
|
||||
//@ts-ignore
|
||||
import {DEGREES, EPS1, EPS12, EPS15, RADIANS, zeroTwoPI} from "../math.js";
|
||||
|
||||
export interface IInverseResult {
|
||||
distance: number;
|
||||
initialAzimuth: number;
|
||||
finalAzimuth: number;
|
||||
}
|
||||
|
||||
export interface IDirectResult {
|
||||
destination: LonLat;
|
||||
finalAzimuth: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class represents a plant ellipsoid.
|
||||
@ -12,11 +24,24 @@ import { Quat } from "../math/Quat.js";
|
||||
* @param {number} polarSize - Polar ellipsoid size.
|
||||
*/
|
||||
class Ellipsoid {
|
||||
/**
|
||||
* @param {number} equatorialSize - Equatorial ellipsoid size.
|
||||
* @param {number} polarSize - Polar ellipsoid size.
|
||||
*/
|
||||
constructor(equatorialSize, polarSize) {
|
||||
|
||||
protected _a: number;
|
||||
protected _b: number;
|
||||
protected _flattening: number;
|
||||
protected _f: number;
|
||||
protected _a2: number;
|
||||
protected _b2: number;
|
||||
protected _e: number;
|
||||
protected _e2: number;
|
||||
protected _e22: number;
|
||||
protected _k: number;
|
||||
protected _k2: number;
|
||||
protected _radii: Vec3;
|
||||
protected _radii2: Vec3;
|
||||
protected _invRadii: Vec3;
|
||||
protected _invRadii2: Vec3;
|
||||
|
||||
constructor(equatorialSize: number = 1, polarSize: number = 1) {
|
||||
this._a = equatorialSize;
|
||||
this._b = polarSize;
|
||||
this._flattening = (equatorialSize - polarSize) / equatorialSize;
|
||||
@ -25,7 +50,7 @@ class Ellipsoid {
|
||||
this._a2 = equatorialSize * equatorialSize;
|
||||
this._b2 = polarSize * polarSize;
|
||||
|
||||
var qa2b2 = Math.sqrt(this._a2 - this._b2);
|
||||
const qa2b2 = Math.sqrt(this._a2 - this._b2);
|
||||
|
||||
this._e = qa2b2 / equatorialSize;
|
||||
this._e2 = this._e * this._e;
|
||||
@ -42,11 +67,11 @@ class Ellipsoid {
|
||||
|
||||
/**
|
||||
* Returns the distance travelling from ‘this’ point to destination point along a rhumb line.
|
||||
* @param {LonLat} start coordinates.
|
||||
* @param {LonLat} end coordinates
|
||||
* @param {LonLat} startLonLat coordinates.
|
||||
* @param {LonLat} endLonLat coordinates
|
||||
* @returns {number} Distance in m between this point and destination point (same units as radius).
|
||||
*/
|
||||
rhumbDistanceTo(startLonLat, endLonLat) {
|
||||
public rhumbDistanceTo(startLonLat: LonLat, endLonLat: LonLat): number {
|
||||
const f1 = startLonLat.lat * RADIANS;
|
||||
const f2 = endLonLat.lat * RADIANS;
|
||||
const df = f2 - f1;
|
||||
@ -65,11 +90,9 @@ class Ellipsoid {
|
||||
* @param {number} fraction - Fraction between the two points (0 = source point, 1 = destination point).
|
||||
* @returns {LonLat} Intermediate point between points.
|
||||
*/
|
||||
getIntermediatePointOnGreatCircle(lonLat1, lonLat2, fraction) {
|
||||
|
||||
public getIntermediatePointOnGreatCircle(lonLat1: LonLat, lonLat2: LonLat, fraction: number): LonLat {
|
||||
if (fraction == 0) return lonLat1.clone();
|
||||
if (fraction == 1) return lonLat2.clone();
|
||||
|
||||
const inverse = this.inverse(lonLat1, lonLat2);
|
||||
const dist = inverse.distance;
|
||||
const azimuth = inverse.initialAzimuth;
|
||||
@ -82,17 +105,17 @@ class Ellipsoid {
|
||||
* @param lonLat2
|
||||
* @returns {number}
|
||||
*/
|
||||
static getBearing(lonLat1, lonLat2) {
|
||||
var f1 = lonLat1.lat * RADIANS,
|
||||
static getBearing(lonLat1: LonLat, lonLat2: LonLat): number {
|
||||
let f1 = lonLat1.lat * RADIANS,
|
||||
l1 = lonLat1.lon * RADIANS;
|
||||
var f2 = lonLat2.lat * RADIANS,
|
||||
let f2 = lonLat2.lat * RADIANS,
|
||||
l2 = lonLat2.lon * RADIANS;
|
||||
var y = Math.sin(l2 - l1) * Math.cos(f2);
|
||||
var x = Math.cos(f1) * Math.sin(f2) - Math.sin(f1) * Math.cos(f2) * Math.cos(l2 - l1);
|
||||
let y = Math.sin(l2 - l1) * Math.cos(f2);
|
||||
let x = Math.cos(f1) * Math.sin(f2) - Math.sin(f1) * Math.cos(f2) * Math.cos(l2 - l1);
|
||||
return Math.atan2(y, x) * DEGREES;
|
||||
}
|
||||
|
||||
getFlattening() {
|
||||
public getFlattening(): number {
|
||||
return this._flattening;
|
||||
}
|
||||
|
||||
@ -101,7 +124,7 @@ class Ellipsoid {
|
||||
* @public
|
||||
* @returns {number} -
|
||||
*/
|
||||
getEquatorialSize() {
|
||||
public getEquatorialSize(): number {
|
||||
return this._a;
|
||||
}
|
||||
|
||||
@ -110,7 +133,7 @@ class Ellipsoid {
|
||||
* @public
|
||||
* @returns {number} -
|
||||
*/
|
||||
getPolarSize() {
|
||||
public getPolarSize(): number {
|
||||
return this._b;
|
||||
}
|
||||
|
||||
@ -120,7 +143,7 @@ class Ellipsoid {
|
||||
* @param {LonLat} lonlat - Geodetic coordinates.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
lonLatToCartesian(lonlat) {
|
||||
public lonLatToCartesian(lonlat: LonLat): Vec3 {
|
||||
return this.geodeticToCartesian(lonlat.lon, lonlat.lat, lonlat.height);
|
||||
}
|
||||
|
||||
@ -131,7 +154,7 @@ class Ellipsoid {
|
||||
* @param {Vec3} res - Output variable reference.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
lonLatToCartesianRes(lonlat, res) {
|
||||
public lonLatToCartesianRes(lonlat: LonLat, res: Vec3): Vec3 {
|
||||
return this.geodeticToCartesian(lonlat.lon, lonlat.lat, lonlat.height, res);
|
||||
}
|
||||
|
||||
@ -141,11 +164,10 @@ class Ellipsoid {
|
||||
* @param {Number} lon - Longitude.
|
||||
* @param {Number} lat - Latitude.
|
||||
* @param {Number} height - Height.
|
||||
* @param {Vec3} res - Output result variable.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
geodeticToCartesian(lon, lat, height = 0, res) {
|
||||
res = res || new Vec3();
|
||||
|
||||
public geodeticToCartesian(lon: number, lat: number, height: number = 0, res: Vec3 = new Vec3()): Vec3 {
|
||||
let latrad = RADIANS * lat,
|
||||
lonrad = RADIANS * lon;
|
||||
|
||||
@ -167,7 +189,7 @@ class Ellipsoid {
|
||||
* @param {Vec3} p - Cartesian coordinates.
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
projToSurface(p) {
|
||||
public projToSurface(p: Vec3): Vec3 {
|
||||
|
||||
let pX = p.x || 0.0,
|
||||
pY = p.y || 0.0,
|
||||
@ -226,7 +248,7 @@ class Ellipsoid {
|
||||
* @param {Vec3} cart - Cartesian coordinates
|
||||
* @returns {LonLat} - Geodetic coordinates
|
||||
*/
|
||||
cartesianToLonLat(cart) {
|
||||
public cartesianToLonLat(cart: Vec3): LonLat {
|
||||
return this.cartesianToLonLatRes(cart);
|
||||
}
|
||||
|
||||
@ -236,8 +258,7 @@ class Ellipsoid {
|
||||
* @param {LonLat} res - Link geodetic coordinates variable
|
||||
* @returns {LonLat} - Geodetic coordinates
|
||||
*/
|
||||
cartesianToLonLatRes(cart, res) {
|
||||
res = res || new LonLat();
|
||||
public cartesianToLonLatRes(cart: Vec3, res: LonLat = new LonLat()): LonLat {
|
||||
let p = this.projToSurface(cart);
|
||||
let n = this.getSurfaceNormal3v(p),
|
||||
h = cart.sub(p);
|
||||
@ -255,7 +276,7 @@ class Ellipsoid {
|
||||
* @param {Vec3} coord - Spatial coordinates.
|
||||
* @return {Vec3} -
|
||||
*/
|
||||
getSurfaceNormal3v(coord) {
|
||||
public getSurfaceNormal3v(coord: Vec3): Vec3 {
|
||||
let r2 = this._invRadii2;
|
||||
let nx = coord.x * r2.x,
|
||||
ny = coord.y * r2.y,
|
||||
@ -264,7 +285,7 @@ class Ellipsoid {
|
||||
return new Vec3(nx * l, ny * l, nz * l);
|
||||
}
|
||||
|
||||
getGreatCircleDistance(lonLat1, lonLat2) {
|
||||
public getGreatCircleDistance(lonLat1: LonLat, lonLat2: LonLat): number {
|
||||
return this.inverse(lonLat1, lonLat2).distance;
|
||||
}
|
||||
|
||||
@ -277,11 +298,11 @@ class Ellipsoid {
|
||||
* @param {number} dist - Distance to the destination point coordinates in meters
|
||||
* @returns {LonLat} - Destination point coordinates
|
||||
*/
|
||||
getGreatCircleDestination(lonLat, azimuth, dist) {
|
||||
public getGreatCircleDestination(lonLat: LonLat, azimuth: number, dist: number): LonLat {
|
||||
return this.direct(lonLat, azimuth, dist).destination;
|
||||
}
|
||||
|
||||
inverse(lonLat1, lonLat2) {
|
||||
public inverse(lonLat1: LonLat, lonLat2: LonLat): IInverseResult {
|
||||
|
||||
let a = this._a, b = this._b, f = this._flattening;
|
||||
|
||||
@ -346,9 +367,11 @@ class Ellipsoid {
|
||||
* @param {number} dist - Distance to the destination point coordinates in meters
|
||||
* @returns {LonLat} - Destination point coordinates
|
||||
*/
|
||||
direct(lonLat, azimuth, dist) {
|
||||
public direct(lonLat: LonLat, azimuth: number, dist: number): IDirectResult {
|
||||
|
||||
let lon1 = lonLat.lon,
|
||||
lat1 = lonLat.lat;
|
||||
|
||||
let a = this._a,
|
||||
b = this._b,
|
||||
f = this._flattening,
|
||||
@ -367,19 +390,26 @@ class Ellipsoid {
|
||||
B = (uSq / 1024) * (256 + uSq * (-128 + uSq * (74 - 47 * uSq))),
|
||||
sigma = s / (b * A),
|
||||
sigmaP = 2 * Math.PI;
|
||||
|
||||
let cos2SigmaM = 0,
|
||||
sinSigma = 0,
|
||||
cosSigma = 0,
|
||||
deltaSigma = 0;
|
||||
|
||||
while (Math.abs(sigma - sigmaP) > 1e-12) {
|
||||
var cos2SigmaM = Math.cos(2 * sigma1 + sigma),
|
||||
sinSigma = Math.sin(sigma),
|
||||
cosSigma = Math.cos(sigma),
|
||||
deltaSigma = B * sinSigma *
|
||||
(cos2SigmaM + (B / 4) *
|
||||
(
|
||||
cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) -
|
||||
(B / 6) * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)
|
||||
));
|
||||
cos2SigmaM = Math.cos(2 * sigma1 + sigma);
|
||||
sinSigma = Math.sin(sigma);
|
||||
cosSigma = Math.cos(sigma);
|
||||
deltaSigma = B * sinSigma *
|
||||
(cos2SigmaM + (B / 4) *
|
||||
(
|
||||
cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) -
|
||||
(B / 6) * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)
|
||||
));
|
||||
sigmaP = sigma;
|
||||
sigma = s / (b * A) + deltaSigma;
|
||||
}
|
||||
|
||||
let tmp = sinU1 * sinSigma - cosU1 * cosSigma * cosAlpha1,
|
||||
lat2 = Math.atan2(
|
||||
sinU1 * cosSigma + cosU1 * sinSigma * cosAlpha1,
|
||||
@ -408,20 +438,20 @@ class Ellipsoid {
|
||||
* @param {Vec3} direction - Ray direction.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
hitRay(origin, direction) {
|
||||
var q = this._invRadii.mul(origin);
|
||||
var w = this._invRadii.mul(direction);
|
||||
public hitRay(origin: Vec3, direction: Vec3): Vec3 | undefined {
|
||||
let q = this._invRadii.mul(origin);
|
||||
let w = this._invRadii.mul(direction);
|
||||
|
||||
var q2 = q.dot(q);
|
||||
var qw = q.dot(w);
|
||||
let q2 = q.dot(q);
|
||||
let qw = q.dot(w);
|
||||
|
||||
var difference, w2, product, discriminant, temp;
|
||||
let difference, w2, product, discriminant, temp;
|
||||
|
||||
if (q2 > 1.0) {
|
||||
// Outside ellipsoid.
|
||||
if (qw >= 0.0) {
|
||||
// Looking outward or tangent (0 intersections).
|
||||
return null;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// qw < 0.0.
|
||||
@ -434,7 +464,7 @@ class Ellipsoid {
|
||||
|
||||
if (eps > EPS15 && qw2 < product) {
|
||||
// Imaginary roots (0 intersections).
|
||||
return null;
|
||||
return undefined;
|
||||
} else if (qw2 > product) {
|
||||
// Distinct roots (2 intersections).
|
||||
discriminant = qw * qw - product;
|
||||
@ -470,7 +500,7 @@ class Ellipsoid {
|
||||
}
|
||||
}
|
||||
|
||||
getNorthFrameRotation(cartesian) {
|
||||
public getNorthFrameRotation(cartesian: Vec3): Quat {
|
||||
let n = this.getSurfaceNormal3v(cartesian);
|
||||
let t = Vec3.proj_b_to_plane(Vec3.NORTH, n);
|
||||
return Quat.getLookRotation(t, n);
|
||||
@ -483,7 +513,7 @@ class Ellipsoid {
|
||||
* @param distance
|
||||
* @returns {LonLat}
|
||||
*/
|
||||
getBearingDestination(lonLat1, bearing = 0.0, distance = 0) {
|
||||
public getBearingDestination(lonLat1: LonLat, bearing: number = 0.0, distance: number = 0): LonLat {
|
||||
bearing = bearing * RADIANS;
|
||||
var nlon = ((lonLat1.lon + 540) % 360) - 180;
|
||||
var f1 = lonLat1.lat * RADIANS,
|
||||
@ -510,7 +540,7 @@ class Ellipsoid {
|
||||
* @param {number} fraction - Fraction between the two points (0 = source point, 1 = destination point).
|
||||
* @returns {LonLat} Intermediate point between points.
|
||||
*/
|
||||
static getIntermediatePointOnGreatCircle(lonLat1, lonLat2, fraction) {
|
||||
static getIntermediatePointOnGreatCircle(lonLat1: LonLat, lonLat2: LonLat, fraction: number): LonLat {
|
||||
var f1 = lonLat1.lat * RADIANS,
|
||||
l1 = lonLat1.lon * RADIANS;
|
||||
var f2 = lonLat2.lat * RADIANS,
|
||||
@ -545,7 +575,7 @@ class Ellipsoid {
|
||||
return new LonLat(((l3 * DEGREES + 540) % 360) - 180, f3 * DEGREES);
|
||||
}
|
||||
|
||||
static getRhumbBearing(lonLat1, lonLat2) {
|
||||
static getRhumbBearing(lonLat1: LonLat, lonLat2: LonLat): number {
|
||||
var dLon = (lonLat2.lon - lonLat1.lon) * RADIANS;
|
||||
var dPhi = Math.log(
|
||||
Math.tan((lonLat2.lat * RADIANS) / 2 + Math.PI / 4) /
|
||||
@ -562,4 +592,4 @@ class Ellipsoid {
|
||||
}
|
||||
}
|
||||
|
||||
export { Ellipsoid };
|
||||
export {Ellipsoid};
|
||||
@ -1,20 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
import { Mat4 } from "./Mat4.js";
|
||||
import { Vec3 } from "./Vec3.js";
|
||||
import {Mat4} from "./Mat4";
|
||||
import {Vec3} from "./Vec3";
|
||||
|
||||
/**
|
||||
* Class represents a 3x3 matrix.
|
||||
* @class
|
||||
*/
|
||||
export class Mat3 {
|
||||
|
||||
/**
|
||||
* A 3x3 matrix, indexing as a column-major order array.
|
||||
* @public
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
public _m: number[] = new Array(9);
|
||||
|
||||
constructor() {
|
||||
/**
|
||||
* A 3x3 matrix, indexable as a column-major order array.
|
||||
* @public
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this._m = new Array(9);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -23,7 +25,7 @@ export class Mat3 {
|
||||
* @param {Array.<number>} m - Matrix array.
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
set(m) {
|
||||
public set(m: number[]): Mat3 {
|
||||
this._m[0] = m[0];
|
||||
this._m[1] = m[1];
|
||||
this._m[2] = m[2];
|
||||
@ -41,9 +43,9 @@ export class Mat3 {
|
||||
* @public
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
clone() {
|
||||
var res = new Mat3();
|
||||
res.set(this);
|
||||
public clone(): Mat3 {
|
||||
let res = new Mat3();
|
||||
res.set(this._m);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -53,18 +55,18 @@ export class Mat3 {
|
||||
* @param {Mat3} a - Matrix to copy.
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
copy(a) {
|
||||
public copy(a: Mat3): Mat3 {
|
||||
return this.set(a._m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates trasposed matrix from the current.
|
||||
* Creates transposed matrix from the current.
|
||||
* @public
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
transposeTo() {
|
||||
var res = new Mat3();
|
||||
var m = this._m;
|
||||
public transposeTo(): Mat3 {
|
||||
let res = new Mat3();
|
||||
let m = this._m;
|
||||
res._m[0] = m[0];
|
||||
res._m[1] = m[3];
|
||||
res._m[2] = m[6];
|
||||
@ -82,7 +84,7 @@ export class Mat3 {
|
||||
* @public
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
setIdentity() {
|
||||
public setIdentity(): Mat3 {
|
||||
this._m[0] = 1;
|
||||
this._m[1] = 0;
|
||||
this._m[2] = 0;
|
||||
@ -101,11 +103,14 @@ export class Mat3 {
|
||||
* @params {Vec3} p - 3d vector.
|
||||
* @returns {Vec3}
|
||||
*/
|
||||
mulVec(p) {
|
||||
var d = p.x,
|
||||
public mulVec(p: Vec3): Vec3 {
|
||||
|
||||
let d = p.x,
|
||||
e = p.y,
|
||||
g = p.z;
|
||||
var m = this._m;
|
||||
|
||||
let m = this._m;
|
||||
|
||||
return new Vec3(
|
||||
m[0] * d + m[3] * e + m[6] * g,
|
||||
m[1] * d + m[4] * e + m[7] * g,
|
||||
@ -118,10 +123,12 @@ export class Mat3 {
|
||||
* @public
|
||||
* @returns {Mat4}
|
||||
*/
|
||||
toMatrix4() {
|
||||
var res = new Mat4();
|
||||
var b = res._m;
|
||||
var a = this._m;
|
||||
public toMatrix4(): Mat4 {
|
||||
|
||||
let res = new Mat4();
|
||||
let b = res._m;
|
||||
let a = this._m;
|
||||
|
||||
b[0] = a[0];
|
||||
b[1] = a[1];
|
||||
b[2] = a[2];
|
||||
@ -138,6 +145,7 @@ export class Mat3 {
|
||||
b[13] = 0;
|
||||
b[14] = 0;
|
||||
b[15] = 1;
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@ -147,6 +155,6 @@ export class Mat3 {
|
||||
* @static
|
||||
* @return {Mat3}
|
||||
*/
|
||||
export function mat3() {
|
||||
export function mat3(): Mat3 {
|
||||
return new Mat3();
|
||||
}
|
||||
@ -1,22 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
import { Mat3 } from "./Mat3.js";
|
||||
import { Quat } from "./Quat.js";
|
||||
import { Vec3 } from "./Vec3.js";
|
||||
import { Vec4 } from "./Vec4.js";
|
||||
import {Mat3} from "./Mat3";
|
||||
import {Quat} from "./Quat";
|
||||
import {Vec3} from "./Vec3";
|
||||
import {Vec4} from "./Vec4";
|
||||
|
||||
/**
|
||||
* Class represents a 4x4 matrix.
|
||||
* @class
|
||||
*/
|
||||
export class Mat4 {
|
||||
|
||||
/**
|
||||
* A 4x4 matrix, index-able as a column-major order array.
|
||||
* @public
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
public _m: number[] = new Array(16);
|
||||
|
||||
constructor() {
|
||||
/**
|
||||
* A 4x4 matrix, indexable as a column-major order array.
|
||||
* @public
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this._m = new Array(16);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -24,8 +26,8 @@ export class Mat4 {
|
||||
* @static
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
static identity() {
|
||||
var res = new Mat4();
|
||||
static identity(): Mat4 {
|
||||
let res = new Mat4();
|
||||
res._m[0] = 1;
|
||||
res._m[1] = 0;
|
||||
res._m[2] = 0;
|
||||
@ -51,7 +53,7 @@ export class Mat4 {
|
||||
* @param {Array.<number>} m - Matrix array.
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
set(m) {
|
||||
public set(m: number[]): Mat4 {
|
||||
this._m[0] = m[0];
|
||||
this._m[1] = m[1];
|
||||
this._m[2] = m[2];
|
||||
@ -76,19 +78,20 @@ export class Mat4 {
|
||||
* @public
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
clone() {
|
||||
var res = new Mat4();
|
||||
res.set(this);
|
||||
public clone(): Mat4 {
|
||||
let res = new Mat4();
|
||||
res.set(this._m);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy matrix.
|
||||
* @public
|
||||
* @param {Mat3} a - Matrix to copy.
|
||||
* @param {Mat4} a - Matrix to copy.
|
||||
* @return {Mat4}
|
||||
*/
|
||||
copy(a) {
|
||||
this.set(a._m);
|
||||
public copy(a: Mat4): Mat4 {
|
||||
return this.set(a._m);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,9 +99,9 @@ export class Mat4 {
|
||||
* @public
|
||||
* @returns {Mat3} -
|
||||
*/
|
||||
toMatrix3() {
|
||||
var res = new Mat3();
|
||||
var a = this._m,
|
||||
public toMatrix3(): Mat3 {
|
||||
let res = new Mat3();
|
||||
let a = this._m,
|
||||
b = res._m;
|
||||
b[0] = a[0];
|
||||
b[1] = a[1];
|
||||
@ -118,8 +121,8 @@ export class Mat4 {
|
||||
* @param {Vec3} p - 3d vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
mulVec3(p) {
|
||||
var d = p.x,
|
||||
public mulVec3(p: Vec3): Vec3 {
|
||||
let d = p.x,
|
||||
e = p.y,
|
||||
g = p.z;
|
||||
return new Vec3(
|
||||
@ -135,8 +138,8 @@ export class Mat4 {
|
||||
* @param {Vec4} p - 4d vector.
|
||||
* @returns {Vec4} -
|
||||
*/
|
||||
mulVec4(p) {
|
||||
var d = p.x,
|
||||
public mulVec4(p: Vec4): Vec4 {
|
||||
let d = p.x,
|
||||
e = p.y,
|
||||
g = p.z,
|
||||
f = p.w;
|
||||
@ -149,13 +152,13 @@ export class Mat4 {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an inversed 3x3 matrix of the current.
|
||||
* Creates an inverse 3x3 matrix of the current.
|
||||
* @public
|
||||
* @returns {Mat3} -
|
||||
*/
|
||||
toInverseMatrix3() {
|
||||
var a = this._m;
|
||||
var c = a[0],
|
||||
public toInverseMatrix3(): Mat3 | undefined {
|
||||
let a = this._m;
|
||||
let c = a[0],
|
||||
d = a[1],
|
||||
e = a[2],
|
||||
g = a[4],
|
||||
@ -170,12 +173,12 @@ export class Mat4 {
|
||||
n = c * l + d * o + e * m;
|
||||
|
||||
if (!n) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
n = 1 / n;
|
||||
n = 1.0 / n;
|
||||
|
||||
var res = new Mat3();
|
||||
let res = new Mat3();
|
||||
res._m[0] = l * n;
|
||||
res._m[1] = (-k * d + e * j) * n;
|
||||
res._m[2] = (h * d - e * f) * n;
|
||||
@ -185,16 +188,17 @@ export class Mat4 {
|
||||
res._m[6] = m * n;
|
||||
res._m[7] = (-j * c + d * i) * n;
|
||||
res._m[8] = (f * c - d * g) * n;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an inversed matrix of the current.
|
||||
* Creates an inverse matrix of the current.
|
||||
* @public
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
inverseTo(res) {
|
||||
var c = this._m[0],
|
||||
public inverseTo(res: Mat4 = new Mat4): Mat4 {
|
||||
let c = this._m[0],
|
||||
d = this._m[1],
|
||||
e = this._m[2],
|
||||
g = this._m[3],
|
||||
@ -224,8 +228,6 @@ export class Mat4 {
|
||||
E = o * s - m * r,
|
||||
q = 1 / (A * E - B * D + t * C + u * z - v * y + w * x);
|
||||
|
||||
res = res || new Mat4();
|
||||
|
||||
res._m[0] = (h * E - i * D + j * C) * q;
|
||||
res._m[1] = (-d * E + e * D - g * C) * q;
|
||||
res._m[2] = (p * w - r * v + s * u) * q;
|
||||
@ -242,16 +244,17 @@ export class Mat4 {
|
||||
res._m[13] = (c * C - d * y + e * x) * q;
|
||||
res._m[14] = (-n * u + p * B - r * A) * q;
|
||||
res._m[15] = (k * u - l * B + o * A) * q;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a trasposed matrix of the current.
|
||||
* Creates a transposed matrix of the current.
|
||||
* @public
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
transposeTo() {
|
||||
var res = new Mat4();
|
||||
public transposeTo(): Mat4 {
|
||||
let res = new Mat4();
|
||||
res._m[0] = this._m[0];
|
||||
res._m[1] = this._m[4];
|
||||
res._m[2] = this._m[8];
|
||||
@ -276,7 +279,7 @@ export class Mat4 {
|
||||
* @public
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
setIdentity() {
|
||||
public setIdentity(): Mat4 {
|
||||
this._m[0] = 1;
|
||||
this._m[1] = 0;
|
||||
this._m[2] = 0;
|
||||
@ -302,7 +305,8 @@ export class Mat4 {
|
||||
* @param {Mat4} mx - Matrix to multiply.
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
mul(mx) {
|
||||
public mul(mx: Mat4): Mat4 {
|
||||
|
||||
let d = this._m[0],
|
||||
e = this._m[1],
|
||||
g = this._m[2],
|
||||
@ -337,7 +341,8 @@ export class Mat4 {
|
||||
G = mx._m[14],
|
||||
b = mx._m[15];
|
||||
|
||||
var res = new Mat4();
|
||||
let res = new Mat4();
|
||||
|
||||
res._m[0] = A * d + B * h + t * l + u * p;
|
||||
res._m[1] = A * e + B * i + t * o + u * r;
|
||||
res._m[2] = A * g + B * j + t * m + u * s;
|
||||
@ -354,6 +359,7 @@ export class Mat4 {
|
||||
res._m[13] = q * e + F * i + G * o + b * r;
|
||||
res._m[14] = q * g + F * j + G * m + b * s;
|
||||
res._m[15] = q * f + F * k + G * n + b * a;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -363,15 +369,19 @@ export class Mat4 {
|
||||
* @param {Vec3} v - Translate vector.
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
translate(v) {
|
||||
var d = v.x,
|
||||
public translate(v: Vec3): Mat4 {
|
||||
|
||||
let d = v.x,
|
||||
e = v.y,
|
||||
b = v.z;
|
||||
var a = this._m;
|
||||
|
||||
let a = this._m;
|
||||
|
||||
a[12] = a[0] * d + a[4] * e + a[8] * b + a[12];
|
||||
a[13] = a[1] * d + a[5] * e + a[9] * b + a[13];
|
||||
a[14] = a[2] * d + a[6] * e + a[10] * b + a[14];
|
||||
a[15] = a[3] * d + a[7] * e + a[11] * b + a[15];
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -381,8 +391,8 @@ export class Mat4 {
|
||||
* @param {Vec3} v - Translate to position.
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
translateToPosition(v) {
|
||||
var a = this._m;
|
||||
public translateToPosition(v: Vec3): Mat4 {
|
||||
let a = this._m;
|
||||
a[12] = v.x;
|
||||
a[13] = v.y;
|
||||
a[14] = v.z;
|
||||
@ -390,18 +400,20 @@ export class Mat4 {
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate currrent matrix around the aligned axis and angle.
|
||||
* Rotate current matrix around the aligned axis and angle.
|
||||
* @public
|
||||
* @param {Vec3} u - Aligned axis.
|
||||
* @param {number} angle - Aligned axis angle in radians.
|
||||
* @returns {Mat4} -
|
||||
* @todo: OPTIMIZE: reveal multiplication
|
||||
*/
|
||||
rotate(u, angle) {
|
||||
var c = Math.cos(angle),
|
||||
public rotate(u: Vec3, angle: number): Mat4 {
|
||||
|
||||
let c = Math.cos(angle),
|
||||
s = Math.sin(angle);
|
||||
var rot = new Mat4();
|
||||
var mx = rot._m;
|
||||
|
||||
let rot = new Mat4();
|
||||
let mx = rot._m;
|
||||
|
||||
mx[0] = c + (1 - c) * u.x * u.x;
|
||||
mx[1] = (1 - c) * u.y * u.x - s * u.z;
|
||||
mx[2] = (1 - c) * u.z * u.x + s * u.y;
|
||||
@ -418,6 +430,7 @@ export class Mat4 {
|
||||
mx[13] = 0;
|
||||
mx[14] = 0;
|
||||
mx[15] = 1;
|
||||
|
||||
return this.mul(rot);
|
||||
}
|
||||
|
||||
@ -428,10 +441,13 @@ export class Mat4 {
|
||||
* @param {number} angle - Aligned axis angle in radians.
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
setRotation(u, angle) {
|
||||
var c = Math.cos(angle),
|
||||
public setRotation(u: Vec3, angle: number): Mat4 {
|
||||
|
||||
let c = Math.cos(angle),
|
||||
s = Math.sin(angle);
|
||||
var mx = this._m;
|
||||
|
||||
let mx = this._m;
|
||||
|
||||
mx[0] = c + (1 - c) * u.x * u.x;
|
||||
mx[1] = (1 - c) * u.y * u.x - s * u.z;
|
||||
mx[2] = (1 - c) * u.z * u.x + s * u.y;
|
||||
@ -448,18 +464,19 @@ export class Mat4 {
|
||||
mx[13] = 0;
|
||||
mx[14] = 0;
|
||||
mx[15] = 1;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rotation matrix from one vector to another.
|
||||
* @public
|
||||
* @param {Vec3} a - Firtst vector.
|
||||
* @param {Vec3} a - First vector.
|
||||
* @param {Vec3} b - Second vector.
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
rotateBetweenVectors(a, b) {
|
||||
var q = Quat.getRotationBetweenVectors(a, b);
|
||||
public rotateBetweenVectors(a: Vec3, b: Vec3): Mat4 {
|
||||
let q = Quat.getRotationBetweenVectors(a, b);
|
||||
return q.getMat4();
|
||||
}
|
||||
|
||||
@ -469,8 +486,8 @@ export class Mat4 {
|
||||
* @param {Vec3} v - Scale vector.
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
scale(v) {
|
||||
var mx = this._m;
|
||||
public scale(v: Vec3): Mat4 {
|
||||
let mx = this._m;
|
||||
mx[0] = mx[0] * v.x;
|
||||
mx[1] = mx[1] * v.x;
|
||||
mx[2] = mx[2] * v.x;
|
||||
@ -497,10 +514,12 @@ export class Mat4 {
|
||||
* @param {number} far -
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
setPerspective(left, right, bottom, top, near, far) {
|
||||
var h = right - left,
|
||||
public setPerspective(left: number, right: number, bottom: number, top: number, near: number, far: number): Mat4 {
|
||||
|
||||
let h = right - left,
|
||||
i = top - bottom,
|
||||
j = far - near;
|
||||
|
||||
this._m[0] = (near * 2) / h;
|
||||
this._m[1] = 0;
|
||||
this._m[2] = 0;
|
||||
@ -517,6 +536,7 @@ export class Mat4 {
|
||||
this._m[13] = 0;
|
||||
this._m[14] = -(far * near * 2) / j;
|
||||
this._m[15] = 0;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -531,8 +551,9 @@ export class Mat4 {
|
||||
* @param {number} far -
|
||||
* @return {Mat4} -
|
||||
*/
|
||||
setOrtho(left, right, bottom, top, near, far) {
|
||||
var lr = 1.0 / (left - right),
|
||||
public setOrtho(left: number, right: number, bottom: number, top: number, near: number, far: number): Mat4 {
|
||||
|
||||
let lr = 1.0 / (left - right),
|
||||
bt = 1.0 / (bottom - top),
|
||||
nf = 1.0 / (near - far),
|
||||
m = this._m;
|
||||
@ -553,29 +574,31 @@ export class Mat4 {
|
||||
m[13] = (top + bottom) * bt;
|
||||
m[14] = (far + near) * nf;
|
||||
m[15] = 1.0;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current rotation matrix by euler's angles.
|
||||
* @public
|
||||
* @param {number} ax - Rotation angle in radians arond X axis.
|
||||
* @param {number} ay - Rotation angle in radians arond Y axis.
|
||||
* @param {number} az - Rotation angle in radians arond Z axis.
|
||||
* @param {number} ax - Rotation angle in radians around X axis.
|
||||
* @param {number} ay - Rotation angle in radians around Y axis.
|
||||
* @param {number} az - Rotation angle in radians around Z axis.
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
eulerToMatrix(ax, ay, az) {
|
||||
var a = Math.cos(ax),
|
||||
public eulerToMatrix(ax: number, ay: number, az: number): Mat4 {
|
||||
|
||||
let a = Math.cos(ax),
|
||||
b = Math.sin(ax),
|
||||
c = Math.cos(ay),
|
||||
d = Math.sin(ay),
|
||||
e = Math.cos(az),
|
||||
f = Math.sin(az);
|
||||
|
||||
var ad = a * d,
|
||||
let ad = a * d,
|
||||
bd = b * d;
|
||||
|
||||
var mat = this._m;
|
||||
let mat = this._m;
|
||||
|
||||
mat[0] = c * e;
|
||||
mat[1] = -c * f;
|
||||
@ -598,6 +621,6 @@ export class Mat4 {
|
||||
* @static
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
export function mat4() {
|
||||
export function mat4(): Mat4 {
|
||||
return new Mat4();
|
||||
}
|
||||
@ -1,9 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
import {Vec3} from "./Vec3";
|
||||
import {Mat4} from "./Mat4";
|
||||
import {Mat3} from "./Mat3";
|
||||
|
||||
//@ts-ignore
|
||||
import * as math from "../math.js";
|
||||
import { Mat3 } from "./Mat3.js";
|
||||
import { Mat4 } from "./Mat4.js";
|
||||
import { Vec3 } from "./Vec3.js";
|
||||
|
||||
|
||||
/**
|
||||
* A set of 4-dimensional coordinates used to represent rotation in 3-dimensional space.
|
||||
@ -15,43 +18,42 @@ import { Vec3 } from "./Vec3.js";
|
||||
*/
|
||||
export class Quat {
|
||||
/**
|
||||
* @param {Number} [x=0.0] The X component.
|
||||
* @param {Number} [y=0.0] The Y component.
|
||||
* @param {Number} [z=0.0] The Z component.
|
||||
* @param {Number} [w=0.0] The W component.
|
||||
* The X component.
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @default 0.0
|
||||
*/
|
||||
constructor(x = 0.0, y = 0.0, z = 0.0, w = 0.0) {
|
||||
/**
|
||||
* The X component.
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @default 0.0
|
||||
*/
|
||||
this.x = x || 0.0;
|
||||
public x: number;
|
||||
|
||||
/**
|
||||
* The Y component.
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @default 0.0
|
||||
*/
|
||||
this.y = y || 0.0;
|
||||
/**
|
||||
* The Y component.
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @default 0.0
|
||||
*/
|
||||
public y: number;
|
||||
|
||||
/**
|
||||
* The Z component.
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @default 0.0
|
||||
*/
|
||||
this.z = z || 0.0;
|
||||
/**
|
||||
* The Z component.
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @default 0.0
|
||||
*/
|
||||
public z: number;
|
||||
|
||||
/**
|
||||
* The W component.
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @default 0.0
|
||||
*/
|
||||
this.w = w || 0.0;
|
||||
/**
|
||||
* The W component.
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @default 0.0
|
||||
*/
|
||||
public w: number;
|
||||
|
||||
constructor(x: number = 0.0, y: number = 0.0, z: number = 0.0, w: number = 0.0) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +61,7 @@ export class Quat {
|
||||
* @const
|
||||
* @type {Quat}
|
||||
*/
|
||||
static get IDENTITY() {
|
||||
static get IDENTITY(): Quat {
|
||||
return new Quat(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
@ -69,7 +71,7 @@ export class Quat {
|
||||
* @param {number} a - The angle in radians to rotate around the axis.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
static xRotation(a) {
|
||||
static xRotation(a: number): Quat {
|
||||
a *= 0.5;
|
||||
return new Quat(Math.sin(a), 0.0, 0.0, Math.cos(a));
|
||||
}
|
||||
@ -80,7 +82,7 @@ export class Quat {
|
||||
* @param {number} a - The angle in radians to rotate around the axis.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
static yRotation(a) {
|
||||
static yRotation(a: number): Quat {
|
||||
a *= 0.5;
|
||||
return new Quat(0.0, Math.sin(a), 0.0, Math.cos(a));
|
||||
}
|
||||
@ -91,7 +93,7 @@ export class Quat {
|
||||
* @param {number} a - The angle in radians to rotate around the axis.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
static zRotation(a) {
|
||||
static zRotation(a: number): Quat {
|
||||
a *= 0.5;
|
||||
return new Quat(0.0, 0.0, Math.sin(a), Math.cos(a));
|
||||
}
|
||||
@ -103,11 +105,10 @@ export class Quat {
|
||||
* @param {number} [angle=0.0] The angle in radians to rotate around the axis.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
static axisAngleToQuat(axis, angle) {
|
||||
angle = angle || 0.0;
|
||||
var v = axis.normal();
|
||||
var half_angle = angle * 0.5;
|
||||
var sin_a = Math.sin(half_angle);
|
||||
static axisAngleToQuat(axis: Vec3, angle: number = 0): Quat {
|
||||
let v = axis.getNormal();
|
||||
let half_angle = angle * 0.5;
|
||||
let sin_a = Math.sin(half_angle);
|
||||
return new Quat(v.x * sin_a, v.y * sin_a, v.z * sin_a, Math.cos(half_angle));
|
||||
}
|
||||
|
||||
@ -118,12 +119,11 @@ export class Quat {
|
||||
* @param {Vec3} up - Up vector.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
static getLookRotation(forward, up) {
|
||||
var f = forward.normal().negate();
|
||||
var s = up.cross(f).normalize();
|
||||
var u = f.cross(s);
|
||||
|
||||
var z = 1.0 + s.x + u.y + f.z;
|
||||
static getLookRotation(forward: Vec3, up: Vec3): Quat {
|
||||
let f = forward.getNormal().negate();
|
||||
let s = up.cross(f).normalize();
|
||||
let u = f.cross(s);
|
||||
let z = 1.0 + s.x + u.y + f.z;
|
||||
|
||||
if (z > 0.000001) {
|
||||
let fd = 1.0 / (2.0 * Math.sqrt(z));
|
||||
@ -145,23 +145,23 @@ export class Quat {
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a Quat from from source point heading to the destination point.
|
||||
* Computes a Quat from source point heading to the destination point.
|
||||
* @static
|
||||
* @param {Vec3} sourcePoint - Source coordinate.
|
||||
* @param {Vec3} destPoint - Destination coordinate.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
static getLookAtSourceDest(sourcePoint, destPoint) {
|
||||
var forwardVector = destPoint.subA(sourcePoint).normalize();
|
||||
var dot = Vec3.FORWARD.dot(forwardVector);
|
||||
static getLookAtSourceDest(sourcePoint: Vec3, destPoint: Vec3): Quat {
|
||||
let forwardVector = destPoint.subA(sourcePoint).normalize();
|
||||
let dot = Vec3.FORWARD.dot(forwardVector);
|
||||
if (Math.abs(dot - -1.0) < 0.000001) {
|
||||
return Quat.axisAngleToQuat(Vec3.UP, Math.PI);
|
||||
}
|
||||
if (Math.abs(dot - 1.0) < 0.000001) {
|
||||
return new Quat(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
var rotAngle = Math.acos(dot);
|
||||
var rotAxis = Vec3.FORWARD.cross(forwardVector).normalize();
|
||||
let rotAngle = Math.acos(dot);
|
||||
let rotAxis = Vec3.FORWARD.cross(forwardVector).normalize();
|
||||
return Quat.axisAngleToQuat(rotAxis, rotAngle);
|
||||
}
|
||||
|
||||
@ -172,9 +172,9 @@ export class Quat {
|
||||
* @param {Vec3} v - Second vector.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
static getRotationBetweenVectors(u, v) {
|
||||
var w = u.cross(v);
|
||||
var q = new Quat(w.x, w.y, w.z, 1.0 + u.dot(v));
|
||||
static getRotationBetweenVectors(u: Vec3, v: Vec3): Quat {
|
||||
let w = u.cross(v);
|
||||
let q = new Quat(w.x, w.y, w.z, 1.0 + u.dot(v));
|
||||
return q.normalize();
|
||||
}
|
||||
|
||||
@ -186,46 +186,45 @@ export class Quat {
|
||||
* @param {Quat} res
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
static getRotationBetweenVectorsRes(u, v, res) {
|
||||
var w = u.cross(v);
|
||||
static getRotationBetweenVectorsRes(u: Vec3, v: Vec3, res: Quat): Quat {
|
||||
let w = u.cross(v);
|
||||
res.set(w.x, w.y, w.z, 1.0 + u.dot(v));
|
||||
return res.normalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute rotation between two vectors with around vector up
|
||||
* for exactly opposite vectors. If vectors exaclty in the same
|
||||
* direction than returns identity Quat.
|
||||
* for exactly opposite vectors. If vectors exactly in the same
|
||||
* direction as returns identity Quat.
|
||||
* @static
|
||||
* @param {Vec3} source - First vector.
|
||||
* @param {Vec3} dest - Second vector.
|
||||
* @param {Vec3} up - Up vector.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
static getRotationBetweenVectorsUp(source, dest, up) {
|
||||
var dot = source.dot(dest);
|
||||
static getRotationBetweenVectorsUp(source: Vec3, dest: Vec3, up: Vec3): Quat {
|
||||
let dot = source.dot(dest);
|
||||
if (Math.abs(dot + 1.0) < 0.000001) {
|
||||
// vector source and dest point exactly in the opposite direction,
|
||||
// so it is a 180 degrees turn around the up-axis
|
||||
return Quat.axisAngleToQuat(up, Math.PI);
|
||||
}
|
||||
if (Math.abs(dot - 1.0) < 0.000001) {
|
||||
// vector source and dest point exactly in the same direction
|
||||
// vector source and dest point exactly in the same direction,
|
||||
// so we return the identity Quat
|
||||
return new Quat(0, 0, 0, 1);
|
||||
}
|
||||
var rotAngle = Math.acos(dot);
|
||||
var rotAxis = source.cross(dest).normalize();
|
||||
let rotAngle = Math.acos(dot);
|
||||
let rotAxis = source.cross(dest).normalize();
|
||||
return Quat.axisAngleToQuat(rotAxis, rotAngle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the components are zero.
|
||||
* @public
|
||||
* @param {Quat} q - Quat to subtract.
|
||||
* @returns {Quat} -
|
||||
* @returns {boolean} -
|
||||
*/
|
||||
isZero() {
|
||||
public isZero(): boolean {
|
||||
return this.x === 0.0 && this.y === 0.0 && this.z === 0.0 && this.w === 0.0;
|
||||
}
|
||||
|
||||
@ -234,7 +233,7 @@ export class Quat {
|
||||
* @public
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
clear() {
|
||||
public clear(): Quat {
|
||||
this.x = this.y = this.z = this.w = 0;
|
||||
return this;
|
||||
}
|
||||
@ -248,7 +247,7 @@ export class Quat {
|
||||
* @param {Number} [w=0.0] The W component.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
set(x, y, z, w) {
|
||||
public set(x: number, y: number, z: number, w: number): Quat {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
@ -262,7 +261,7 @@ export class Quat {
|
||||
* @param {Quat} q - Copy Quat.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
copy(q) {
|
||||
public copy(q: Quat): Quat {
|
||||
this.x = q.x;
|
||||
this.y = q.y;
|
||||
this.z = q.z;
|
||||
@ -275,7 +274,7 @@ export class Quat {
|
||||
* @public
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
setIdentity() {
|
||||
public setIdentity(): Quat {
|
||||
this.x = 0.0;
|
||||
this.y = 0.0;
|
||||
this.z = 0.0;
|
||||
@ -288,7 +287,7 @@ export class Quat {
|
||||
* @public
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
clone() {
|
||||
public clone(): Quat {
|
||||
return new Quat(this.x, this.y, this.z, this.w);
|
||||
}
|
||||
|
||||
@ -298,7 +297,7 @@ export class Quat {
|
||||
* @param {Quat} q - Quat to add.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
add(q) {
|
||||
public add(q: Quat): Quat {
|
||||
return new Quat(this.x + q.x, this.y + q.y, this.z + q.z, this.w + q.w);
|
||||
}
|
||||
|
||||
@ -308,7 +307,7 @@ export class Quat {
|
||||
* @param {Quat} q - Quat to subtract.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
sub(q) {
|
||||
public sub(q: Quat): Quat {
|
||||
return new Quat(this.x - q.x, this.y - q.y, this.z - q.z, this.w - q.w);
|
||||
}
|
||||
|
||||
@ -318,7 +317,7 @@ export class Quat {
|
||||
* @param {Number} scale - The scalar to multiply with.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
scaleTo(scale) {
|
||||
public scaleTo(scale: number): Quat {
|
||||
return new Quat(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
|
||||
}
|
||||
|
||||
@ -328,7 +327,7 @@ export class Quat {
|
||||
* @param {Number} scale - The scalar to multiply with.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
scale(scale) {
|
||||
public scale(scale: number): Quat {
|
||||
this.x *= scale;
|
||||
this.y *= scale;
|
||||
this.z *= scale;
|
||||
@ -341,7 +340,7 @@ export class Quat {
|
||||
* @public
|
||||
* @returns {Array.<number>} - (exactly 4 entries)
|
||||
*/
|
||||
toVec() {
|
||||
public toVec(): [number, number, number, number] {
|
||||
return [this.x, this.y, this.z, this.w];
|
||||
}
|
||||
|
||||
@ -353,17 +352,19 @@ export class Quat {
|
||||
* @param {number} angle - Angle in radians.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
setFromSphericalCoords(lat, lon, angle) {
|
||||
var sin_a = Math.sin(angle / 2);
|
||||
var cos_a = Math.cos(angle / 2);
|
||||
var sin_lat = Math.sin(lat);
|
||||
var cos_lat = Math.cos(lat);
|
||||
var sin_long = Math.sin(lon);
|
||||
var cos_long = Math.cos(lon);
|
||||
public setFromSphericalCoords(lat: number, lon: number, angle: number): Quat {
|
||||
let sin_a = Math.sin(angle / 2);
|
||||
let cos_a = Math.cos(angle / 2);
|
||||
let sin_lat = Math.sin(lat);
|
||||
let cos_lat = Math.cos(lat);
|
||||
let sin_long = Math.sin(lon);
|
||||
let cos_long = Math.cos(lon);
|
||||
|
||||
this.x = sin_a * cos_lat * sin_long;
|
||||
this.y = sin_a * sin_lat;
|
||||
this.z = sin_a * sin_lat * cos_long;
|
||||
this.w = cos_a;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -374,12 +375,11 @@ export class Quat {
|
||||
* @param {Vec3} up - Up vector.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
setLookRotation(forward, up) {
|
||||
var f = forward.normal().negate();
|
||||
var s = up.cross(f).normalize();
|
||||
var u = f.cross(s);
|
||||
|
||||
var z = 1.0 + s.x + u.y + f.z;
|
||||
public setLookRotation(forward: Vec3, up: Vec3): Quat {
|
||||
let f = forward.getNormal().negate();
|
||||
let s = up.cross(f).normalize();
|
||||
let u = f.cross(s);
|
||||
let z = 1.0 + s.x + u.y + f.z;
|
||||
|
||||
if (z > 0.000001) {
|
||||
let fd = 1.0 / (2.0 * Math.sqrt(z));
|
||||
@ -415,29 +415,37 @@ export class Quat {
|
||||
* @public
|
||||
* @returns {Object} Returns object with latitude, longitude and alpha.
|
||||
*/
|
||||
toSphericalCoords() {
|
||||
var cos_a = this.w;
|
||||
var sin_a = Math.sqrt(1.0 - cos_a * cos_a);
|
||||
public toSphericalCoords(): any {
|
||||
|
||||
let cos_a = this.w;
|
||||
let sin_a = Math.sqrt(1.0 - cos_a * cos_a);
|
||||
|
||||
// var angle = Math.acos(cos_a) * 2;
|
||||
if (Math.abs(sin_a) < 0.0005) {
|
||||
sin_a = 1;
|
||||
}
|
||||
var tx = this.x / sin_a;
|
||||
var ty = this.y / sin_a;
|
||||
var tz = this.z / sin_a;
|
||||
|
||||
var lon,
|
||||
lat = -Math.asin(ty);
|
||||
let tx = this.x / sin_a;
|
||||
let ty = this.y / sin_a;
|
||||
let tz = this.z / sin_a;
|
||||
|
||||
let lon, lat = -Math.asin(ty);
|
||||
|
||||
if (tx * tx + tz * tz < 0.0005) {
|
||||
lon = 0;
|
||||
} else {
|
||||
lon = Math.atan2(tx, tz);
|
||||
}
|
||||
|
||||
if (lon < 0) {
|
||||
lon += 360.0;
|
||||
}
|
||||
|
||||
return { lat: lat, lon: lon, alpha: Math.acos(cos_a) };
|
||||
return {
|
||||
lat: lat,
|
||||
lon: lon,
|
||||
alpha: Math.acos(cos_a)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -447,10 +455,10 @@ export class Quat {
|
||||
* @param {number} angle The angle in radians to rotate around the axis.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
setFromAxisAngle(axis, angle) {
|
||||
var v = axis.normal();
|
||||
var half_angle = angle * 0.5;
|
||||
var sin_a = Math.sin(half_angle);
|
||||
public setFromAxisAngle(axis: Vec3, angle: number): Quat {
|
||||
let v = axis.getNormal();
|
||||
let half_angle = angle * 0.5;
|
||||
let sin_a = Math.sin(half_angle);
|
||||
this.set(v.x * sin_a, v.y * sin_a, v.z * sin_a, Math.cos(half_angle));
|
||||
return this;
|
||||
}
|
||||
@ -460,15 +468,15 @@ export class Quat {
|
||||
* @public
|
||||
* @returns {Object} -
|
||||
*/
|
||||
getAxisAngle() {
|
||||
public getAxisAngle(): any {
|
||||
let x = this.x,
|
||||
y = this.y,
|
||||
z = this.z,
|
||||
w = this.w;
|
||||
var vl = Math.sqrt(x * x + y * y + z * z);
|
||||
var axis, angle;
|
||||
let vl = Math.sqrt(x * x + y * y + z * z);
|
||||
let axis, angle;
|
||||
if (vl > 0.0000001) {
|
||||
var ivl = 1.0 / vl;
|
||||
let ivl = 1.0 / vl;
|
||||
axis = new Vec3(x * ivl, y * ivl, z * ivl);
|
||||
if (w < 0) {
|
||||
angle = 2.0 * Math.atan2(-vl, -w); // -PI,0
|
||||
@ -479,7 +487,11 @@ export class Quat {
|
||||
axis = new Vec3(0, 0, 0);
|
||||
angle = 0;
|
||||
}
|
||||
return { axis: axis, angle: angle };
|
||||
|
||||
return {
|
||||
axis: axis,
|
||||
angle: angle
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -490,20 +502,20 @@ export class Quat {
|
||||
* @param {number} roll - Roll angle in degrees.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
setFromEulerAngles(pitch, yaw, roll) {
|
||||
var ex = pitch * math.RADIANS_HALF,
|
||||
public setFromEulerAngles(pitch: number, yaw: number, roll: number): Quat {
|
||||
let ex = pitch * math.RADIANS_HALF,
|
||||
ey = yaw * math.RADIANS_HALF,
|
||||
ez = roll * math.RADIANS_HALF;
|
||||
|
||||
var cr = Math.cos(ex),
|
||||
let cr = Math.cos(ex),
|
||||
cp = Math.cos(ey),
|
||||
cy = Math.cos(ez);
|
||||
|
||||
var sr = Math.sin(ex),
|
||||
let sr = Math.sin(ex),
|
||||
sp = Math.sin(ey),
|
||||
sy = Math.sin(ez);
|
||||
|
||||
var cpcy = cp * cy,
|
||||
let cpcy = cp * cy,
|
||||
spsy = sp * sy;
|
||||
|
||||
this.w = cr * cpcy + sr * spsy;
|
||||
@ -519,7 +531,7 @@ export class Quat {
|
||||
* @public
|
||||
* @returns {Object} -
|
||||
*/
|
||||
getEulerAngles() {
|
||||
public getEulerAngles(): any {
|
||||
let x = this.x,
|
||||
y = this.y,
|
||||
z = this.z,
|
||||
@ -540,23 +552,27 @@ export class Quat {
|
||||
|
||||
let yaw = Math.atan2(2.0 * (w * z + x * y), 1.0 - 2.0 * (sqy + z * z));
|
||||
|
||||
return { roll, pitch, yaw };
|
||||
return {
|
||||
roll,
|
||||
pitch,
|
||||
yaw
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a Quat from the provided 4x4 matrix instance.
|
||||
* @public
|
||||
* @param {Mat4} m - The rotation matrix.
|
||||
* @param {Mat4} mx - The rotation matrix.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
setFromMatrix4(m) {
|
||||
var tr,
|
||||
public setFromMatrix4(mx: Mat4): Quat {
|
||||
let tr,
|
||||
s,
|
||||
q = [];
|
||||
var i, j, k;
|
||||
m = m._m;
|
||||
let i, j, k;
|
||||
let m = mx._m;
|
||||
|
||||
var nxt = [1, 2, 0];
|
||||
let nxt = [1, 2, 0];
|
||||
|
||||
tr = m[0] + m[5] + m[10];
|
||||
|
||||
@ -595,39 +611,28 @@ export class Quat {
|
||||
/**
|
||||
* Converts current Quat to the rotation 4x4 matrix.
|
||||
* @public
|
||||
* @params {Mat4} [out] - Output matrix
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
getMat4(out) {
|
||||
var xs = this.x + this.x;
|
||||
var ys = this.y + this.y;
|
||||
var zs = this.z + this.z;
|
||||
var wx = this.w * xs;
|
||||
var wy = this.w * ys;
|
||||
var wz = this.w * zs;
|
||||
var xx = this.x * xs;
|
||||
var xy = this.x * ys;
|
||||
var xz = this.x * zs;
|
||||
var yy = this.y * ys;
|
||||
var yz = this.y * zs;
|
||||
var zz = this.z * zs;
|
||||
var m = out || new Mat4();
|
||||
return m.set([
|
||||
1 - (yy + zz),
|
||||
xy - wz,
|
||||
xz + wy,
|
||||
0,
|
||||
xy + wz,
|
||||
1 - (xx + zz),
|
||||
yz - wx,
|
||||
0,
|
||||
xz - wy,
|
||||
yz + wx,
|
||||
1 - (xx + yy),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1
|
||||
public getMat4(out: Mat4 = new Mat4()): Mat4 {
|
||||
let xs = this.x + this.x;
|
||||
let ys = this.y + this.y;
|
||||
let zs = this.z + this.z;
|
||||
let wx = this.w * xs;
|
||||
let wy = this.w * ys;
|
||||
let wz = this.w * zs;
|
||||
let xx = this.x * xs;
|
||||
let xy = this.x * ys;
|
||||
let xz = this.x * zs;
|
||||
let yy = this.y * ys;
|
||||
let yz = this.y * zs;
|
||||
let zz = this.z * zs;
|
||||
|
||||
return out.set([
|
||||
1 - (yy + zz), xy - wz, xz + wy, 0,
|
||||
xy + wz, 1 - (xx + zz), yz - wx, 0,
|
||||
xz - wy, yz + wx, 1 - (xx + yy), 0,
|
||||
0, 0, 0, 1
|
||||
]);
|
||||
}
|
||||
|
||||
@ -637,10 +642,10 @@ export class Quat {
|
||||
* @returns {Mat3} -
|
||||
* @todo NOT TESTED
|
||||
*/
|
||||
getMat3() {
|
||||
var m = new Mat3();
|
||||
var mx = m._m;
|
||||
var c = this.x,
|
||||
public getMat3(): Mat3 {
|
||||
let m = new Mat3();
|
||||
let mx = m._m;
|
||||
let c = this.x,
|
||||
d = this.y,
|
||||
e = this.z,
|
||||
g = this.w,
|
||||
@ -652,7 +657,7 @@ export class Quat {
|
||||
|
||||
c = c * i;
|
||||
|
||||
var l = d * h;
|
||||
let l = d * h;
|
||||
|
||||
d = d * i;
|
||||
e = e * i;
|
||||
@ -674,25 +679,25 @@ export class Quat {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns quatrenion and vector production.
|
||||
* Returns quaternion and vector production.
|
||||
* @public
|
||||
* @param {Vec3} v - 3d Vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
mulVec3(v) {
|
||||
public mulVec3(v: Vec3): Vec3 {
|
||||
// t = 2 * cross(q.xyz, v)
|
||||
// v' = v + q.w * t + cross(q.xyz, t)
|
||||
|
||||
var d = v.x,
|
||||
let d = v.x,
|
||||
e = v.y,
|
||||
g = v.z;
|
||||
|
||||
var b = this.x,
|
||||
let b = this.x,
|
||||
f = this.y,
|
||||
h = this.z,
|
||||
a = this.w;
|
||||
|
||||
var i = a * d + f * g - h * e,
|
||||
let i = a * d + f * g - h * e,
|
||||
j = a * e + h * d - b * g,
|
||||
k = a * g + b * e - f * d;
|
||||
|
||||
@ -711,15 +716,17 @@ export class Quat {
|
||||
* @param {Quat} q - Quat to multiply.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
mul(q) {
|
||||
var d = this.x,
|
||||
public mul(q: Quat): Quat {
|
||||
let d = this.x,
|
||||
e = this.y,
|
||||
g = this.z,
|
||||
a = this.w;
|
||||
var f = q.x,
|
||||
|
||||
let f = q.x,
|
||||
h = q.y,
|
||||
i = q.z,
|
||||
b = q.w;
|
||||
|
||||
return new Quat(
|
||||
d * b + a * f + e * i - g * h,
|
||||
e * b + a * h + g * f - d * i,
|
||||
@ -734,19 +741,22 @@ export class Quat {
|
||||
* @param {Quat} q - Quat to multiply.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
mulA(q) {
|
||||
var d = this.x,
|
||||
public mulA(q: Quat): Quat {
|
||||
let d = this.x,
|
||||
e = this.y,
|
||||
g = this.z,
|
||||
a = this.w;
|
||||
var f = q.x,
|
||||
|
||||
let f = q.x,
|
||||
h = q.y,
|
||||
i = q.z,
|
||||
b = q.w;
|
||||
|
||||
this.x = d * b + a * f + e * i - g * h;
|
||||
this.y = e * b + a * h + g * f - d * i;
|
||||
this.z = g * b + a * i + d * h - e * f;
|
||||
this.w = a * b - d * f - e * h - g * i;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -755,7 +765,7 @@ export class Quat {
|
||||
* @public
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
conjugate() {
|
||||
public conjugate(): Quat {
|
||||
return new Quat(-this.x, -this.y, -this.z, this.w);
|
||||
}
|
||||
|
||||
@ -764,8 +774,8 @@ export class Quat {
|
||||
* @public
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
inverse() {
|
||||
var n = 1 / this.magnitude2();
|
||||
public inverse(): Quat {
|
||||
let n = 1.0 / this.magnitude2();
|
||||
return new Quat(-this.x * n, -this.y * n, -this.z * n, this.w * n);
|
||||
}
|
||||
|
||||
@ -774,8 +784,8 @@ export class Quat {
|
||||
* @public
|
||||
* @returns {number} -
|
||||
*/
|
||||
magnitude() {
|
||||
var b = this.x,
|
||||
public magnitude(): number {
|
||||
let b = this.x,
|
||||
c = this.y,
|
||||
d = this.z,
|
||||
a = this.w;
|
||||
@ -787,8 +797,8 @@ export class Quat {
|
||||
* @public
|
||||
* @returns {number} -
|
||||
*/
|
||||
magnitude2() {
|
||||
var b = this.x,
|
||||
public magnitude2(): number {
|
||||
let b = this.x,
|
||||
c = this.y,
|
||||
d = this.z,
|
||||
a = this.w;
|
||||
@ -798,10 +808,10 @@ export class Quat {
|
||||
/**
|
||||
* Computes the dot (scalar) product of two Quats.
|
||||
* @public
|
||||
* @param {Quat} q - Second quatrnion.
|
||||
* @param {Quat} q - Second quaternion.
|
||||
* @returns {number} -
|
||||
*/
|
||||
dot(q) {
|
||||
public dot(q: Quat): number {
|
||||
return this.x * q.x + this.y * q.y + this.z * q.z;
|
||||
}
|
||||
|
||||
@ -810,12 +820,14 @@ export class Quat {
|
||||
* @public
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
normalize() {
|
||||
var c = this.x,
|
||||
public normalize(): Quat {
|
||||
|
||||
let c = this.x,
|
||||
d = this.y,
|
||||
e = this.z,
|
||||
g = this.w,
|
||||
f = Math.sqrt(c * c + d * d + e * e + g * g);
|
||||
|
||||
if (f === 0.0) {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
@ -823,22 +835,24 @@ export class Quat {
|
||||
this.w = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
f = 1 / f;
|
||||
this.x = c * f;
|
||||
this.y = d * f;
|
||||
this.z = e * f;
|
||||
this.w = g * f;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two Quats.
|
||||
* @public
|
||||
* @param {Quat} q - Second quatrnion.
|
||||
* @param {Quat} q - Second quaternion.
|
||||
* @returns {Boolean} -
|
||||
*/
|
||||
isEqual(q) {
|
||||
var matching = this.dot(q);
|
||||
public isEqual(q: Quat): boolean {
|
||||
let matching = this.dot(q);
|
||||
if (Math.abs(matching - 1.0) < 0.001) {
|
||||
return true;
|
||||
}
|
||||
@ -852,8 +866,9 @@ export class Quat {
|
||||
* @param {number} t - interpolation amount between the two Quats.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
slerp(b, t) {
|
||||
var ax = this.x,
|
||||
public slerp(b: Quat, t: number): Quat {
|
||||
|
||||
let ax = this.x,
|
||||
ay = this.y,
|
||||
az = this.z,
|
||||
aw = this.w,
|
||||
@ -862,7 +877,7 @@ export class Quat {
|
||||
bz = b.z,
|
||||
bw = b.w;
|
||||
|
||||
var omega, cosom, sinom, scale0, scale1;
|
||||
let omega, cosom, sinom, scale0, scale1;
|
||||
|
||||
cosom = ax * bx + ay * by + az * bz + aw * bw;
|
||||
|
||||
@ -898,18 +913,20 @@ export class Quat {
|
||||
* @param {Boolean} [reprojectAxis] -
|
||||
* @returns {Number} -
|
||||
*/
|
||||
getRoll(reprojectAxis) {
|
||||
var x = this.x,
|
||||
public getRoll(reprojectAxis: boolean = false): number {
|
||||
|
||||
let x = this.x,
|
||||
y = this.y,
|
||||
z = this.z,
|
||||
w = this.w;
|
||||
|
||||
if (reprojectAxis) {
|
||||
var fTy = 2.0 * y;
|
||||
var fTz = 2.0 * z;
|
||||
var fTwz = fTz * w;
|
||||
var fTxy = fTy * x;
|
||||
var fTyy = fTy * y;
|
||||
var fTzz = fTz * z;
|
||||
let fTy = 2.0 * y;
|
||||
let fTz = 2.0 * z;
|
||||
let fTwz = fTz * w;
|
||||
let fTxy = fTy * x;
|
||||
let fTyy = fTy * y;
|
||||
let fTzz = fTz * z;
|
||||
return Math.atan2(fTxy + fTwz, 1.0 - (fTyy + fTzz));
|
||||
} else {
|
||||
return Math.atan2(2 * (x * y + w * z), w * w + x * x - y * y - z * z);
|
||||
@ -922,18 +939,20 @@ export class Quat {
|
||||
* @param {Boolean} [reprojectAxis] -
|
||||
* @returns {number} -
|
||||
*/
|
||||
getPitch(reprojectAxis) {
|
||||
var x = this.x,
|
||||
public getPitch(reprojectAxis: boolean = false): number {
|
||||
|
||||
let x = this.x,
|
||||
y = this.y,
|
||||
z = this.z,
|
||||
w = this.w;
|
||||
|
||||
if (reprojectAxis) {
|
||||
var fTx = 2.0 * x;
|
||||
var fTz = 2.0 * z;
|
||||
var fTwx = fTx * w;
|
||||
var fTxx = fTx * x;
|
||||
var fTyz = fTz * y;
|
||||
var fTzz = fTz * z;
|
||||
let fTx = 2.0 * x;
|
||||
let fTz = 2.0 * z;
|
||||
let fTwx = fTx * w;
|
||||
let fTxx = fTx * x;
|
||||
let fTyz = fTz * y;
|
||||
let fTzz = fTz * z;
|
||||
return Math.atan2(fTyz + fTwx, 1.0 - (fTxx + fTzz));
|
||||
} else {
|
||||
return Math.atan2(2 * (y * z + w * x), w * w - x * x - y * y + z * z);
|
||||
@ -946,19 +965,21 @@ export class Quat {
|
||||
* @param {Boolean} [reprojectAxis] -
|
||||
* @returns {number} -
|
||||
*/
|
||||
getYaw(reprojectAxis = false) {
|
||||
var x = this.x,
|
||||
public getYaw(reprojectAxis: boolean = false): number {
|
||||
|
||||
let x = this.x,
|
||||
y = this.y,
|
||||
z = this.z,
|
||||
w = this.w;
|
||||
|
||||
if (reprojectAxis) {
|
||||
var fTx = 2.0 * x;
|
||||
var fTy = 2.0 * y;
|
||||
var fTz = 2.0 * z;
|
||||
var fTwy = fTy * w;
|
||||
var fTxx = fTx * x;
|
||||
var fTxz = fTz * x;
|
||||
var fTyy = fTy * y;
|
||||
let fTx = 2.0 * x;
|
||||
let fTy = 2.0 * y;
|
||||
let fTz = 2.0 * z;
|
||||
let fTwy = fTy * w;
|
||||
let fTxx = fTx * x;
|
||||
let fTxz = fTz * x;
|
||||
let fTyy = fTy * y;
|
||||
return Math.atan2(fTxz + fTwy, 1.0 - (fTxx + fTyy));
|
||||
} else {
|
||||
return Math.asin(-2 * (x * z - w * y));
|
||||
@ -975,6 +996,6 @@ export class Quat {
|
||||
* @param {Number} [w=0.0] The W component.
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
export function quat(x, y, z, w) {
|
||||
export function quat(x: number = 0, y: number = 0, z: number = 0, w: number = 0): Quat {
|
||||
return new Quat(x, y, z, w);
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
import { Quat } from "./Quat.js";
|
||||
import { Vec4 } from "./Vec4.js";
|
||||
import {Quat} from "./Quat";
|
||||
import {Vec4} from "./Vec4";
|
||||
|
||||
/**
|
||||
* Class represents a 3d vector.
|
||||
@ -11,90 +11,94 @@ import { Vec4 } from "./Vec4.js";
|
||||
* @param {number} [z] - Third value.
|
||||
*/
|
||||
export class Vec3 {
|
||||
constructor(x = 0.0, y = 0.0, z = 0.0) {
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.x = x || 0.0;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.y = y || 0.0;
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
public x: number;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.z = z || 0.0;
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
public y: number;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
public z: number;
|
||||
|
||||
constructor(x: number = 0.0, y: number = 0.0, z: number = 0.0) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/** @const */
|
||||
static get UP() {
|
||||
static get UP(): Vec3 {
|
||||
return new Vec3(0, 1, 0);
|
||||
}
|
||||
|
||||
/** @const */
|
||||
static get DOWN() {
|
||||
static get DOWN(): Vec3 {
|
||||
return new Vec3(0, -1, 0);
|
||||
}
|
||||
|
||||
/** @const */
|
||||
static get RIGHT() {
|
||||
static get RIGHT(): Vec3 {
|
||||
return new Vec3(1, 0, 0);
|
||||
}
|
||||
|
||||
/** @const */
|
||||
static get LEFT() {
|
||||
static get LEFT(): Vec3 {
|
||||
return new Vec3(-1, 0, 0);
|
||||
}
|
||||
|
||||
/** @const */
|
||||
static get FORWARD() {
|
||||
static get FORWARD(): Vec3 {
|
||||
return new Vec3(0, 0, -1);
|
||||
}
|
||||
|
||||
/** @const */
|
||||
static get BACKWARD() {
|
||||
static get BACKWARD(): Vec3 {
|
||||
return new Vec3(0, 0, 1);
|
||||
}
|
||||
|
||||
/** @const */
|
||||
static get ZERO() {
|
||||
static get ZERO(): Vec3 {
|
||||
return new Vec3();
|
||||
}
|
||||
|
||||
/** @const */
|
||||
static get UNIT_X() {
|
||||
static get UNIT_X(): Vec3 {
|
||||
return new Vec3(1, 0, 0);
|
||||
}
|
||||
|
||||
/** @const */
|
||||
static get UNIT_Y() {
|
||||
static get UNIT_Y(): Vec3 {
|
||||
return new Vec3(0, 1, 0);
|
||||
}
|
||||
|
||||
/** @const */
|
||||
static get UNIT_Z() {
|
||||
static get UNIT_Z(): Vec3 {
|
||||
return new Vec3(0, 0, 1);
|
||||
}
|
||||
|
||||
/** @const */
|
||||
static get NORTH() {
|
||||
static get NORTH(): Vec3 {
|
||||
return Vec3.UNIT_Z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Separate 63 bit Vec3 to two Vec3 32 bit float values.
|
||||
* Separate 63 bit Vec3 to two Vec3 32-bit float values.
|
||||
* @function
|
||||
* @param {number} value - Double type value.
|
||||
* @param {Vec3} v - Double type value.
|
||||
* @param {Vec3} high - Out vector high values.
|
||||
* @param {Vec3} low - Out vector low values.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
static doubleToTwoFloats(v, high, low) {
|
||||
static doubleToTwoFloats(v: Vec3, high: Vec3, low: Vec3) {
|
||||
let x = v.x,
|
||||
y = v.y,
|
||||
z = v.z;
|
||||
@ -131,14 +135,14 @@ export class Vec3 {
|
||||
}
|
||||
|
||||
/**
|
||||
* Separate 63 bit Vec3 to two Vec3 32 bit float values.
|
||||
* Separate 63 bit Vec3 to two Vec3 32-bit float values.
|
||||
* @function
|
||||
* @param {number} value - Double type value.
|
||||
* @param {Vec3} v - Double type value.
|
||||
* @param {Float32Array} high - Out vector high values.
|
||||
* @param {Float32Array} low - Out vector low values.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
static doubleToTwoFloat32Array(v, high, low) {
|
||||
static doubleToTwoFloat32Array(v: Vec3, high: [number, number, number], low: [number, number, number]) {
|
||||
let x = v.x,
|
||||
y = v.y,
|
||||
z = v.z;
|
||||
@ -177,10 +181,10 @@ export class Vec3 {
|
||||
/**
|
||||
* Creates 3d vector from array.
|
||||
* @function
|
||||
* @param {Array.<number>} arr - Input array (exactly 3 entries)
|
||||
* @param {[number, number, number]} arr - Input array (exactly 3 entries)
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
static fromVec(arr) {
|
||||
static fromVec(arr: [number, number, number]): Vec3 {
|
||||
return new Vec3(arr[0], arr[1], arr[2]);
|
||||
}
|
||||
|
||||
@ -191,7 +195,7 @@ export class Vec3 {
|
||||
* @param {Vec3} b - Second vector.
|
||||
* @returns {number} -
|
||||
*/
|
||||
static angle(a, b) {
|
||||
static angle(a: Vec3, b: Vec3): number {
|
||||
return Math.acos(a.dot(b) / Math.sqrt(a.length2() * b.length2()));
|
||||
}
|
||||
|
||||
@ -203,7 +207,7 @@ export class Vec3 {
|
||||
* @param {number} l - Interpolate value.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
static lerp(v1, v2, l) {
|
||||
static lerp(v1: Vec3, v2: Vec3, l: number) {
|
||||
return new Vec3(v1.x + (v2.x - v1.x) * l, v1.y + (v2.y - v1.y) * l, v1.z + (v2.z - v1.z) * l);
|
||||
}
|
||||
|
||||
@ -214,8 +218,8 @@ export class Vec3 {
|
||||
* @param {Vec3} b - Second vector.
|
||||
* @returns {Vec3} - Summary vector.
|
||||
*/
|
||||
static add(a, b) {
|
||||
var res = new Vec3(a.x, a.y, a.z);
|
||||
static add(a: Vec3, b: Vec3): Vec3 {
|
||||
let res = new Vec3(a.x, a.y, a.z);
|
||||
res.addA(b);
|
||||
return res;
|
||||
}
|
||||
@ -227,8 +231,8 @@ export class Vec3 {
|
||||
* @param {Vec3} b - Second vector.
|
||||
* @returns {Vec3} - Vectors subtraction.
|
||||
*/
|
||||
static sub(a, b) {
|
||||
var res = new Vec3(a.x, a.y, a.z);
|
||||
static sub(a: Vec3, b: Vec3): Vec3 {
|
||||
let res = new Vec3(a.x, a.y, a.z);
|
||||
res.subA(b);
|
||||
return res;
|
||||
}
|
||||
@ -240,7 +244,7 @@ export class Vec3 {
|
||||
* @param {number} scale - Scale value.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
static scale(a, scale) {
|
||||
static scale(a: Vec3, scale: number): Vec3 {
|
||||
return a.scaleTo(scale);
|
||||
}
|
||||
|
||||
@ -251,21 +255,21 @@ export class Vec3 {
|
||||
* @param {Vec3} b - Second vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
static mul(a, b) {
|
||||
var res = new Vec3(a.x, a.y, a.z);
|
||||
static mul(a: Vec3, b: Vec3): Vec3 {
|
||||
let res = new Vec3(a.x, a.y, a.z);
|
||||
res.mulA(b);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if two vectors are non collinear.
|
||||
* Returns true if two vectors are non-collinear.
|
||||
* @public
|
||||
* @param {Vec3} a - First vector.
|
||||
* @param {Vec3} b - Second vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
static noncollinear(a, b) {
|
||||
return a.y * b.z - a.z * b.y || a.z * b.x - a.x * b.z || a.x * b.y - a.y * b.z;
|
||||
static noncollinear(a: Vec3, b: Vec3): boolean {
|
||||
return Boolean(a.y * b.z - a.z * b.y || a.z * b.x - a.x * b.z || a.x * b.y - a.y * b.z);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,8 +280,8 @@ export class Vec3 {
|
||||
* @param {Vec3} [def] - Default value for non existed result.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
static proj_b_to_plane(b, n, def) {
|
||||
var res = b.sub(n.scaleTo(n.dot(b) / n.dot(n)));
|
||||
static proj_b_to_plane(b: Vec3, n: Vec3, def?: Vec3): Vec3 {
|
||||
let res = b.sub(n.scaleTo(n.dot(b) / n.dot(n)));
|
||||
if (def && res.isZero()) {
|
||||
return new Vec3(def.x, def.y, def.z);
|
||||
}
|
||||
@ -291,7 +295,7 @@ export class Vec3 {
|
||||
* @param {Vec3} a - Second vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
static proj_b_to_a(b, a) {
|
||||
static proj_b_to_a(b: Vec3, a: Vec3): Vec3 {
|
||||
return a.scaleTo(a.dot(b) / a.dot(a));
|
||||
}
|
||||
|
||||
@ -303,8 +307,8 @@ export class Vec3 {
|
||||
* @param {Vec3} tangent - Tangent vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
static orthoNormalize(normal, tangent) {
|
||||
normal = normal.normal();
|
||||
static orthoNormalize(normal: Vec3, tangent: Vec3): Vec3 {
|
||||
normal = normal.getNormal();
|
||||
normal.scale(tangent.dot(normal));
|
||||
return tangent.subA(normal).normalize();
|
||||
}
|
||||
@ -316,21 +320,21 @@ export class Vec3 {
|
||||
* @param {Vec3} b - Second vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
static div(a, b) {
|
||||
var res = new Vec3(a.x, a.y, a.z);
|
||||
static div(a: Vec3, b: Vec3): Vec3 {
|
||||
let res = new Vec3(a.x, a.y, a.z);
|
||||
res.divA(b);
|
||||
return res;
|
||||
}
|
||||
|
||||
static length2(a) {
|
||||
static length2(a: Vec3): number {
|
||||
return a.length2();
|
||||
}
|
||||
|
||||
static length(a) {
|
||||
return a.length();
|
||||
}
|
||||
// static length(a: Vec3): number {
|
||||
// return a.length();
|
||||
// }
|
||||
|
||||
static dot(a, b) {
|
||||
static dot(a: Vec3, b: Vec3): number {
|
||||
return a.dot(b);
|
||||
}
|
||||
|
||||
@ -339,7 +343,7 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Vec4} -
|
||||
*/
|
||||
toVec4() {
|
||||
public toVec4(): Vec4 {
|
||||
return new Vec4(this.x, this.y, this.z, 1.0);
|
||||
}
|
||||
|
||||
@ -348,7 +352,7 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
clone() {
|
||||
public clone(): Vec3 {
|
||||
return new Vec3(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
@ -357,8 +361,8 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {string} -
|
||||
*/
|
||||
toString() {
|
||||
return "(" + this.x + "," + this.y + "," + this.z + ")";
|
||||
public toString(): string {
|
||||
return `(${this.x},${this.y},${this.z})`;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -366,7 +370,7 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {boolean} -
|
||||
*/
|
||||
isZero() {
|
||||
public isZero(): boolean {
|
||||
return !(this.x || this.y || this.z);
|
||||
}
|
||||
|
||||
@ -376,7 +380,7 @@ export class Vec3 {
|
||||
* @param {Vec3} a - Project vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
projToVec(a) {
|
||||
public projToVec(a: Vec3): Vec3 {
|
||||
return a.scaleTo(a.dot(this) / a.dot(a));
|
||||
}
|
||||
|
||||
@ -386,7 +390,7 @@ export class Vec3 {
|
||||
* @param {Vec3} p - Vector to compare.
|
||||
* @returns {boolean} -
|
||||
*/
|
||||
equal(p) {
|
||||
public equal(p: Vec3): boolean {
|
||||
return this.x === p.x && this.y === p.y && this.z === p.z;
|
||||
}
|
||||
|
||||
@ -395,7 +399,7 @@ export class Vec3 {
|
||||
* @param {Vec3} p - Vector to copy.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
copy(p) {
|
||||
public copy(p: Vec3): Vec3 {
|
||||
this.x = p.x;
|
||||
this.y = p.y;
|
||||
this.z = p.z;
|
||||
@ -407,7 +411,7 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {number} -
|
||||
*/
|
||||
length() {
|
||||
public length(): number {
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
||||
}
|
||||
|
||||
@ -416,7 +420,7 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {number} -
|
||||
*/
|
||||
length2() {
|
||||
public length2(): number {
|
||||
return this.x * this.x + this.y * this.y + this.z * this.z;
|
||||
}
|
||||
|
||||
@ -425,7 +429,7 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
getQuat() {
|
||||
public getQuat(): Quat {
|
||||
return new Quat(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
@ -435,7 +439,7 @@ export class Vec3 {
|
||||
* @param {Vec3} p - Point to add.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
addA(p) {
|
||||
public addA(p: Vec3): Vec3 {
|
||||
this.x += p.x;
|
||||
this.y += p.y;
|
||||
this.z += p.z;
|
||||
@ -448,7 +452,7 @@ export class Vec3 {
|
||||
* @param {Vec3} p - Vector to add.
|
||||
* @returns {Vec3} Returns a sum vector.
|
||||
*/
|
||||
add(p) {
|
||||
public add(p: Vec3): Vec3 {
|
||||
return new Vec3(this.x + p.x, this.y + p.y, this.z + p.z);
|
||||
}
|
||||
|
||||
@ -458,7 +462,7 @@ export class Vec3 {
|
||||
* @param {Vec3} p - Subtract vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
subA(p) {
|
||||
public subA(p: Vec3): Vec3 {
|
||||
this.x -= p.x;
|
||||
this.y -= p.y;
|
||||
this.z -= p.z;
|
||||
@ -471,7 +475,7 @@ export class Vec3 {
|
||||
* @param {Vec3} p - Subtract vector.
|
||||
* @return {Vec3} Returns new instance of a subtraction
|
||||
*/
|
||||
sub(p) {
|
||||
public sub(p: Vec3): Vec3 {
|
||||
return new Vec3(this.x - p.x, this.y - p.y, this.z - p.z);
|
||||
}
|
||||
|
||||
@ -481,7 +485,7 @@ export class Vec3 {
|
||||
* @param {number} scale - Scale value.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
scale(scale) {
|
||||
public scale(scale: number): Vec3 {
|
||||
this.x *= scale;
|
||||
this.y *= scale;
|
||||
this.z *= scale;
|
||||
@ -494,7 +498,7 @@ export class Vec3 {
|
||||
* @param {number} scale - Scale value.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
scaleTo(scale) {
|
||||
public scaleTo(scale: number): Vec3 {
|
||||
return new Vec3(this.x * scale, this.y * scale, this.z * scale);
|
||||
}
|
||||
|
||||
@ -504,7 +508,7 @@ export class Vec3 {
|
||||
* @param {Vec3} vec - Multiply vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
mulA(vec) {
|
||||
public mulA(vec: Vec3): Vec3 {
|
||||
this.x *= vec.x;
|
||||
this.y *= vec.y;
|
||||
this.z *= vec.z;
|
||||
@ -517,7 +521,7 @@ export class Vec3 {
|
||||
* @param {Vec3} vec - Multiply vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
mul(vec) {
|
||||
public mul(vec: Vec3): Vec3 {
|
||||
return new Vec3(this.x * vec.x, this.y * vec.y, this.z * vec.z);
|
||||
}
|
||||
|
||||
@ -527,7 +531,7 @@ export class Vec3 {
|
||||
* @param {Vec3} vec - Div vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
divA(vec) {
|
||||
public divA(vec: Vec3): Vec3 {
|
||||
this.x /= vec.x;
|
||||
this.y /= vec.y;
|
||||
this.z /= vec.z;
|
||||
@ -540,7 +544,7 @@ export class Vec3 {
|
||||
* @param {Vec3} vec - Div vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
div(vec) {
|
||||
public div(vec: Vec3): Vec3 {
|
||||
return new Vec3(this.x / vec.x, this.y / vec.y, this.z / vec.z);
|
||||
}
|
||||
|
||||
@ -550,7 +554,7 @@ export class Vec3 {
|
||||
* @param {Vec3} a - Another vector.
|
||||
* @returns {number} -
|
||||
*/
|
||||
dot(a) {
|
||||
public dot(a: Vec3): number {
|
||||
return a.x * this.x + a.y * this.y + a.z * this.z;
|
||||
}
|
||||
|
||||
@ -560,7 +564,7 @@ export class Vec3 {
|
||||
* @param {Array.<number>} arr - Array vector. (exactly 3 entries)
|
||||
* @returns {number} -
|
||||
*/
|
||||
dotArr(arr) {
|
||||
public dotArr(arr: [number, number, number]): number {
|
||||
return arr[0] * this.x + arr[1] * this.y + arr[2] * this.z;
|
||||
}
|
||||
|
||||
@ -570,7 +574,7 @@ export class Vec3 {
|
||||
* @param {Vec3} point3 - Another vector.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
cross(point3) {
|
||||
public cross(point3: Vec3): Vec3 {
|
||||
return new Vec3(
|
||||
this.y * point3.z - this.z * point3.y,
|
||||
this.z * point3.x - this.x * point3.z,
|
||||
@ -583,7 +587,7 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
clear() {
|
||||
public clear(): Vec3 {
|
||||
this.x = this.y = this.z = 0;
|
||||
return this;
|
||||
}
|
||||
@ -593,11 +597,11 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
getNormal() {
|
||||
var res = new Vec3();
|
||||
public getNormal(): Vec3 {
|
||||
let res = new Vec3();
|
||||
res.copy(this);
|
||||
|
||||
var length = 1.0 / res.length();
|
||||
let length = 1.0 / res.length();
|
||||
|
||||
res.x *= length;
|
||||
res.y *= length;
|
||||
@ -612,11 +616,11 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
normal() {
|
||||
var res = new Vec3();
|
||||
public normal(): Vec3 {
|
||||
let res = new Vec3();
|
||||
res.copy(this);
|
||||
|
||||
var length = 1.0 / res.length();
|
||||
let length = 1.0 / res.length();
|
||||
|
||||
res.x *= length;
|
||||
res.y *= length;
|
||||
@ -630,11 +634,11 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
normalNegate() {
|
||||
var res = new Vec3();
|
||||
public normalNegate(): Vec3 {
|
||||
let res = new Vec3();
|
||||
res.copy(this);
|
||||
|
||||
var length = -1.0 / res.length();
|
||||
let length = -1.0 / res.length();
|
||||
|
||||
res.x *= length;
|
||||
res.y *= length;
|
||||
@ -648,11 +652,11 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
normalNegateScale(scale) {
|
||||
var res = new Vec3();
|
||||
public normalNegateScale(scale: number): Vec3 {
|
||||
let res = new Vec3();
|
||||
res.copy(this);
|
||||
|
||||
var length = -scale / res.length();
|
||||
let length = -scale / res.length();
|
||||
|
||||
res.x *= length;
|
||||
res.y *= length;
|
||||
@ -666,11 +670,11 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
normalScale(scale) {
|
||||
var res = new Vec3();
|
||||
public normalScale(scale: number): Vec3 {
|
||||
let res = new Vec3();
|
||||
res.copy(this);
|
||||
|
||||
var length = scale / res.length();
|
||||
let length = scale / res.length();
|
||||
|
||||
res.x *= length;
|
||||
res.y *= length;
|
||||
@ -684,13 +688,11 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
normalize() {
|
||||
var length = 1.0 / this.length();
|
||||
|
||||
public normalize(): Vec3 {
|
||||
let length = 1.0 / this.length();
|
||||
this.x *= length;
|
||||
this.y *= length;
|
||||
this.z *= length;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -700,7 +702,7 @@ export class Vec3 {
|
||||
* @returns {Array.<number>} - (exactly 3 entries)
|
||||
* @deprecated
|
||||
*/
|
||||
toVec() {
|
||||
public toVec(): [number, number, number] {
|
||||
return [this.x, this.y, this.z];
|
||||
}
|
||||
|
||||
@ -709,7 +711,7 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Array.<number>} - (exactly 3 entries)
|
||||
*/
|
||||
toArray() {
|
||||
public toArray(): [number, number, number] {
|
||||
return [this.x, this.y, this.z];
|
||||
}
|
||||
|
||||
@ -719,7 +721,7 @@ export class Vec3 {
|
||||
* @param {Vec3} p - Distant point.
|
||||
* @returns {number} -
|
||||
*/
|
||||
distance(p) {
|
||||
public distance(p: Vec3): number {
|
||||
let dx = this.x - p.x,
|
||||
dy = this.y - p.y,
|
||||
dz = this.z - p.z;
|
||||
@ -732,7 +734,7 @@ export class Vec3 {
|
||||
* @param {Vec3} p - Distant point.
|
||||
* @returns {number} -
|
||||
*/
|
||||
distance2(p) {
|
||||
public distance2(p: Vec3): number {
|
||||
let dx = this.x - p.x,
|
||||
dy = this.y - p.y,
|
||||
dz = this.z - p.z;
|
||||
@ -747,7 +749,7 @@ export class Vec3 {
|
||||
* @param {number} z - Value Z.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
set(x, y, z) {
|
||||
public set(x: number, y: number, z: number): Vec3 {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
@ -759,7 +761,7 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
negate() {
|
||||
public negate(): Vec3 {
|
||||
this.x = -this.x;
|
||||
this.y = -this.y;
|
||||
this.z = -this.z;
|
||||
@ -771,7 +773,7 @@ export class Vec3 {
|
||||
* @public
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
negateTo() {
|
||||
public negateTo(): Vec3 {
|
||||
return new Vec3(-this.x, -this.y, -this.z);
|
||||
}
|
||||
|
||||
@ -782,8 +784,8 @@ export class Vec3 {
|
||||
* @param {Vec3} direction - Ray direction.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
projToRay(pos, direction) {
|
||||
var v = Vec3.proj_b_to_a(Vec3.sub(this, pos), direction);
|
||||
public projToRay(pos: Vec3, direction: Vec3): Vec3 {
|
||||
let v = Vec3.proj_b_to_a(Vec3.sub(this, pos), direction);
|
||||
v.addA(pos);
|
||||
return v;
|
||||
}
|
||||
@ -794,7 +796,7 @@ export class Vec3 {
|
||||
* @param {Vec3} a - Another vector.
|
||||
* @returns {number} -
|
||||
*/
|
||||
angle(a) {
|
||||
public angle(a: Vec3): number {
|
||||
return Vec3.angle(this, a);
|
||||
}
|
||||
|
||||
@ -805,7 +807,7 @@ export class Vec3 {
|
||||
* @param {number} l - Interpolate value.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
lerp(v2, l) {
|
||||
public lerp(v2: Vec3, l: number) {
|
||||
return new Vec3(
|
||||
this.x + (v2.x - this.x) * l,
|
||||
this.y + (v2.y - this.y) * l,
|
||||
@ -820,8 +822,8 @@ export class Vec3 {
|
||||
* @param {number} t - Interpolate value.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
smerp(v2, t) {
|
||||
var one_d = 1 - t;
|
||||
public smerp(v2: Vec3, t: number): Vec3 {
|
||||
let one_d = 1 - t;
|
||||
return new Vec3(
|
||||
this.x * t + v2.x * one_d,
|
||||
this.y * t + v2.y * one_d,
|
||||
@ -829,7 +831,7 @@ export class Vec3 {
|
||||
);
|
||||
}
|
||||
|
||||
static get LERP_DELTA() {
|
||||
static get LERP_DELTA(): number {
|
||||
return 1e-6;
|
||||
}
|
||||
|
||||
@ -843,19 +845,19 @@ export class Vec3 {
|
||||
* @param {number} t - The parameter t is clamped to the range [0, 1].
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
slerp(v2, t) {
|
||||
var res = new Vec3();
|
||||
public slerp(v2: Vec3, t: number): Vec3 {
|
||||
let res = new Vec3();
|
||||
|
||||
if (t <= 0.0) {
|
||||
res.copy(this);
|
||||
return;
|
||||
return res;
|
||||
} else if (t >= 1.0) {
|
||||
res.copy(v2);
|
||||
return;
|
||||
return res;
|
||||
}
|
||||
|
||||
var omega, sinom, scale0, scale1;
|
||||
var cosom = this.dot(v2);
|
||||
let omega, sinom, scale0, scale1;
|
||||
let cosom = this.dot(v2);
|
||||
|
||||
if (1.0 - cosom > Vec3.LERP_DELTA) {
|
||||
omega = Math.acos(cosom);
|
||||
@ -877,7 +879,7 @@ export class Vec3 {
|
||||
* @returns {Quat} -
|
||||
* @todo: TEST IT!
|
||||
*/
|
||||
getRotationTo(dest, fallbackAxis) {
|
||||
public getRotationTo(dest: Vec3, fallbackAxis: Vec3): Quat {
|
||||
// Based on Stan Melax's article in Game Programming Gems
|
||||
// Copy, since cannot modify local
|
||||
let v0 = this.clone();
|
||||
@ -892,9 +894,9 @@ export class Vec3 {
|
||||
}
|
||||
|
||||
if (d < 1e-6 - 1.0) {
|
||||
if (!fallbackAxis.isEqual(Vec3.ZERO)) {
|
||||
if (!fallbackAxis.equal(Vec3.ZERO)) {
|
||||
// rotate 180 degrees about the fallback axis
|
||||
return Quat.axisAngleToQuat(Math.PI, fallbackAxis);
|
||||
return Quat.axisAngleToQuat(fallbackAxis, Math.PI);
|
||||
} else {
|
||||
// Generate an axis
|
||||
let axis = Vec3.UNIT_X.cross(v0);
|
||||
@ -903,16 +905,14 @@ export class Vec3 {
|
||||
axis = Vec3.UNIT_Y.cross(v0);
|
||||
}
|
||||
axis.normalize();
|
||||
return Quat.axisAngleToQuat(Math.PI, axis);
|
||||
return Quat.axisAngleToQuat(axis, Math.PI);
|
||||
}
|
||||
} else {
|
||||
let s = Math.sqrt((1 + d) * 2);
|
||||
let invs = 1.0 / s;
|
||||
|
||||
let c = v0.cross(v1);
|
||||
|
||||
let q = new Quat(c.x * invs, c.y * invs, c.z * invs, s * 0.5);
|
||||
q.normalise();
|
||||
q.normalize();
|
||||
return q;
|
||||
}
|
||||
}
|
||||
@ -921,11 +921,11 @@ export class Vec3 {
|
||||
/**
|
||||
* Vector 3d object creator.
|
||||
* @function
|
||||
* @param {number} [x] - First cvalue.
|
||||
* @param {number} [y] - Second value.
|
||||
* @param {number} [z] - Third value.
|
||||
* @param {number} [x] - value X.
|
||||
* @param {number} [y] - value Y.
|
||||
* @param {number} [z] - value Z.
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
export function vec3(x, y, z) {
|
||||
export function vec3(x: number = 0, y: number = 0, z: number = 0): Vec3 {
|
||||
return new Vec3(x, y, z);
|
||||
}
|
||||
@ -1,7 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
import { frac } from "../math.js";
|
||||
import { Vec3 } from "./Vec3.js";
|
||||
import {Vec3} from "./Vec3";
|
||||
|
||||
//@ts-ignore
|
||||
import {frac} from "../math.js";
|
||||
|
||||
/**
|
||||
* Class represents a 4d vector.
|
||||
@ -12,30 +14,37 @@ import { Vec3 } from "./Vec3.js";
|
||||
* @param {number} [w] - Fourth value.
|
||||
*/
|
||||
export class Vec4 {
|
||||
constructor(x = 0.0, y = 0.0, z = 0.0, w = 0.0) {
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.x = x || 0.0;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.y = y || 0.0;
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
public x: number;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.z = z || 0.0;
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
public y: number;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.w = w || 0.0;
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
public z: number;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
public w: number;
|
||||
|
||||
|
||||
constructor(x: number = 0.0, y: number = 0.0, z: number = 0.0, w: number = 0.0) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,26 +52,26 @@ export class Vec4 {
|
||||
* @const
|
||||
* @type {Vec4}
|
||||
*/
|
||||
static get identity() {
|
||||
static get identity(): Vec4 {
|
||||
return new Vec4(0, 0, 0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates 4d vector from array.
|
||||
* @function
|
||||
* @param {Array.<number>} - (exactly 4 entries)
|
||||
* @param {Array.<number>} arr - Array of four values
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
static fromVec(arr) {
|
||||
static fromVec(arr: [number, number, number, number]): Vec4 {
|
||||
return new Vec4(arr[0], arr[1], arr[2], arr[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts to 3d vector, without fourth value.
|
||||
* Converts to Vec3, without fourth value.
|
||||
* @public
|
||||
* @returns {Vec3}
|
||||
*/
|
||||
toVec3() {
|
||||
public toVec3(): Vec3 {
|
||||
return new Vec3(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
@ -71,17 +80,17 @@ export class Vec4 {
|
||||
* @public
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
clone() {
|
||||
public clone(): Vec4 {
|
||||
return new Vec4(this.x, this.y, this.z, this.w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares with vector. Returns true if it equals another.
|
||||
* @public
|
||||
* @param {Vec4} p - Vector to compare.
|
||||
* @param {Vec4} v - Vector to compare.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
equal(v) {
|
||||
public equal(v: Vec4): boolean {
|
||||
return this.x === v.x && this.y === v.y && this.z === v.z && this.w === v.w;
|
||||
}
|
||||
|
||||
@ -90,7 +99,7 @@ export class Vec4 {
|
||||
* @param {Vec4} v - Vector to copy.
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
copy(v) {
|
||||
public copy(v: Vec4): Vec4 {
|
||||
this.x = v.x;
|
||||
this.y = v.y;
|
||||
this.z = v.z;
|
||||
@ -103,7 +112,7 @@ export class Vec4 {
|
||||
* @public
|
||||
* @returns {Array.<number>} - (exactly 4 entries)
|
||||
*/
|
||||
toArray() {
|
||||
public toArray(): [number, number, number, number] {
|
||||
return [this.x, this.y, this.z, this.w];
|
||||
}
|
||||
|
||||
@ -112,7 +121,7 @@ export class Vec4 {
|
||||
* @public
|
||||
* @returns {Array.<number>} - (exactly 4 entries)
|
||||
*/
|
||||
toArray3() {
|
||||
toArray3(): [number, number, number] {
|
||||
return [this.x, this.y, this.z];
|
||||
}
|
||||
|
||||
@ -125,7 +134,7 @@ export class Vec4 {
|
||||
* @param {number} w - Value W.
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
set(x, y, z, w) {
|
||||
public set(x: number, y: number, z: number, w: number): Vec4 {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
@ -136,10 +145,10 @@ export class Vec4 {
|
||||
/**
|
||||
* Adds vector to the current.
|
||||
* @public
|
||||
* @param {Vec4}
|
||||
* @param {Vec4} v - Vector to add.
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
addA(v) {
|
||||
public addA(v: Vec4): Vec4 {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
this.z += v.z;
|
||||
@ -153,7 +162,7 @@ export class Vec4 {
|
||||
* @param {Vec4} v - Subtract vector.
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
subA(v) {
|
||||
public subA(v: Vec4): Vec4 {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
this.z -= v.z;
|
||||
@ -167,7 +176,7 @@ export class Vec4 {
|
||||
* @param {number} scale - Scale value.
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
scale(scale) {
|
||||
public scale(scale: number): Vec4 {
|
||||
this.x *= scale;
|
||||
this.y *= scale;
|
||||
this.z *= scale;
|
||||
@ -176,16 +185,19 @@ export class Vec4 {
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes vector affinity. Thereby fourh component becomes to 1.0.
|
||||
* Makes vector affinity. Thereby fourth component becomes to 1.0.
|
||||
* @public
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
affinity() {
|
||||
var iw = 1 / this.w;
|
||||
public affinity(): Vec4 {
|
||||
|
||||
let iw = 1.0 / this.w;
|
||||
|
||||
this.x *= iw;
|
||||
this.y *= iw;
|
||||
this.z *= iw;
|
||||
this.w = 1.0;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -195,16 +207,16 @@ export class Vec4 {
|
||||
* @param {number} scale - Scale value.
|
||||
* @returns {Vec3}
|
||||
*/
|
||||
scaleTo(scale) {
|
||||
public scaleTo(scale: number): Vec4 {
|
||||
return new Vec4(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vector's edge function that returns vector where each component is 0.0 if it's smaller then edge and otherwise 1.0.
|
||||
* Vector's edge function that returns vector where each component is 0.0 if it's smaller than edge and otherwise 1.0.
|
||||
* @public
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
getStep(edge) {
|
||||
public getStep(edge: number): Vec4 {
|
||||
return new Vec4(
|
||||
this.x < edge ? 0.0 : 1.0,
|
||||
this.y < edge ? 0.0 : 1.0,
|
||||
@ -214,21 +226,22 @@ export class Vec4 {
|
||||
}
|
||||
|
||||
/**
|
||||
* The vector fract function returns the vector of fractional parts of each value, i.e. x minus floor(x).
|
||||
* The vector frac function returns the vector of fractional parts of each value, i.e. x minus floor(x).
|
||||
* @public
|
||||
* @param {Vec4} v - Input vector
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
getFrac(v) {
|
||||
public getFrac(v: Vec4): Vec4 {
|
||||
return new Vec4(frac(v.x), frac(v.y), frac(v.z), frac(v.w));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets vectors dot production.
|
||||
* @public
|
||||
* @param {math.Vec4} v - Another vector.
|
||||
* @param {Vec4} v - Another vector.
|
||||
* @returns {number} - Dot product.
|
||||
*/
|
||||
dot(v) {
|
||||
public dot(v: Vec4): number {
|
||||
return v.x * this.x + v.y * this.y + v.z * this.z + v.w * this.w;
|
||||
}
|
||||
|
||||
@ -237,7 +250,7 @@ export class Vec4 {
|
||||
* @public
|
||||
* @returns {boolean} -
|
||||
*/
|
||||
isZero() {
|
||||
public isZero(): boolean {
|
||||
return !(this.x || this.y || this.z || this.w);
|
||||
}
|
||||
}
|
||||
@ -245,12 +258,12 @@ export class Vec4 {
|
||||
/**
|
||||
* Vector 4d object creator.
|
||||
* @function
|
||||
* @param {number} [x] - First cvalue.
|
||||
* @param {number} [x] - First value.
|
||||
* @param {number} [y] - Second value.
|
||||
* @param {number} [z] - Third value.
|
||||
* @param {number} [w] - Fourth value.
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
export function vec4(x, y, z, w) {
|
||||
export function vec4(x: number = 0, y: number = 0, z: number = 0, w: number = 0): Vec4 {
|
||||
return new Vec4(x, y, z, w);
|
||||
}
|
||||
@ -1,8 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
//@ts-ignore
|
||||
import { Extent } from "./Extent.js";
|
||||
|
||||
import { Extent } from "./Extent";
|
||||
import { LonLat } from './LonLat';
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user