vislite 0.6.0 → 0.7.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.
Files changed (118) hide show
  1. package/CHANGELOG +15 -1
  2. package/README.md +24 -5
  3. package/lib/Buffer/index.umd.js +2 -2
  4. package/lib/Buffer/index.umd.min.js +2 -2
  5. package/lib/Canvas/index.umd.js +4 -4
  6. package/lib/Canvas/index.umd.min.js +3 -3
  7. package/lib/Cardinal/index.umd.js +2 -2
  8. package/lib/Cardinal/index.umd.min.js +2 -2
  9. package/lib/Eoap/index.umd.js +2 -2
  10. package/lib/Eoap/index.umd.min.js +2 -2
  11. package/lib/Geometry/index.umd.js +69 -8
  12. package/lib/Geometry/index.umd.min.js +3 -3
  13. package/lib/Hermite/index.umd.js +2 -2
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +2 -2
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +2 -2
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/OralCanvas/index.es.js +3 -3
  20. package/lib/OralCanvas/index.es.min.js +3 -3
  21. package/lib/OralWebGL/index.es.js +21 -18
  22. package/lib/OralWebGL/index.es.min.js +3 -3
  23. package/lib/SVG/index.umd.js +2 -2
  24. package/lib/SVG/index.umd.min.js +2 -2
  25. package/lib/Shader/index.umd.js +3 -2
  26. package/lib/Shader/index.umd.min.js +3 -3
  27. package/lib/Texture/index.umd.js +2 -2
  28. package/lib/Texture/index.umd.min.js +2 -2
  29. package/lib/TreeLayout/index.umd.js +13 -11
  30. package/lib/TreeLayout/index.umd.min.js +3 -3
  31. package/lib/WebGL/index.umd.js +22 -19
  32. package/lib/WebGL/index.umd.min.js +3 -3
  33. package/lib/animation/index.umd.js +2 -2
  34. package/lib/animation/index.umd.min.js +2 -2
  35. package/lib/formatColor/index.umd.js +2 -2
  36. package/lib/formatColor/index.umd.min.js +2 -2
  37. package/lib/getLoopColors/index.umd.js +2 -2
  38. package/lib/getLoopColors/index.umd.min.js +2 -2
  39. package/lib/getWebGLContext/index.umd.js +4 -4
  40. package/lib/getWebGLContext/index.umd.min.js +3 -3
  41. package/lib/index.umd.js +104 -38
  42. package/lib/index.umd.min.js +3 -3
  43. package/lib/move/index.umd.js +2 -2
  44. package/lib/move/index.umd.min.js +2 -2
  45. package/lib/resizeObserver/index.umd.js +2 -2
  46. package/lib/resizeObserver/index.umd.min.js +2 -2
  47. package/lib/rotate/index.umd.js +2 -2
  48. package/lib/rotate/index.umd.min.js +2 -2
  49. package/lib/ruler/index.umd.js +4 -4
  50. package/lib/ruler/index.umd.min.js +3 -3
  51. package/lib/scale/index.umd.js +2 -2
  52. package/lib/scale/index.umd.min.js +2 -2
  53. package/lib/throttle/index.umd.js +2 -2
  54. package/lib/throttle/index.umd.min.js +2 -2
  55. package/lib/viewHandler/index.umd.js +2 -2
  56. package/lib/viewHandler/index.umd.min.js +2 -2
  57. package/package/TreeLayout/index.ts +2 -2
  58. package/package.json +1 -1
  59. package/src/Canvas.ts +1 -1
  60. package/src/Eoap.ts +66 -66
  61. package/src/Geometry.ts +57 -13
  62. package/src/Matrix4/index.ts +84 -84
  63. package/src/Matrix4/move.ts +12 -12
  64. package/src/Matrix4/rotate.ts +1 -1
  65. package/src/Matrix4/transform.ts +1 -1
  66. package/src/Mercator.ts +27 -27
  67. package/src/SVG.ts +24 -24
  68. package/src/WebGL.ts +1 -1
  69. package/src/animation.ts +98 -98
  70. package/src/common/assemble.ts +1 -1
  71. package/src/common/canvas/arc.ts +51 -51
  72. package/src/common/canvas/config.ts +158 -158
  73. package/src/common/canvas/gradient.ts +29 -29
  74. package/src/common/canvas/index.ts +2 -2
  75. package/src/common/canvas/painter.ts +2 -0
  76. package/src/common/geometry/prism-horizontal.ts +35 -35
  77. package/src/common/geometry/prism-vertical.ts +1 -1
  78. package/src/common/geometry/sphere-fragment.ts +40 -40
  79. package/src/common/geometry/tool/circle.ts +11 -11
  80. package/src/common/geometry/tool/rotateLine.ts +36 -0
  81. package/src/common/mergeOption.ts +6 -6
  82. package/src/common/setStyle.ts +1 -1
  83. package/src/common/svg/config.ts +10 -6
  84. package/src/common/svg/gradient.ts +63 -63
  85. package/src/common/svg/index.ts +5 -5
  86. package/src/common/svg/tool.ts +6 -6
  87. package/src/common/tree/toInnerTree.ts +8 -6
  88. package/src/common/tree/toPlainTree.ts +1 -1
  89. package/src/common/webgl/buffer.ts +1 -1
  90. package/src/common/webgl/doDraw.ts +16 -16
  91. package/src/common/webgl/getColorFactory.ts +26 -26
  92. package/src/common/webgl/getShader.ts +48 -48
  93. package/src/common/webgl/getTexture.ts +11 -11
  94. package/src/common/webgl/getWebGLContext.ts +3 -3
  95. package/src/common/webgl/index.ts +6 -4
  96. package/src/common/webgl/shader.ts +3 -3
  97. package/src/common/webgl/texture.ts +2 -2
  98. package/src/formatColor.ts +44 -44
  99. package/src/getLoopColors.ts +42 -42
  100. package/src/interpolation/Cardinal.ts +110 -110
  101. package/src/interpolation/Hermite.ts +65 -65
  102. package/src/layout/TreeLayout.ts +13 -11
  103. package/src/move.ts +7 -7
  104. package/src/resizeObserver.ts +2 -2
  105. package/src/rotate.ts +7 -7
  106. package/src/ruler.ts +10 -10
  107. package/src/throttle.ts +52 -52
  108. package/src/viewHandler.ts +4 -2
  109. package/types/Canvas.d.ts +1 -1
  110. package/types/CanvasOption.d.ts +8 -8
  111. package/types/CanvasOpts.d.ts +9 -9
  112. package/types/Geometry.d.ts +65 -40
  113. package/types/Matrix4.d.ts +47 -47
  114. package/types/SVGConfig.d.ts +79 -76
  115. package/types/TreeConfig.d.ts +36 -24
  116. package/uni-app/ui-canvas.vue +9 -31
  117. package/.editorconfig +0 -19
  118. package/.eslintrc.js +0 -26
