vislite 0.2.0 → 0.3.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +19 -1
- package/LICENSE +20 -20
- package/README.md +53 -53
- package/lib/Canvas/index.umd.js +91 -14
- package/lib/Canvas/index.umd.min.js +7 -3
- package/lib/Cardinal/index.umd.js +6 -2
- package/lib/Cardinal/index.umd.min.js +6 -2
- package/lib/Eoap/index.umd.js +6 -2
- package/lib/Eoap/index.umd.min.js +6 -2
- package/lib/Hermite/index.umd.js +6 -2
- package/lib/Hermite/index.umd.min.js +6 -2
- package/lib/Matrix4/index.umd.js +6 -2
- package/lib/Matrix4/index.umd.min.js +6 -2
- package/lib/Mercator/index.umd.js +6 -2
- package/lib/Mercator/index.umd.min.js +6 -2
- package/lib/OralCanvas/index.es.js +91 -14
- package/lib/OralCanvas/index.es.min.js +7 -3
- package/lib/OralWebGL/index.es.js +8 -2
- package/lib/OralWebGL/index.es.min.js +6 -2
- package/lib/SVG/index.umd.js +82 -62
- package/lib/SVG/index.umd.min.js +7 -3
- package/lib/WebGL/index.umd.js +6 -2
- package/lib/WebGL/index.umd.min.js +6 -2
- package/lib/animation/index.umd.js +6 -2
- package/lib/animation/index.umd.min.js +6 -2
- package/lib/getLoopColors/index.umd.js +6 -2
- package/lib/getLoopColors/index.umd.min.js +6 -2
- package/lib/index.umd.js +167 -74
- package/lib/index.umd.min.js +7 -3
- package/lib/rotate/index.umd.js +6 -2
- package/lib/rotate/index.umd.min.js +6 -2
- package/lib/ruler/index.umd.js +6 -2
- package/lib/ruler/index.umd.min.js +6 -2
- package/lib/viewHandler/index.umd.js +6 -2
- package/lib/viewHandler/index.umd.min.js +6 -2
- package/miniprogram/ui-canvas/index.json +4 -4
- package/miniprogram/ui-canvas/index.wxml +4 -4
- package/miniprogram/ui-canvas/index.wxss +5 -5
- package/package/Canvas/index.ts +1 -1
- package/package/Cardinal/index.ts +2 -2
- package/package/Eoap/index.ts +2 -2
- package/package/Hermite/index.ts +2 -2
- package/package/Matrix4/index.ts +2 -2
- package/package/OralCanvas/index.ts +1 -1
- package/package/OralWebGL/index.ts +1 -1
- package/package/SVG/index.ts +2 -2
- package/package/animation/index.ts +2 -2
- package/package/getLoopColors/index.ts +2 -2
- package/package/rotate/index.ts +2 -2
- package/package/ruler/index.ts +2 -2
- package/package.json +4 -4
- package/src/Matrix4/index.ts +76 -76
- package/src/Matrix4/move.ts +12 -12
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/scale.ts +11 -11
- package/src/Matrix4/transform.ts +64 -64
- package/src/animation.ts +99 -99
- package/src/common/canvas/arc.ts +50 -50
- package/src/common/canvas/config.ts +142 -61
- package/src/common/canvas/gradient.ts +29 -0
- package/src/common/canvas/index.ts +122 -82
- package/src/common/canvas/painter.ts +12 -0
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +173 -128
- package/src/common/svg/index.ts +315 -266
- package/src/common/svg/tool.ts +43 -43
- package/src/getLoopColors.ts +42 -42
- package/src/interpolation/Cardinal.ts +91 -91
- package/src/interpolation/Hermite.ts +65 -65
- package/src/rotate.ts +7 -7
- package/src/ruler.ts +99 -99
- package/types/Canvas.d.ts +282 -221
- package/types/CanvasConfig.d.ts +3 -3
- package/types/Cardinal.d.ts +13 -13
- package/types/Gradient.d.ts +15 -0
- package/types/Hermite.d.ts +18 -18
- package/types/Matrix4.d.ts +42 -42
- package/types/SVG.d.ts +210 -210
- package/types/animation.d.ts +6 -6
- package/types/getLoopColors.d.ts +2 -2
- package/types/rotate.d.ts +2 -2
- package/types/ruler.d.ts +2 -2
- package/uni-app/ui-canvas.vue +22 -46
package/lib/rotate/index.umd.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本版本系测试版本,请认真阅读下述说明再使用:
|
|
10
|
+
*
|
|
11
|
+
*【测试版本细则】
|
|
12
|
+
* alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
|
|
13
|
+
* beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
|
|
10
14
|
*/
|
|
11
15
|
(function (global, factory) {
|
|
12
16
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本版本系测试版本,请认真阅读下述说明再使用:
|
|
10
|
+
*
|
|
11
|
+
*【测试版本细则】
|
|
12
|
+
* alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
|
|
13
|
+
* beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
|
|
10
14
|
*/
|
|
11
15
|
var e,t;e=this,t=function(){"use strict";return function(e,t,n,o,i){var f=Math.cos(n),d=Math.sin(n);return[(o-e)*f-(i-t)*d+e,(o-e)*d+(i-t)*f+t]}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_rotate=t();
|
package/lib/ruler/index.umd.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本版本系测试版本,请认真阅读下述说明再使用:
|
|
10
|
+
*
|
|
11
|
+
*【测试版本细则】
|
|
12
|
+
* alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
|
|
13
|
+
* beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
|
|
10
14
|
*/
|
|
11
15
|
(function (global, factory) {
|
|
12
16
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本版本系测试版本,请认真阅读下述说明再使用:
|
|
10
|
+
*
|
|
11
|
+
*【测试版本细则】
|
|
12
|
+
* alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
|
|
13
|
+
* beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
|
|
10
14
|
*/
|
|
11
15
|
var e,r;e=this,r=function(){"use strict";return function(e,r,t){if(e<r){var f=r;r=e,e=f}else if(e==r)return[e];var n=function(e){for(var r=e<100&&e>-100?10:.1,t=-1,f=e;10==r?f>=-100&&f<=100:f<=-100||f>=100;)t+=1,f*=r;if(10==r)return Math.pow(10,t);for(var n="0.",o=1;o<t;o++)n+="0";return+(n+"1")}(e-r),o=Math.ceil((e-r)*n/t),i=(o={3:2,4:5,6:5,7:5,8:10,9:10,11:10,12:10,13:15,14:15,16:15,17:15,18:20,19:20,21:20,22:20,23:25,24:25,26:25,27:25}[o]||o)/n,u=Math.floor(r/i)*i,a=[];a.push(u);for(var l=1;a[a.length-1]<e;l++)a.push(u+i*l);return a}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_ruler=r();
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本版本系测试版本,请认真阅读下述说明再使用:
|
|
10
|
+
*
|
|
11
|
+
*【测试版本细则】
|
|
12
|
+
* alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
|
|
13
|
+
* beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
|
|
10
14
|
*/
|
|
11
15
|
(function (global, factory) {
|
|
12
16
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本版本系测试版本,请认真阅读下述说明再使用:
|
|
10
|
+
*
|
|
11
|
+
*【测试版本细则】
|
|
12
|
+
* alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
|
|
13
|
+
* beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
|
|
10
14
|
*/
|
|
11
15
|
var e,n;e=this,n=function(){"use strict";var e=function(e,n){var t=e.getBoundingClientRect();return{x:n.clientX-t.left,y:n.clientY-t.top}};return function(n){var t=document.getElementsByTagName("body")[0];t.addEventListener("keydown",(function(e){var t=function(e){return{37:"left",38:"up",39:"right",40:"down"}[e.keyCode||e.which]}(e);"up"==t?n({type:"lookUp",normal:[],value:.1}):"down"==t?n({type:"lookDown",normal:[],value:.1}):"left"==t?n({type:"lookLeft",normal:[],value:.1}):"right"==t&&n({type:"lookRight",normal:[],value:.1})}));var o=null,i=function(i){if(null!=o){var u=e(t,i),l=[u.x-o.x,u.y-o.y],a=[l[1],l[0],0];0==a[0]&&0==a[1]||(n({type:"rotate",normal:a,value:.01*(Math.abs(u.x-o.x)+Math.abs(u.y-o.y))}),o=u)}};t.addEventListener("mousedown",(function(n){o=e(t,n)})),t.addEventListener("mouseup",(function(e){o=null})),t.addEventListener("mousemove",(function(e){i(e)})),t.addEventListener("touchend",(function(e){o=null})),t.addEventListener("touchstart",(function(n){o=e(t,n)})),t.addEventListener("touchmove",(function(e){i(e.touches[0])}));var u=function(e){0!=e&&n({type:"scale",value:e<0?.899:1.101,normal:[]})};t.addEventListener("mousewheel",(function(e){u(e.wheelDelta)})),window.addEventListener&&window.addEventListener("DOMMouseScroll",(function(e){u(-1*e.detail)}),!1)}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_viewHandler=n();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{
|
|
2
|
-
"usingComponents": {},
|
|
3
|
-
"component": true
|
|
4
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"usingComponents": {},
|
|
3
|
+
"component": true
|
|
4
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<view>
|
|
2
|
-
<canvas type="2d" id="painter" style='width:{{width}}px;height:{{height}}px;' bindtouchstart="doitstart"></canvas>
|
|
3
|
-
<canvas type="2d" id="region" style='width:{{width}}px;height:{{height}}px;' class="region"></canvas>
|
|
4
|
-
</view>
|
|
1
|
+
<view>
|
|
2
|
+
<canvas type="2d" id="painter" style='width:{{width}}px;height:{{height}}px;' bindtouchstart="doitstart"></canvas>
|
|
3
|
+
<canvas type="2d" id="region" style='width:{{width}}px;height:{{height}}px;' class="region"></canvas>
|
|
4
|
+
</view>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* 辅助的区域不应该可以看见 */
|
|
2
|
-
.region {
|
|
3
|
-
position: fixed;
|
|
4
|
-
left: 50000px;
|
|
5
|
-
}
|
|
1
|
+
/* 辅助的区域不应该可以看见 */
|
|
2
|
+
.region {
|
|
3
|
+
position: fixed;
|
|
4
|
+
left: 50000px;
|
|
5
|
+
}
|
package/package/Canvas/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import Canvas from "../../src/Canvas"
|
|
1
|
+
import Canvas from "../../src/Canvas"
|
|
2
2
|
export default Canvas
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import Cardinal from "../../src/interpolation/Cardinal"
|
|
2
|
-
|
|
1
|
+
import Cardinal from "../../src/interpolation/Cardinal"
|
|
2
|
+
|
|
3
3
|
export default Cardinal
|
package/package/Eoap/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import Eoap from "../../src/Eoap"
|
|
2
|
-
|
|
1
|
+
import Eoap from "../../src/Eoap"
|
|
2
|
+
|
|
3
3
|
export default Eoap
|
package/package/Hermite/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import Hermite from "../../src/interpolation/Hermite"
|
|
2
|
-
|
|
1
|
+
import Hermite from "../../src/interpolation/Hermite"
|
|
2
|
+
|
|
3
3
|
export default Hermite
|
package/package/Matrix4/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import Matrix4 from "../../src/Matrix4/index"
|
|
2
|
-
|
|
1
|
+
import Matrix4 from "../../src/Matrix4/index"
|
|
2
|
+
|
|
3
3
|
export default Matrix4
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import _Canvas from "../../src/common/canvas/index"
|
|
1
|
+
import _Canvas from "../../src/common/canvas/index"
|
|
2
2
|
export default _Canvas
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import _WebGL from "../../src/common/webgl/index"
|
|
1
|
+
import _WebGL from "../../src/common/webgl/index"
|
|
2
2
|
export default _WebGL
|
package/package/SVG/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import SVG from "../../src/SVG"
|
|
2
|
-
|
|
1
|
+
import SVG from "../../src/SVG"
|
|
2
|
+
|
|
3
3
|
export default SVG
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import animation from "../../src/animation"
|
|
2
|
-
|
|
1
|
+
import animation from "../../src/animation"
|
|
2
|
+
|
|
3
3
|
export default animation
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import getLoopColors from "../../src/getLoopColors"
|
|
2
|
-
|
|
1
|
+
import getLoopColors from "../../src/getLoopColors"
|
|
2
|
+
|
|
3
3
|
export default getLoopColors
|
package/package/rotate/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import rotate from "../../src/rotate"
|
|
2
|
-
|
|
1
|
+
import rotate from "../../src/rotate"
|
|
2
|
+
|
|
3
3
|
export default rotate
|
package/package/ruler/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import ruler from "../../src/ruler"
|
|
2
|
-
|
|
1
|
+
import ruler from "../../src/ruler"
|
|
2
|
+
|
|
3
3
|
export default ruler
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vislite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha.0",
|
|
4
4
|
"description": "灵活、快速、简单的数据可视化交互式跨端前端库",
|
|
5
5
|
"main": "./lib/index.umd.min.js",
|
|
6
6
|
"typings": "./types/index.d.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "webpack serve --config ./build/webpack.config.js",
|
|
11
|
-
"build": "devby
|
|
11
|
+
"build": "devby --delete ./lib && node ./build/pkg.js",
|
|
12
12
|
"server": "devby -s 30000",
|
|
13
13
|
"test": "karma start ./build/karma.config.js"
|
|
14
14
|
},
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@rollup/plugin-typescript": "^11.1.0",
|
|
43
43
|
"@types/jasmine": "^4.3.1",
|
|
44
|
-
"devby": "^0.3.
|
|
44
|
+
"devby": "^0.3.1",
|
|
45
45
|
"karma": "^6.3.10",
|
|
46
46
|
"karma-chrome-launcher": "^3.1.0",
|
|
47
47
|
"karma-jasmine": "^4.0.1",
|
|
@@ -55,4 +55,4 @@
|
|
|
55
55
|
"webpack-cli": "^4.9.2",
|
|
56
56
|
"webpack-dev-server": "^4.7.4"
|
|
57
57
|
}
|
|
58
|
-
}
|
|
58
|
+
}
|
package/src/Matrix4/index.ts
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import Matrix4Type from '../../types/Matrix4'
|
|
2
|
-
|
|
3
|
-
// 两个4x4矩阵相乘
|
|
4
|
-
// 或矩阵和齐次坐标相乘
|
|
5
|
-
let _multiply = function (matrix4: number[], param: number[]) {
|
|
6
|
-
let newParam: number[] = []
|
|
7
|
-
for (let i = 0; i < 4; i++)
|
|
8
|
-
for (let j = 0; j < param.length / 4; j++)
|
|
9
|
-
newParam[j * 4 + i] =
|
|
10
|
-
matrix4[i] * param[j * 4] +
|
|
11
|
-
matrix4[i + 4] * param[j * 4 + 1] +
|
|
12
|
-
matrix4[i + 8] * param[j * 4 + 2] +
|
|
13
|
-
matrix4[i + 12] * param[j * 4 + 3]
|
|
14
|
-
return newParam
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
import _move from './move'
|
|
18
|
-
import _rotate from './rotate'
|
|
19
|
-
import _scale from './scale'
|
|
20
|
-
import _transform from './transform'
|
|
21
|
-
|
|
22
|
-
// 列主序存储的4x4矩阵
|
|
23
|
-
|
|
24
|
-
class Matrix4 implements Matrix4Type {
|
|
25
|
-
readonly name: string = 'Matrix4'
|
|
26
|
-
|
|
27
|
-
private __matrix4: number[]
|
|
28
|
-
|
|
29
|
-
constructor(initMatrix4: number[] = [
|
|
30
|
-
1, 0, 0, 0,
|
|
31
|
-
0, 1, 0, 0,
|
|
32
|
-
0, 0, 1, 0,
|
|
33
|
-
0, 0, 0, 1
|
|
34
|
-
]) {
|
|
35
|
-
this.__matrix4 = initMatrix4
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 移动
|
|
39
|
-
move(dis: number, a: number, b: number, c: number = 0) {
|
|
40
|
-
this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4)
|
|
41
|
-
return this
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 旋转
|
|
45
|
-
rotate(deg: number, a1: number, b1: number, c1?: number, a2?: number, b2?: number, c2?: number) {
|
|
46
|
-
let matrix4s = _transform(a1, b1, c1, a2, b2, c2)
|
|
47
|
-
this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4)
|
|
48
|
-
return this
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 缩放
|
|
52
|
-
scale(xTimes: number, yTimes: number, zTimes: number, cx: number = 0, cy: number = 0, cz: number = 0) {
|
|
53
|
-
this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4)
|
|
54
|
-
return this
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 乘法
|
|
58
|
-
// 可以传入一个矩阵(matrix4,flag)
|
|
59
|
-
multiply(newMatrix4: number[], flag: boolean = false) {
|
|
60
|
-
this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4)
|
|
61
|
-
return this
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 对一个坐标应用变换
|
|
65
|
-
// 齐次坐标(x,y,z,w)
|
|
66
|
-
use(x: number, y: number, z: number = 0, w: number = 1) {
|
|
67
|
-
// w为0表示点位于无穷远处,忽略
|
|
68
|
-
return _multiply(this.__matrix4, [x, y, z, w])
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 矩阵的值
|
|
72
|
-
value() {
|
|
73
|
-
return this.__matrix4
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
1
|
+
import Matrix4Type from '../../types/Matrix4'
|
|
2
|
+
|
|
3
|
+
// 两个4x4矩阵相乘
|
|
4
|
+
// 或矩阵和齐次坐标相乘
|
|
5
|
+
let _multiply = function (matrix4: number[], param: number[]) {
|
|
6
|
+
let newParam: number[] = []
|
|
7
|
+
for (let i = 0; i < 4; i++)
|
|
8
|
+
for (let j = 0; j < param.length / 4; j++)
|
|
9
|
+
newParam[j * 4 + i] =
|
|
10
|
+
matrix4[i] * param[j * 4] +
|
|
11
|
+
matrix4[i + 4] * param[j * 4 + 1] +
|
|
12
|
+
matrix4[i + 8] * param[j * 4 + 2] +
|
|
13
|
+
matrix4[i + 12] * param[j * 4 + 3]
|
|
14
|
+
return newParam
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
import _move from './move'
|
|
18
|
+
import _rotate from './rotate'
|
|
19
|
+
import _scale from './scale'
|
|
20
|
+
import _transform from './transform'
|
|
21
|
+
|
|
22
|
+
// 列主序存储的4x4矩阵
|
|
23
|
+
|
|
24
|
+
class Matrix4 implements Matrix4Type {
|
|
25
|
+
readonly name: string = 'Matrix4'
|
|
26
|
+
|
|
27
|
+
private __matrix4: number[]
|
|
28
|
+
|
|
29
|
+
constructor(initMatrix4: number[] = [
|
|
30
|
+
1, 0, 0, 0,
|
|
31
|
+
0, 1, 0, 0,
|
|
32
|
+
0, 0, 1, 0,
|
|
33
|
+
0, 0, 0, 1
|
|
34
|
+
]) {
|
|
35
|
+
this.__matrix4 = initMatrix4
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 移动
|
|
39
|
+
move(dis: number, a: number, b: number, c: number = 0) {
|
|
40
|
+
this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4)
|
|
41
|
+
return this
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 旋转
|
|
45
|
+
rotate(deg: number, a1: number, b1: number, c1?: number, a2?: number, b2?: number, c2?: number) {
|
|
46
|
+
let matrix4s = _transform(a1, b1, c1, a2, b2, c2)
|
|
47
|
+
this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4)
|
|
48
|
+
return this
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 缩放
|
|
52
|
+
scale(xTimes: number, yTimes: number, zTimes: number, cx: number = 0, cy: number = 0, cz: number = 0) {
|
|
53
|
+
this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4)
|
|
54
|
+
return this
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 乘法
|
|
58
|
+
// 可以传入一个矩阵(matrix4,flag)
|
|
59
|
+
multiply(newMatrix4: number[], flag: boolean = false) {
|
|
60
|
+
this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4)
|
|
61
|
+
return this
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 对一个坐标应用变换
|
|
65
|
+
// 齐次坐标(x,y,z,w)
|
|
66
|
+
use(x: number, y: number, z: number = 0, w: number = 1) {
|
|
67
|
+
// w为0表示点位于无穷远处,忽略
|
|
68
|
+
return _multiply(this.__matrix4, [x, y, z, w])
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 矩阵的值
|
|
72
|
+
value() {
|
|
73
|
+
return this.__matrix4
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
77
|
export default Matrix4
|
package/src/Matrix4/move.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 在(a,b,c)方向位移d
|
|
3
|
-
*/
|
|
4
|
-
export default function (d: number, a: number, b: number, c: number = 0) {
|
|
5
|
-
let sqrt = Math.sqrt(a * a + b * b + c * c)
|
|
6
|
-
return [
|
|
7
|
-
1, 0, 0, 0,
|
|
8
|
-
0, 1, 0, 0,
|
|
9
|
-
0, 0, 1, 0,
|
|
10
|
-
a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
|
|
11
|
-
]
|
|
12
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 在(a,b,c)方向位移d
|
|
3
|
+
*/
|
|
4
|
+
export default function (d: number, a: number, b: number, c: number = 0) {
|
|
5
|
+
let sqrt = Math.sqrt(a * a + b * b + c * c)
|
|
6
|
+
return [
|
|
7
|
+
1, 0, 0, 0,
|
|
8
|
+
0, 1, 0, 0,
|
|
9
|
+
0, 0, 1, 0,
|
|
10
|
+
a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
|
|
11
|
+
]
|
|
12
|
+
}
|
package/src/Matrix4/rotate.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 围绕0Z轴旋转
|
|
3
|
-
* 其它的旋转可以借助transform实现
|
|
4
|
-
* 旋转角度单位采用弧度制
|
|
5
|
-
*/
|
|
6
|
-
export default function (deg: number) {
|
|
7
|
-
let sin = Math.sin(deg),
|
|
8
|
-
cos = Math.cos(deg)
|
|
9
|
-
return [
|
|
10
|
-
cos, sin, 0, 0,
|
|
11
|
-
-sin, cos, 0, 0,
|
|
12
|
-
0, 0, 1, 0,
|
|
13
|
-
0, 0, 0, 1
|
|
14
|
-
]
|
|
15
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 围绕0Z轴旋转
|
|
3
|
+
* 其它的旋转可以借助transform实现
|
|
4
|
+
* 旋转角度单位采用弧度制
|
|
5
|
+
*/
|
|
6
|
+
export default function (deg: number) {
|
|
7
|
+
let sin = Math.sin(deg),
|
|
8
|
+
cos = Math.cos(deg)
|
|
9
|
+
return [
|
|
10
|
+
cos, sin, 0, 0,
|
|
11
|
+
-sin, cos, 0, 0,
|
|
12
|
+
0, 0, 1, 0,
|
|
13
|
+
0, 0, 0, 1
|
|
14
|
+
]
|
|
15
|
+
}
|
package/src/Matrix4/scale.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 围绕圆心x、y和z分别缩放xTimes, yTimes和zTimes倍
|
|
3
|
-
*/
|
|
4
|
-
export default function (xTimes: number, yTimes: number, zTimes: number, cx: number = 0, cy: number = 0, cz: number = 0) {
|
|
5
|
-
return [
|
|
6
|
-
xTimes, 0, 0, 0,
|
|
7
|
-
0, yTimes, 0, 0,
|
|
8
|
-
0, 0, zTimes, 0,
|
|
9
|
-
cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
|
|
10
|
-
]
|
|
11
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 围绕圆心x、y和z分别缩放xTimes, yTimes和zTimes倍
|
|
3
|
+
*/
|
|
4
|
+
export default function (xTimes: number, yTimes: number, zTimes: number, cx: number = 0, cy: number = 0, cz: number = 0) {
|
|
5
|
+
return [
|
|
6
|
+
xTimes, 0, 0, 0,
|
|
7
|
+
0, yTimes, 0, 0,
|
|
8
|
+
0, 0, zTimes, 0,
|
|
9
|
+
cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
|
|
10
|
+
]
|
|
11
|
+
}
|
package/src/Matrix4/transform.ts
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 针对任意射线(a1,b1,c1)->(a2,b2,c2)
|
|
3
|
-
* 计算出两个变换矩阵
|
|
4
|
-
* 分别为:任意射线变成OZ轴变换矩阵 + OZ轴变回原来的射线的变换矩阵
|
|
5
|
-
*/
|
|
6
|
-
export default function (a1: number, b1: number, c1: number, a2: number, b2: number, c2: number) {
|
|
7
|
-
|
|
8
|
-
if (typeof a1 === 'number' && typeof b1 === 'number') {
|
|
9
|
-
|
|
10
|
-
// 如果设置两个点
|
|
11
|
-
// 表示二维上围绕某个点旋转
|
|
12
|
-
if (typeof c1 !== 'number') {
|
|
13
|
-
c1 = 0
|
|
14
|
-
a2 = a1
|
|
15
|
-
b2 = b1
|
|
16
|
-
c2 = 1
|
|
17
|
-
}
|
|
18
|
-
// 只设置三个点(设置不足六个点都认为只设置了三个点)
|
|
19
|
-
// 表示围绕从原点出发的射线旋转
|
|
20
|
-
else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
|
|
21
|
-
a2 = a1
|
|
22
|
-
b2 = b1
|
|
23
|
-
c2 = c1
|
|
24
|
-
a1 = 0
|
|
25
|
-
b1 = 0
|
|
26
|
-
c1 = 0
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (a1 == a2 && b1 == b2 && c1 == c2) throw new Error('It\'s not a legitimate ray!')
|
|
30
|
-
|
|
31
|
-
let sqrt1 = Math.sqrt((a2 - a1) * (a2 - a1) + (b2 - b1) * (b2 - b1)),
|
|
32
|
-
cos1 = sqrt1 != 0 ? (b2 - b1) / sqrt1 : 1,
|
|
33
|
-
sin1 = sqrt1 != 0 ? (a2 - a1) / sqrt1 : 0,
|
|
34
|
-
|
|
35
|
-
b = (a2 - a1) * sin1 + (b2 - b1) * cos1,
|
|
36
|
-
c = c2 - c1,
|
|
37
|
-
|
|
38
|
-
sqrt2 = Math.sqrt(b * b + c * c),
|
|
39
|
-
cos2 = sqrt2 != 0 ? c / sqrt2 : 1,
|
|
40
|
-
sin2 = sqrt2 != 0 ? b / sqrt2 : 0
|
|
41
|
-
|
|
42
|
-
return [
|
|
43
|
-
|
|
44
|
-
// 任意射线变成OZ轴变换矩阵
|
|
45
|
-
[
|
|
46
|
-
cos1, cos2 * sin1, sin1 * sin2, 0,
|
|
47
|
-
-sin1, cos1 * cos2, cos1 * sin2, 0,
|
|
48
|
-
0, -sin2, cos2, 0,
|
|
49
|
-
b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
|
|
50
|
-
],
|
|
51
|
-
|
|
52
|
-
// OZ轴变回原来的射线的变换矩阵
|
|
53
|
-
[
|
|
54
|
-
cos1, -sin1, 0, 0,
|
|
55
|
-
cos2 * sin1, cos2 * cos1, -sin2, 0,
|
|
56
|
-
sin1 * sin2, cos1 * sin2, cos2, 0,
|
|
57
|
-
a1, b1, c1, 1
|
|
58
|
-
]
|
|
59
|
-
|
|
60
|
-
]
|
|
61
|
-
} else {
|
|
62
|
-
throw new Error('a1 and b1 is required!')
|
|
63
|
-
}
|
|
64
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 针对任意射线(a1,b1,c1)->(a2,b2,c2)
|
|
3
|
+
* 计算出两个变换矩阵
|
|
4
|
+
* 分别为:任意射线变成OZ轴变换矩阵 + OZ轴变回原来的射线的变换矩阵
|
|
5
|
+
*/
|
|
6
|
+
export default function (a1: number, b1: number, c1: number, a2: number, b2: number, c2: number) {
|
|
7
|
+
|
|
8
|
+
if (typeof a1 === 'number' && typeof b1 === 'number') {
|
|
9
|
+
|
|
10
|
+
// 如果设置两个点
|
|
11
|
+
// 表示二维上围绕某个点旋转
|
|
12
|
+
if (typeof c1 !== 'number') {
|
|
13
|
+
c1 = 0
|
|
14
|
+
a2 = a1
|
|
15
|
+
b2 = b1
|
|
16
|
+
c2 = 1
|
|
17
|
+
}
|
|
18
|
+
// 只设置三个点(设置不足六个点都认为只设置了三个点)
|
|
19
|
+
// 表示围绕从原点出发的射线旋转
|
|
20
|
+
else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
|
|
21
|
+
a2 = a1
|
|
22
|
+
b2 = b1
|
|
23
|
+
c2 = c1
|
|
24
|
+
a1 = 0
|
|
25
|
+
b1 = 0
|
|
26
|
+
c1 = 0
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (a1 == a2 && b1 == b2 && c1 == c2) throw new Error('It\'s not a legitimate ray!')
|
|
30
|
+
|
|
31
|
+
let sqrt1 = Math.sqrt((a2 - a1) * (a2 - a1) + (b2 - b1) * (b2 - b1)),
|
|
32
|
+
cos1 = sqrt1 != 0 ? (b2 - b1) / sqrt1 : 1,
|
|
33
|
+
sin1 = sqrt1 != 0 ? (a2 - a1) / sqrt1 : 0,
|
|
34
|
+
|
|
35
|
+
b = (a2 - a1) * sin1 + (b2 - b1) * cos1,
|
|
36
|
+
c = c2 - c1,
|
|
37
|
+
|
|
38
|
+
sqrt2 = Math.sqrt(b * b + c * c),
|
|
39
|
+
cos2 = sqrt2 != 0 ? c / sqrt2 : 1,
|
|
40
|
+
sin2 = sqrt2 != 0 ? b / sqrt2 : 0
|
|
41
|
+
|
|
42
|
+
return [
|
|
43
|
+
|
|
44
|
+
// 任意射线变成OZ轴变换矩阵
|
|
45
|
+
[
|
|
46
|
+
cos1, cos2 * sin1, sin1 * sin2, 0,
|
|
47
|
+
-sin1, cos1 * cos2, cos1 * sin2, 0,
|
|
48
|
+
0, -sin2, cos2, 0,
|
|
49
|
+
b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
|
|
50
|
+
],
|
|
51
|
+
|
|
52
|
+
// OZ轴变回原来的射线的变换矩阵
|
|
53
|
+
[
|
|
54
|
+
cos1, -sin1, 0, 0,
|
|
55
|
+
cos2 * sin1, cos2 * cos1, -sin2, 0,
|
|
56
|
+
sin1 * sin2, cos1 * sin2, cos2, 0,
|
|
57
|
+
a1, b1, c1, 1
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
]
|
|
61
|
+
} else {
|
|
62
|
+
throw new Error('a1 and b1 is required!')
|
|
63
|
+
}
|
|
64
|
+
}
|