@@ -1,158 +1,158 @@
1
- import type CanvasConfigType from "../../../types/CanvasConfig"
2
-
3
- import arc from "./arc"
4
-
5
- // 文字统一设置方法
6
- export const initText = function (
7
- painter: CanvasRenderingContext2D,
8
- config: CanvasConfigType,
9
- x: number,
10
- y: number,
11
- deg: number
12
- ) {
13
- painter.beginPath();
14
- painter.translate(x, y);
15
- painter.rotate(deg);
16
- painter.font =
17
- config.fontStyle +
18
- " " +
19
- config.fontWeight +
20
- " " +
21
- config.fontSize +
22
- "px " +
23
- config.fontFamily;
24
- return painter
25
- }
26
-
27
- // 画弧统一设置方法
28
- export const initArc = function (
29
- painter: CanvasRenderingContext2D,
30
- config: CanvasConfigType,
31
- cx: number,
32
- cy: number,
33
- r1: number,
34
- r2: number,
35
- beginDeg: number,
36
- deg: number
37
- ) {
38
- if (r1 > r2) {
39
- const temp = r1
40
- r1 = r2
41
- r2 = temp
42
- }
43
-
44
- beginDeg = beginDeg % (Math.PI * 2)
45
-
46
- // 当|deg|>=2π的时候都认为是一个圆环
47
- // 为什么不取2π比较,是怕部分浏览器浮点不精确
48
- if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
49
- deg = Math.PI * 2
50
- } else {
51
- deg = deg % (Math.PI * 2)
52
- }
53
-
54
- arc(
55
- beginDeg,
56
- deg,
57
- cx,
58
- cy,
59
- r1,
60
- r2,
61
- function (
62
- beginA: number,
63
- endA: number,
64
- begInnerX: number,
65
- begInnerY: number,
66
- begOuterX: number,
67
- begOuterY: number,
68
- endInnerX: number,
69
- endInnerY: number,
70
- endOuterX: number,
71
- endOuterY: number,
72
- r: number
73
- ) {
74
- if (r < 0) r = -r
75
- painter.beginPath()
76
- painter.moveTo(begInnerX, begInnerY)
77
- painter.arc(
78
- // (圆心x,圆心y,半径,开始角度,结束角度,true逆时针/false顺时针)
79
- cx,
80
- cy,
81
- r1,
82
- beginA,
83
- endA,
84
- false
85
- )
86
- // 结尾
87
- if (config.arcEndCap == "round")
88
- painter.arc(
89
- (endInnerX + endOuterX) * 0.5,
90
- (endInnerY + endOuterY) * 0.5,
91
- r,
92
- endA - Math.PI,
93
- endA,
94
- true
95
- )
96
- else if (config.arcEndCap == "-round")
97
- painter.arc(
98
- (endInnerX + endOuterX) * 0.5,
99
- (endInnerY + endOuterY) * 0.5,
100
- r,
101
- endA - Math.PI,
102
- endA,
103
- false
104
- )
105
- else painter.lineTo(endOuterX, endOuterY)
106
-
107
- painter.arc(cx, cy, r2, endA, beginA, true)
108
- // 开头
109
- if (config.arcStartCap == "round")
110
- painter.arc(
111
- (begInnerX + begOuterX) * 0.5,
112
- (begInnerY + begOuterY) * 0.5,
113
- r,
114
- beginA,
115
- beginA - Math.PI,
116
- true
117
- )
118
- else if (config.arcStartCap == "-round")
119
- painter.arc(
120
- (begInnerX + begOuterX) * 0.5,
121
- (begInnerY + begOuterY) * 0.5,
122
- r,
123
- beginA,
124
- beginA - Math.PI,
125
- false
126
- )
127
- else painter.lineTo(begInnerX, begInnerY)
128
- }
129
- )
130
- if (config.arcStartCap == "butt") painter.closePath()
131
- return painter
132
- }
133
-
134
- // 画圆统一设置方法
135
- export const initCircle = function (
136
- painter: CanvasRenderingContext2D,
137
- cx: number,
138
- cy: number,
139
- r: number
140
- ) {
141
- painter.beginPath()
142
- painter.moveTo(cx + r, cy)
143
- painter.arc(cx, cy, r, 0, Math.PI * 2)
144
- return painter
145
- };
146
-
147
- // 画矩形统一设置方法
148
- export const initRect = function (
149
- painter: CanvasRenderingContext2D,
150
- x: number,
151
- y: number,
152
- width: number,
153
- height: number
154
- ) {
155
- painter.beginPath()
156
- painter.rect(x, y, width, height)
157
- return painter
158
- }
1
+ import type CanvasConfigType from "../../../types/CanvasConfig"
2
+
3
+ import arc from "./arc"
4
+
5
+ // 文字统一设置方法
6
+ export const initText = function (
7
+ painter: CanvasRenderingContext2D,
8
+ config: CanvasConfigType,
9
+ x: number,
10
+ y: number,
11
+ deg: number
12
+ ) {
13
+ painter.beginPath();
14
+ painter.translate(x, y);
15
+ painter.rotate(deg);
16
+ painter.font =
17
+ config.fontStyle +
18
+ " " +
19
+ config.fontWeight +
20
+ " " +
21
+ config.fontSize +
22
+ "px " +
23
+ config.fontFamily;
24
+ return painter
25
+ }
26
+
27
+ // 画弧统一设置方法
28
+ export const initArc = function (
29
+ painter: CanvasRenderingContext2D,
30
+ config: CanvasConfigType,
31
+ cx: number,
32
+ cy: number,
33
+ r1: number,
34
+ r2: number,
35
+ beginDeg: number,
36
+ deg: number
37
+ ) {
38
+ if (r1 > r2) {
39
+ const temp = r1
40
+ r1 = r2
41
+ r2 = temp
42
+ }
43
+
44
+ beginDeg = beginDeg % (Math.PI * 2)
45
+
46
+ // 当|deg|>=2π的时候都认为是一个圆环
47
+ // 为什么不取2π比较,是怕部分浏览器浮点不精确
48
+ if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
49
+ deg = Math.PI * 2
50
+ } else {
51
+ deg = deg % (Math.PI * 2)
52
+ }
53
+
54
+ arc(
55
+ beginDeg,
56
+ deg,
57
+ cx,
58
+ cy,
59
+ r1,
60
+ r2,
61
+ function (
62
+ beginA: number,
63
+ endA: number,
64
+ begInnerX: number,
65
+ begInnerY: number,
66
+ begOuterX: number,
67
+ begOuterY: number,
68
+ endInnerX: number,
69
+ endInnerY: number,
70
+ endOuterX: number,
71
+ endOuterY: number,
72
+ r: number
73
+ ) {
74
+ if (r < 0) r = -r
75
+ painter.beginPath()
76
+ painter.moveTo(begInnerX, begInnerY)
77
+ painter.arc(
78
+ // (圆心x,圆心y,半径,开始角度,结束角度,true逆时针/false顺时针)
79
+ cx,
80
+ cy,
81
+ r1,
82
+ beginA,
83
+ endA,
84
+ false
85
+ )
86
+ // 结尾
87
+ if (config.arcEndCap == "round")
88
+ painter.arc(
89
+ (endInnerX + endOuterX) * 0.5,
90
+ (endInnerY + endOuterY) * 0.5,
91
+ r,
92
+ endA - Math.PI,
93
+ endA,
94
+ true
95
+ )
96
+ else if (config.arcEndCap == "-round")
97
+ painter.arc(
98
+ (endInnerX + endOuterX) * 0.5,
99
+ (endInnerY + endOuterY) * 0.5,
100
+ r,
101
+ endA - Math.PI,
102
+ endA,
103
+ false
104
+ )
105
+ else painter.lineTo(endOuterX, endOuterY)
106
+
107
+ painter.arc(cx, cy, r2, endA, beginA, true)
108
+ // 开头
109
+ if (config.arcStartCap == "round")
110
+ painter.arc(
111
+ (begInnerX + begOuterX) * 0.5,
112
+ (begInnerY + begOuterY) * 0.5,
113
+ r,
114
+ beginA,
115
+ beginA - Math.PI,
116
+ true
117
+ )
118
+ else if (config.arcStartCap == "-round")
119
+ painter.arc(
120
+ (begInnerX + begOuterX) * 0.5,
121
+ (begInnerY + begOuterY) * 0.5,
122
+ r,
123
+ beginA,
124
+ beginA - Math.PI,
125
+ false
126
+ )
127
+ else painter.lineTo(begInnerX, begInnerY)
128
+ }
129
+ )
130
+ if (config.arcStartCap == "butt") painter.closePath()
131
+ return painter
132
+ }
133
+
134
+ // 画圆统一设置方法
135
+ export const initCircle = function (
136
+ painter: CanvasRenderingContext2D,
137
+ cx: number,
138
+ cy: number,
139
+ r: number
140
+ ) {
141
+ painter.beginPath()
142
+ painter.moveTo(cx + r, cy)
143
+ painter.arc(cx, cy, r, 0, Math.PI * 2)
144
+ return painter
145
+ };
146
+
147
+ // 画矩形统一设置方法
148
+ export const initRect = function (
149
+ painter: CanvasRenderingContext2D,
150
+ x: number,
151
+ y: number,
152
+ width: number,
153
+ height: number
154
+ ) {
155
+ painter.beginPath()
156
+ painter.rect(x, y, width, height)
157
+ return painter
158
+ }
@@ -1,29 +1,29 @@
1
- // 线性渐变
2
- export const linearGradient = function (painter: CanvasRenderingContext2D, x0: number, y0: number, x1: number, y1: number) {
3
- const gradient = painter.createLinearGradient(x0, y0, x1, y1)
4
- const enhanceGradient = {
5
- "value": function () {
6
- return gradient
7
- },
8
- "setColor": function (stop: number, color: string) {
9
- gradient.addColorStop(stop, color)
10
- return enhanceGradient
11
- }
12
- };
13
- return enhanceGradient
14
- }
15
-
16
- // 环形渐变
17
- export const radialGradient = function (painter: CanvasRenderingContext2D, cx: number, cy: number, r: number) {
18
- const gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r)
19
- const enhanceGradient = {
20
- "value": function () {
21
- return gradient
22
- },
23
- "setColor": function (stop: number, color: string) {
24
- gradient.addColorStop(stop, color)
25
- return enhanceGradient
26
- }
27
- }
28
- return enhanceGradient
29
- }
1
+ // 线性渐变
2
+ export const linearGradient = function (painter: CanvasRenderingContext2D, x0: number, y0: number, x1: number, y1: number) {
3
+ const gradient = painter.createLinearGradient(x0, y0, x1, y1)
4
+ const enhanceGradient = {
5
+ "value": function () {
6
+ return gradient
7
+ },
8
+ "setColor": function (stop: number, color: string) {
9
+ gradient.addColorStop(stop, color)
10
+ return enhanceGradient
11
+ }
12
+ };
13
+ return enhanceGradient
14
+ }
15
+
16
+ // 环形渐变
17
+ export const radialGradient = function (painter: CanvasRenderingContext2D, cx: number, cy: number, r: number) {
18
+ const gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r)
19
+ const enhanceGradient = {
20
+ "value": function () {
21
+ return gradient
22
+ },
23
+ "setColor": function (stop: number, color: string) {
24
+ gradient.addColorStop(stop, color)
25
+ return enhanceGradient
26
+ }
27
+ }
28
+ return enhanceGradient
29
+ }
@@ -25,13 +25,13 @@ class Canvas extends PainterRender {
25
25
  // 2023年7月6日 于南京
26
26
  private __regionAssemble = assemble(0, 255, 10, 3)
27
27
 
28
- constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement, opts: CanvasOptsType = {}) {
28
+ constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null, opts: CanvasOptsType = {}) {
29
29
  super(
30
30
  ViewCanvas,
31
31
  opts,
32
32
  RegionCanvas ? new PainterRender(RegionCanvas, {
33
33
  willReadFrequently: true,
34
- }) : null, true
34
+ }) : undefined, true
35
35
  )
36
36
 
37
37
  this.setRegion("")
@@ -33,6 +33,8 @@ class Painter {
33
33
 
34
34
  // 圆弧结束端闭合方式,和上一个类似
35
35
  "arcEndCap": <arcCapType>'butt'
36
+ } as {
37
+ [key: string]: any
36
38
  }
37
39
 
38
40
  private __initConfig = {
@@ -1,35 +1,35 @@
1
- import rotate from '../../rotate'
2
-
3
- // 棱柱水平部分
4
-
5
- export default function (normal: boolean, x: number, y: number, z: number, radius: number, num: number, d: number) {
6
-
7
- let beginX: number, beginZ: number
8
- if (num == 4) {
9
- const temp = radius / 1.414
10
- beginX = x + temp
11
- beginZ = z + temp
12
-
13
- } else {
14
- beginX = x + radius
15
- beginZ = z
16
- }
17
-
18
- let point = [beginX, beginZ]
19
- const points = []
20
- const deg = Math.PI * 2 / num
21
- for (let i = 0; i < num; i++) {
22
-
23
- points.push(x, y, z)
24
- if (normal) points.push(0, d, 0)
25
-
26
- points.push(point[0], y, point[1])
27
- if (normal) points.push(0, d, 0)
28
-
29
- point = rotate(x, z, deg * (i + 1), beginX, beginZ)
30
- points.push(point[0], y, point[1])
31
- if (normal) points.push(0, d, 0)
32
- }
33
-
34
- return points
35
- }
1
+ import rotate from '../../rotate'
2
+
3
+ // 棱柱水平部分
4
+
5
+ export default function (normal: boolean, x: number, y: number, z: number, radius: number, num: number, d: number) {
6
+
7
+ let beginX: number, beginZ: number
8
+ if (num == 4) {
9
+ const temp = radius / 1.414
10
+ beginX = x + temp
11
+ beginZ = z + temp
12
+
13
+ } else {
14
+ beginX = x + radius
15
+ beginZ = z
16
+ }
17
+
18
+ let point = [beginX, beginZ]
19
+ const points = []
20
+ const deg = Math.PI * 2 / num
21
+ for (let i = 0; i < num; i++) {
22
+
23
+ points.push(x, y, z)
24
+ if (normal) points.push(0, d, 0)
25
+
26
+ points.push(point[0], y, point[1])
27
+ if (normal) points.push(0, d, 0)
28
+
29
+ point = rotate(x, z, deg * (i + 1), beginX, beginZ)
30
+ points.push(point[0], y, point[1])
31
+ if (normal) points.push(0, d, 0)
32
+ }
33
+
34
+ return points
35
+ }
@@ -14,7 +14,7 @@ export default function (normal: boolean, x: number, y: number, z: number, radiu
14
14
 
15
15
  const deg = Math.PI * 2 / num, degHalf = Math.PI * 2 / (num * 2)
16
16
 
17
- let endPosition: [number, number], normalPosition = []
17
+ let endPosition: [number, number], normalPosition: [number, number, number] | [] = []
18
18
  for (let i = 0; i < num; i++) {
19
19
 
20
20
  endPosition = rotate(x, z, deg, ...beginPosition)
@@ -1,40 +1,40 @@
1
- import rotate from '../../rotate'
2
-
3
- // 球体中的一瓣子
4
-
5
- export default function (normal: boolean, cx: number, cy: number, cz: number, radius: number, num: number, index: number) {
6
- const points = [cx, cy + radius, cz], deg = Math.PI * 2 / num
7
- let point: [number, number]
8
-
9
- if (normal) points.push(0, radius, 0)
10
-
11
- const copy2 = () => {
12
- points.push(...points.slice(points.length - (normal ? 12 : 6)))
13
- }
14
-
15
- for (let i = 1; i < num * 0.5; i++) {
16
- point = rotate(cx, cy, deg * i, cx, cy + radius)
17
-
18
- if (i > 1) copy2()
19
-
20
- // 第一个点
21
- const point1 = rotate(cx, cz, deg * index, point[0], cz)
22
- points.push(point1[0], point[1], point1[1])
23
-
24
- if (normal) points.push(point1[0] - cx, point[1] - cy, point1[1] - cz)
25
-
26
- if (i > 1) copy2()
27
-
28
- // 下一个点
29
- const point2 = rotate(cx, cz, deg * (index + 1), point[0], cz)
30
- points.push(point2[0], point[1], point2[1])
31
-
32
- if (normal) points.push(point2[0] - cx, point2[1] - cy, point2[1] - cz)
33
- }
34
- copy2()
35
- points.push(cx, cy - radius, cz)
36
-
37
- if (normal) points.push(0, - radius, 0)
38
-
39
- return points
40
- }
1
+ import rotate from '../../rotate'
2
+
3
+ // 球体中的一瓣子
4
+
5
+ export default function (normal: boolean, cx: number, cy: number, cz: number, radius: number, num: number, index: number) {
6
+ const points = [cx, cy + radius, cz], deg = Math.PI * 2 / num
7
+ let point: [number, number]
8
+
9
+ if (normal) points.push(0, radius, 0)
10
+
11
+ const copy2 = () => {
12
+ points.push(...points.slice(points.length - (normal ? 12 : 6)))
13
+ }
14
+
15
+ for (let i = 1; i < num * 0.5; i++) {
16
+ point = rotate(cx, cy, deg * i, cx, cy + radius)
17
+
18
+ if (i > 1) copy2()
19
+
20
+ // 第一个点
21
+ const point1 = rotate(cx, cz, deg * index, point[0], cz)
22
+ points.push(point1[0], point[1], point1[1])
23
+
24
+ if (normal) points.push(point1[0] - cx, point[1] - cy, point1[1] - cz)
25
+
26
+ if (i > 1) copy2()
27
+
28
+ // 下一个点
29
+ const point2 = rotate(cx, cz, deg * (index + 1), point[0], cz)
30
+ points.push(point2[0], point[1], point2[1])
31
+
32
+ if (normal) points.push(point2[0] - cx, point2[1] - cy, point2[1] - cz)
33
+ }
34
+ copy2()
35
+ points.push(cx, cy - radius, cz)
36
+
37
+ if (normal) points.push(0, - radius, 0)
38
+
39
+ return points
40
+ }
@@ -1,12 +1,12 @@
1
- // 计算切割份数
2
- export const splitNum = function (precision: number, radius: number) {
3
-
4
- // 根据切割弧度得出切割块数目
5
- const num = Math.ceil(Math.PI * 2 /
6
-
7
- // 为了满足最小精度而得出的切割弧度
8
- Math.asin(precision / radius) * 2)
9
-
10
- return (isNaN(num) || num < 12) ? 12 : num
11
-
1
+ // 计算切割份数
2
+ export const splitNum = function (precision: number, radius: number) {
3
+
4
+ // 根据切割弧度得出切割块数目
5
+ const num = Math.ceil(Math.PI * 2 /
6
+
7
+ // 为了满足最小精度而得出的切割弧度
8
+ Math.asin(precision / radius) * 2)
9
+
10
+ return (isNaN(num) || num < 12) ? 12 : num
11
+
12
12
  }
@@ -0,0 +1,36 @@
1
+ export default function (x: number, y: number, z: number, x2: number, y2: number, z2: number) {
2
+ return (x0: number, y0: number, z0: number, isNormal: boolean) => {
3
+ let sin: number, cos: number, temp: Array<number>
4
+
5
+ // 第一步:归零化
6
+ let _x0 = x0 - (isNormal ? 0 : x), _y0 = y0 - (isNormal ? 0 : y), _z0 = z0 - (isNormal ? 0 : z) // 法向量起点本来就是原点
7
+ const _x2 = x2 - x, _y2 = y2 - y, _z2 = z2 - z
8
+
9
+ // 第二步:围绕OZ轴旋转
10
+
11
+ const __d = Math.sqrt(_x2 * _x2 + _z2 * _z2)
12
+ cos = _x2 / __d
13
+ sin = _z2 / __d
14
+
15
+ const _x2N = _z2 * sin + _x2 * cos
16
+
17
+ const d = Math.sqrt(_y2 * _y2 + _x2N * _x2N)
18
+ cos = _y2 / d
19
+ sin = _x2N / d
20
+
21
+ temp = [_y0, _x0]
22
+ _y0 = temp[0] * cos - temp[1] * sin
23
+ _x0 = temp[0] * sin + temp[1] * cos
24
+
25
+ // 第三步:围绕0Y轴旋转
26
+ cos = _x2 / __d
27
+ sin = _z2 / __d
28
+
29
+ temp = [_x0, _z0]
30
+ _x0 = temp[0] * cos - temp[1] * sin
31
+ _z0 = temp[0] * sin + temp[1] * cos
32
+
33
+ // 第四步:去零化(直接返回)
34
+ return [_x0 + (isNormal ? 0 : x), _y0 + (isNormal ? 0 : y), _z0 + (isNormal ? 0 : z)]
35
+ }
36
+ }
@@ -1,7 +1,7 @@
1
- export default function (option: any, defaultOption: any) {
2
- for (const key in option) {
3
- defaultOption[key] = option[key]
4
- }
5
-
6
- return defaultOption
1
+ export default function (option: any, defaultOption: any) {
2
+ for (const key in option) {
3
+ defaultOption[key] = option[key]
4
+ }
5
+
6
+ return defaultOption
7
7
  }
@@ -1,6 +1,6 @@
1
1
  // 修改样式
2
2
  export default function (el: HTMLElement | SVGElement, styles: any) {
3
3
  for (const key in styles) {
4
- el.style[key] = styles[key]
4
+ el.style[key as any] = styles[key]
5
5
  }
6
6
  }