@logicflow/core 2.2.0 → 2.2.1

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 (236) hide show
  1. package/dist/index.css +3 -2
  2. package/dist/index.min.js +1 -1
  3. package/dist/index.min.js.map +1 -1
  4. package/es/LogicFlow.d.ts +9 -0
  5. package/es/LogicFlow.js +0 -1
  6. package/es/constant/index.d.ts +1 -1
  7. package/es/constant/index.js +1 -1
  8. package/es/constant/theme.d.ts +136 -0
  9. package/es/constant/theme.js +680 -0
  10. package/es/index.css +3 -2
  11. package/es/model/GraphModel.d.ts +10 -2
  12. package/es/model/GraphModel.js +48 -14
  13. package/es/model/TransformModel.js +9 -9
  14. package/es/model/edge/BaseEdgeModel.js +7 -2
  15. package/es/model/edge/PolylineEdgeModel.d.ts +7 -0
  16. package/es/model/edge/PolylineEdgeModel.js +136 -7
  17. package/es/model/node/BaseNodeModel.d.ts +12 -1
  18. package/es/model/node/BaseNodeModel.js +9 -2
  19. package/es/model/node/HtmlNodeModel.d.ts +12 -0
  20. package/es/model/node/HtmlNodeModel.js +19 -0
  21. package/es/model/node/PolygonNodeModel.js +3 -3
  22. package/es/options.d.ts +4 -2
  23. package/es/style/index.css +3 -2
  24. package/es/style/index.less +3 -2
  25. package/es/style/raw.d.ts +1 -1
  26. package/es/style/raw.js +1 -1
  27. package/es/tool/MultipleSelectTool.js +10 -5
  28. package/es/util/drag.js +0 -1
  29. package/es/util/edge.d.ts +40 -1
  30. package/es/util/edge.js +43 -9
  31. package/es/util/geometry.d.ts +8 -0
  32. package/es/util/geometry.js +79 -0
  33. package/es/util/theme.d.ts +2 -65
  34. package/es/util/theme.js +4 -281
  35. package/es/view/Anchor.d.ts +1 -0
  36. package/es/view/Anchor.js +24 -21
  37. package/es/view/Control.d.ts +5 -0
  38. package/es/view/Control.js +44 -57
  39. package/es/view/edge/BaseEdge.js +9 -0
  40. package/es/view/edge/PolylineEdge.js +13 -2
  41. package/es/view/node/BaseNode.d.ts +1 -0
  42. package/es/view/node/BaseNode.js +23 -11
  43. package/es/view/node/HtmlNode.js +2 -4
  44. package/es/view/overlay/CanvasOverlay.js +5 -2
  45. package/es/view/overlay/Grid.d.ts +12 -1
  46. package/es/view/overlay/Grid.js +85 -23
  47. package/es/view/overlay/OutlineOverlay.d.ts +1 -0
  48. package/es/view/overlay/OutlineOverlay.js +18 -17
  49. package/es/view/overlay/gridConfig.d.ts +46 -0
  50. package/es/view/overlay/gridConfig.js +99 -0
  51. package/es/view/shape/Polygon.d.ts +0 -7
  52. package/es/view/shape/Polygon.js +12 -43
  53. package/lib/LogicFlow.d.ts +9 -0
  54. package/lib/LogicFlow.js +0 -1
  55. package/lib/constant/index.d.ts +1 -1
  56. package/lib/constant/index.js +16 -2
  57. package/lib/constant/theme.d.ts +136 -0
  58. package/lib/constant/theme.js +683 -0
  59. package/lib/index.css +3 -2
  60. package/lib/model/GraphModel.d.ts +10 -2
  61. package/lib/model/GraphModel.js +49 -15
  62. package/lib/model/TransformModel.js +9 -9
  63. package/lib/model/edge/BaseEdgeModel.js +7 -2
  64. package/lib/model/edge/PolylineEdgeModel.d.ts +7 -0
  65. package/lib/model/edge/PolylineEdgeModel.js +136 -7
  66. package/lib/model/node/BaseNodeModel.d.ts +12 -1
  67. package/lib/model/node/BaseNodeModel.js +9 -2
  68. package/lib/model/node/HtmlNodeModel.d.ts +12 -0
  69. package/lib/model/node/HtmlNodeModel.js +19 -0
  70. package/lib/model/node/PolygonNodeModel.js +3 -3
  71. package/lib/options.d.ts +4 -2
  72. package/lib/style/index.css +3 -2
  73. package/lib/style/index.less +3 -2
  74. package/lib/style/raw.d.ts +1 -1
  75. package/lib/style/raw.js +1 -1
  76. package/lib/tool/MultipleSelectTool.js +10 -5
  77. package/lib/util/drag.js +0 -1
  78. package/lib/util/edge.d.ts +40 -1
  79. package/lib/util/edge.js +43 -9
  80. package/lib/util/geometry.d.ts +8 -0
  81. package/lib/util/geometry.js +81 -1
  82. package/lib/util/theme.d.ts +2 -65
  83. package/lib/util/theme.js +15 -292
  84. package/lib/view/Anchor.d.ts +1 -0
  85. package/lib/view/Anchor.js +24 -21
  86. package/lib/view/Control.d.ts +5 -0
  87. package/lib/view/Control.js +44 -57
  88. package/lib/view/edge/BaseEdge.js +9 -0
  89. package/lib/view/edge/PolylineEdge.js +13 -2
  90. package/lib/view/node/BaseNode.d.ts +1 -0
  91. package/lib/view/node/BaseNode.js +22 -10
  92. package/lib/view/node/HtmlNode.js +1 -3
  93. package/lib/view/overlay/CanvasOverlay.js +5 -2
  94. package/lib/view/overlay/Grid.d.ts +12 -1
  95. package/lib/view/overlay/Grid.js +83 -21
  96. package/lib/view/overlay/OutlineOverlay.d.ts +1 -0
  97. package/lib/view/overlay/OutlineOverlay.js +18 -17
  98. package/lib/view/overlay/gridConfig.d.ts +46 -0
  99. package/lib/view/overlay/gridConfig.js +104 -0
  100. package/lib/view/shape/Polygon.d.ts +0 -7
  101. package/lib/view/shape/Polygon.js +13 -45
  102. package/package.json +6 -1
  103. package/.turbo/turbo-build$colon$dev.log +0 -10
  104. package/.turbo/turbo-build.log +0 -33
  105. package/CHANGELOG.md +0 -1849
  106. package/__tests__/algorithm/egde.test.ts +0 -131
  107. package/__tests__/algorithm/index.test.ts +0 -74
  108. package/__tests__/algorithm/outline.test.ts +0 -43
  109. package/__tests__/bugs/1545-spec.test.ts +0 -42
  110. package/__tests__/event/event.test.ts +0 -22
  111. package/__tests__/history/history.test.ts +0 -28
  112. package/__tests__/logicflow.test.ts +0 -575
  113. package/__tests__/model/graphmodel.test.ts +0 -87
  114. package/__tests__/util/compatible.test.ts +0 -48
  115. package/__tests__/util/edge.test.ts +0 -224
  116. package/__tests__/util/geometry.test.ts +0 -14
  117. package/__tests__/util/graph.test.ts +0 -16
  118. package/__tests__/util/matrix.test.ts +0 -41
  119. package/__tests__/util/node.test.ts +0 -68
  120. package/__tests__/util/sampling.test.ts +0 -12
  121. package/__tests__/util/vector.test.ts +0 -50
  122. package/__tests__/util/zIndex.test.ts +0 -10
  123. package/src/LogicFlow.tsx +0 -2008
  124. package/src/algorithm/edge.ts +0 -67
  125. package/src/algorithm/index.ts +0 -70
  126. package/src/algorithm/outline.ts +0 -77
  127. package/src/algorithm/rotate.ts +0 -55
  128. package/src/common/drag.ts +0 -219
  129. package/src/common/history.ts +0 -108
  130. package/src/common/index.ts +0 -6
  131. package/src/common/keyboard.ts +0 -108
  132. package/src/common/matrix.ts +0 -122
  133. package/src/common/vector.ts +0 -93
  134. package/src/constant/index.ts +0 -179
  135. package/src/event/event.md +0 -66
  136. package/src/event/eventArgs.ts +0 -643
  137. package/src/event/eventEmitter.ts +0 -156
  138. package/src/history/index.ts +0 -119
  139. package/src/index.less +0 -1
  140. package/src/index.ts +0 -26
  141. package/src/keyboard/index.ts +0 -112
  142. package/src/keyboard/shortcut.ts +0 -200
  143. package/src/model/BaseModel.ts +0 -250
  144. package/src/model/EditConfigModel.ts +0 -334
  145. package/src/model/GraphModel.ts +0 -1788
  146. package/src/model/NestedTransformModel.ts +0 -121
  147. package/src/model/SnaplineModel.ts +0 -256
  148. package/src/model/TransformModel.ts +0 -258
  149. package/src/model/edge/BaseEdgeModel.ts +0 -777
  150. package/src/model/edge/BezierEdgeModel.ts +0 -197
  151. package/src/model/edge/LineEdgeModel.ts +0 -36
  152. package/src/model/edge/PolylineEdgeModel.ts +0 -672
  153. package/src/model/edge/index.ts +0 -4
  154. package/src/model/index.ts +0 -9
  155. package/src/model/node/BaseNodeModel.ts +0 -949
  156. package/src/model/node/CircleNodeModel.ts +0 -91
  157. package/src/model/node/DiamondNodeModel.ts +0 -132
  158. package/src/model/node/EllipseNodeModel.ts +0 -98
  159. package/src/model/node/HtmlNodeModel.ts +0 -50
  160. package/src/model/node/PolygonNodeModel.ts +0 -150
  161. package/src/model/node/RectNodeModel.ts +0 -69
  162. package/src/model/node/TextNodeModel.ts +0 -54
  163. package/src/model/node/index.ts +0 -8
  164. package/src/options.ts +0 -145
  165. package/src/style/index.less +0 -261
  166. package/src/style/raw.ts +0 -220
  167. package/src/tool/MultipleSelectTool.tsx +0 -132
  168. package/src/tool/TextEditTool.tsx +0 -193
  169. package/src/tool/index.ts +0 -101
  170. package/src/typings.d.ts +0 -5
  171. package/src/util/animation.ts +0 -29
  172. package/src/util/browser.ts +0 -4
  173. package/src/util/compatible.ts +0 -15
  174. package/src/util/drag.ts +0 -220
  175. package/src/util/edge.ts +0 -1060
  176. package/src/util/geometry.ts +0 -55
  177. package/src/util/graph.ts +0 -46
  178. package/src/util/index.ts +0 -17
  179. package/src/util/matrix.ts +0 -129
  180. package/src/util/mobx.ts +0 -23
  181. package/src/util/node.ts +0 -543
  182. package/src/util/raf.ts +0 -28
  183. package/src/util/resize.ts +0 -606
  184. package/src/util/sampling.ts +0 -85
  185. package/src/util/theme.ts +0 -375
  186. package/src/util/uuid.ts +0 -26
  187. package/src/util/vector.ts +0 -93
  188. package/src/util/zIndex.ts +0 -6
  189. package/src/view/Anchor.tsx +0 -445
  190. package/src/view/Control.tsx +0 -512
  191. package/src/view/Graph.tsx +0 -141
  192. package/src/view/Rotate.tsx +0 -113
  193. package/src/view/behavior/dnd.ts +0 -162
  194. package/src/view/behavior/index.ts +0 -2
  195. package/src/view/behavior/snapline.ts +0 -16
  196. package/src/view/edge/AdjustPoint.tsx +0 -425
  197. package/src/view/edge/Arrow.tsx +0 -54
  198. package/src/view/edge/BaseEdge.tsx +0 -650
  199. package/src/view/edge/BezierEdge.tsx +0 -101
  200. package/src/view/edge/LineEdge.tsx +0 -81
  201. package/src/view/edge/PolylineEdge.tsx +0 -299
  202. package/src/view/edge/index.ts +0 -6
  203. package/src/view/index.ts +0 -8
  204. package/src/view/node/BaseNode.tsx +0 -571
  205. package/src/view/node/CircleNode.tsx +0 -21
  206. package/src/view/node/DiamondNode.tsx +0 -24
  207. package/src/view/node/EllipseNode.tsx +0 -22
  208. package/src/view/node/HtmlNode.tsx +0 -95
  209. package/src/view/node/PolygonNode.tsx +0 -28
  210. package/src/view/node/RectNode.tsx +0 -30
  211. package/src/view/node/TextNode.tsx +0 -39
  212. package/src/view/node/index.ts +0 -8
  213. package/src/view/overlay/BackgroundOverlay.tsx +0 -34
  214. package/src/view/overlay/BezierAdjustOverlay.tsx +0 -150
  215. package/src/view/overlay/CanvasOverlay.tsx +0 -288
  216. package/src/view/overlay/Grid.tsx +0 -162
  217. package/src/view/overlay/ModificationOverlay.tsx +0 -31
  218. package/src/view/overlay/OutlineOverlay.tsx +0 -170
  219. package/src/view/overlay/SnaplineOverlay.tsx +0 -44
  220. package/src/view/overlay/ToolOverlay.tsx +0 -65
  221. package/src/view/overlay/getTransformHoc.tsx +0 -50
  222. package/src/view/overlay/index.ts +0 -8
  223. package/src/view/shape/Circle.tsx +0 -41
  224. package/src/view/shape/Ellipse.tsx +0 -42
  225. package/src/view/shape/Line.tsx +0 -39
  226. package/src/view/shape/Path.tsx +0 -22
  227. package/src/view/shape/Polygon.tsx +0 -91
  228. package/src/view/shape/Polyline.tsx +0 -31
  229. package/src/view/shape/Rect.tsx +0 -44
  230. package/src/view/shape/Text.tsx +0 -169
  231. package/src/view/shape/index.ts +0 -8
  232. package/src/view/text/BaseText.tsx +0 -134
  233. package/src/view/text/LineText.tsx +0 -168
  234. package/src/view/text/index.ts +0 -2
  235. package/stats.html +0 -4842
  236. package/tsconfig.json +0 -18
@@ -1,224 +0,0 @@
1
- import {
2
- isBboxOverLapping,
3
- mergeBBox,
4
- isPointOutsideBBox,
5
- isSegmentCrossingBBox,
6
- getLongestEdge,
7
- getSimplePolyline,
8
- pointDirection,
9
- getBBoxCrossPointsByPoint,
10
- isSegmentsInNode,
11
- isSegmentsCrossNode,
12
- getCrossPointInRect,
13
- segmentDirection,
14
- } from '../../src/util/edge'
15
-
16
- describe('util/edge', () => {
17
- test('is bbox overlapping', () => {
18
- const bbox1 = {
19
- centerX: 1,
20
- centerY: 1,
21
- width: 2,
22
- height: 2,
23
- }
24
- const bbox2 = {
25
- centerX: 2,
26
- centerY: 2,
27
- width: 2,
28
- height: 2,
29
- }
30
- expect(isBboxOverLapping(bbox1, bbox2)).toBeTruthy()
31
-
32
- const bbox3 = {
33
- centerX: 3,
34
- centerY: 3,
35
- width: 2,
36
- height: 2,
37
- }
38
- expect(isBboxOverLapping(bbox1, bbox3)).toBeFalsy()
39
- })
40
- test('filter repeat points', () => {
41
- const sPoint1 = {
42
- x: 0,
43
- y: 0,
44
- }
45
- const tPoint1 = {
46
- x: 10,
47
- y: 10,
48
- }
49
- expect(getSimplePolyline(sPoint1, tPoint1)).toEqual([
50
- { x: 0, y: 0, id: '0-0' },
51
- { x: 0, y: 10, id: '0-10' },
52
- { x: 10, y: 10, id: '10-10' },
53
- ])
54
-
55
- const sPoint2 = {
56
- x: 0,
57
- y: 0,
58
- }
59
- const tPoint2 = {
60
- x: 0,
61
- y: 10,
62
- }
63
- expect(getSimplePolyline(sPoint2, tPoint2)).toEqual([
64
- { x: 0, y: 0, id: '0-0' },
65
- { x: 0, y: 10, id: '0-10' },
66
- ])
67
- })
68
- test('merge two BBoxes', () => {
69
- const bbox1 = {
70
- minX: 0,
71
- minY: 0,
72
- maxX: 2,
73
- maxY: 2,
74
- }
75
- const bbox2 = {
76
- minX: 1,
77
- minY: 1,
78
- maxX: 3,
79
- maxY: 3,
80
- }
81
- expect(mergeBBox(bbox1, bbox2)).toEqual({
82
- minX: 0,
83
- minY: 0,
84
- maxX: 3,
85
- maxY: 3,
86
- centerX: 1.5,
87
- centerY: 1.5,
88
- width: 3,
89
- height: 3,
90
- })
91
- })
92
- test('get direction of two points', () => {
93
- const point = {
94
- x: 0,
95
- y: 0,
96
- }
97
- const bbox1 = {
98
- width: 2,
99
- height: 4,
100
- centerX: 1,
101
- centerY: 1,
102
- }
103
- const bbox2 = {
104
- width: 4,
105
- height: 2,
106
- centerX: 1,
107
- centerY: 1,
108
- }
109
- expect(pointDirection(point, bbox1)).toEqual('horizontal')
110
- expect(pointDirection(point, bbox2)).toEqual('vertical')
111
- })
112
- test('is point inside the bbox', () => {
113
- const bbox = {
114
- minX: 0,
115
- minY: 0,
116
- maxX: 2,
117
- maxY: 2,
118
- }
119
- expect(isPointOutsideBBox({ x: 1, y: 1 }, bbox)).toBeFalsy()
120
- expect(isPointOutsideBBox({ x: 3, y: 3 }, bbox)).toBeTruthy()
121
- })
122
- test('get cross points of bbox and point', () => {
123
- const bbox = {
124
- minX: 0,
125
- minY: 0,
126
- maxX: 2,
127
- maxY: 2,
128
- }
129
- const point1 = {
130
- x: 1,
131
- y: 1,
132
- }
133
- const point2 = {
134
- x: 3,
135
- y: 3,
136
- }
137
- expect(getBBoxCrossPointsByPoint(bbox, point1)).toEqual([
138
- { x: 1, y: 0 },
139
- { x: 1, y: 2 },
140
- { x: 0, y: 1 },
141
- { x: 2, y: 1 },
142
- ])
143
- expect(getBBoxCrossPointsByPoint(bbox, point2)).toEqual([])
144
- })
145
- test('is segment cross the bbox', () => {
146
- const bbox = {
147
- minX: 0,
148
- minY: 0,
149
- maxX: 2,
150
- maxY: 2,
151
- }
152
- expect(
153
- isSegmentCrossingBBox({ x: 1, y: 1 }, { x: 3, y: 3 }, bbox),
154
- ).toBeTruthy()
155
- expect(
156
- isSegmentCrossingBBox({ x: 3, y: 3 }, { x: 4, y: 4 }, bbox),
157
- ).toBeFalsy()
158
- })
159
- test('get longest edge', () => {
160
- const points = [
161
- { x: 0, y: 0 },
162
- { x: 1, y: 1 },
163
- { x: 2, y: 2 },
164
- ]
165
- expect(getLongestEdge(points)).toEqual([
166
- { x: 0, y: 0 },
167
- { x: 1, y: 1 },
168
- ])
169
- })
170
-
171
- const segment1 = [
172
- {
173
- x: 0,
174
- y: 0,
175
- },
176
- {
177
- x: 0,
178
- y: 10,
179
- },
180
- ]
181
- const segment2 = [
182
- {
183
- x: -30,
184
- y: 0,
185
- },
186
- {
187
- x: 30,
188
- y: 0,
189
- },
190
- ]
191
- const bbox = {
192
- x: 0,
193
- y: 0,
194
- width: 20,
195
- height: 20,
196
- }
197
- test('is segments in node', () => {
198
- expect(isSegmentsInNode(segment1[0], segment1[1], bbox)).toBeTruthy()
199
- expect(isSegmentsInNode(segment2[0], segment2[1], bbox)).toBeFalsy()
200
- })
201
- test('is segments cross node', () => {
202
- expect(isSegmentsCrossNode(segment1[0], segment1[1], bbox)).toBeFalsy()
203
- expect(isSegmentsCrossNode(segment2[0], segment1[0], bbox)).toBeTruthy()
204
- })
205
- test('get cross point in rect', () => {
206
- expect(getCrossPointInRect(segment1[0], segment1[1], bbox)).toEqual({
207
- x: 0,
208
- y: 10,
209
- })
210
- expect(getCrossPointInRect(segment2[0], segment2[1], bbox)).toEqual({
211
- x: -10,
212
- y: 0,
213
- })
214
- })
215
- test('segment direction', () => {
216
- expect(segmentDirection(segment1[0], segment1[1])).toEqual('vertical')
217
- expect(
218
- segmentDirection(segment1[0], {
219
- x: 10,
220
- y: 0,
221
- }),
222
- ).toEqual('horizontal')
223
- })
224
- })
@@ -1,14 +0,0 @@
1
- import { snapToGrid, getGridOffset } from '../../src/util'
2
-
3
- describe('util/geometry', () => {
4
- test('snapToGrid', () => {
5
- const point = 2.5
6
- const grid = 1.5
7
- expect(snapToGrid(point, grid) - 3 < Number.EPSILON).toBeTruthy()
8
- })
9
- test('getGridOffset', () => {
10
- const distance = 3
11
- const grid = 1.5
12
- expect(getGridOffset(distance, grid) - 2 < Number.EPSILON).toBeTruthy()
13
- })
14
- })
@@ -1,16 +0,0 @@
1
- import { isPointInArea } from '../../src/util/graph'
2
-
3
- describe('util/graph', () => {
4
- test('if element is in an area, truthy', () => {
5
- const point: [number, number] = [1, 1]
6
- const leftTopPoint: [number, number] = [0, 0]
7
- const rightBottomPoint: [number, number] = [2, 2]
8
- expect(isPointInArea(point, leftTopPoint, rightBottomPoint)).toBeTruthy()
9
- })
10
- test('if element is in an area, falsy', () => {
11
- const point: [number, number] = [1, 1]
12
- const leftTopPoint: [number, number] = [2, 2]
13
- const rightBottomPoint: [number, number] = [4, 4]
14
- expect(isPointInArea(point, leftTopPoint, rightBottomPoint)).toBeFalsy()
15
- })
16
- })
@@ -1,41 +0,0 @@
1
- import { Matrix } from '../../src/util/matrix'
2
-
3
- describe('util/matrix', () => {
4
- test('construct', () => {
5
- const m = new Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
6
- expect(m[0]).toEqual([1, 2, 3])
7
- expect(m[1]).toEqual([4, 5, 6])
8
- expect(m[2]).toEqual([7, 8, 9])
9
- })
10
- test('cross', () => {
11
- const m = new Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
12
- const n = new Matrix([9, 8, 7], [6, 5, 4], [3, 2, 1])
13
- expect(m.cross(n)).toEqual(
14
- new Matrix([30, 24, 18], [84, 69, 54], [138, 114, 90]),
15
- )
16
- })
17
- test('transpose', () => {
18
- const m = new Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
19
- expect(m.transpose()).toEqual(new Matrix([1, 4, 7], [2, 5, 8], [3, 6, 9]))
20
- })
21
- test('translate', () => {
22
- const m = new Matrix([1, 0, 0], [0, 1, 0], [0, 0, 1])
23
- expect(m.translate(2, 3)).toEqual(
24
- new Matrix([1, 0, 0], [0, 1, 0], [2, 3, 1]),
25
- )
26
- })
27
- test('rotate', () => {
28
- const m = new Matrix([1, 0, 0], [0, 1, 0], [0, 0, 1])
29
- expect(m.rotate(Math.PI / 2)).toEqual(
30
- new Matrix([0, 1, 0], [-1, 0, 0], [0, 0, 1]),
31
- )
32
- })
33
- test('scale', () => {
34
- const m = new Matrix([1, 0, 0], [0, 1, 0], [0, 0, 1])
35
- expect(m.scale(2, 3)).toEqual(new Matrix([2, 0, 0], [0, 3, 0], [0, 0, 1]))
36
- })
37
- test('toString', () => {
38
- const m = new Matrix([1, 0, 0], [0, 1, 0], [1, 1, 1])
39
- expect(m.toString()).toEqual('matrix(1 0 0 1 1 1)')
40
- })
41
- })
@@ -1,68 +0,0 @@
1
- import {
2
- getClosestAnchor,
3
- isInNode,
4
- getCrossPointWithCircle,
5
- getCrossPointWithEllipse,
6
- } from '../../src/util/node'
7
-
8
- describe('util/node', () => {
9
- test('get closest anchor', () => {
10
- const position = { x: 0, y: 0 }
11
- const node = {
12
- anchors: [
13
- { x: 0, y: 0, id: '1' },
14
- { x: 1, y: 1, id: '2' },
15
- { x: 2, y: 2, id: '3' },
16
- ],
17
- }
18
- expect(getClosestAnchor(position, node)).toEqual({
19
- anchor: { x: 0, y: 0, id: '1' },
20
- index: 0,
21
- })
22
- })
23
- test('is point inside the node', () => {
24
- const position1 = { x: 0, y: 0 }
25
- const position2 = { x: 110, y: 110 }
26
- const node = {
27
- x: 0,
28
- y: 0,
29
- width: 100,
30
- height: 100,
31
- }
32
- expect(isInNode(position1, node)).toBeTruthy()
33
- expect(isInNode(position2, node)).toBeFalsy()
34
- })
35
- test('get cross point with circle', () => {
36
- const position = { x: 0, y: 0 }
37
- const node = {
38
- x: 0,
39
- y: 0,
40
- r: 10,
41
- }
42
- expect(getCrossPointWithCircle(position, 'horizontal', node)).toEqual({
43
- x: 10,
44
- y: 0,
45
- })
46
- expect(getCrossPointWithCircle(position, 'vertical', node)).toEqual({
47
- x: 0,
48
- y: 10,
49
- })
50
- })
51
- test('get cross point with ellipse', () => {
52
- const position = { x: 0, y: 0 }
53
- const node = {
54
- x: 0,
55
- y: 0,
56
- rx: 10,
57
- ry: 5,
58
- }
59
- expect(getCrossPointWithEllipse(position, 'horizontal', node)).toEqual({
60
- x: 10,
61
- y: 0,
62
- })
63
- expect(getCrossPointWithEllipse(position, 'vertical', node)).toEqual({
64
- x: 0,
65
- y: 5,
66
- })
67
- })
68
- })
@@ -1,12 +0,0 @@
1
- import { degrees, getThetaOfVector, Vector } from '../../src/util'
2
-
3
- describe('util/sampling', () => {
4
- test('degrees', () => {
5
- expect(degrees(1)).toBe(57.29577951308232)
6
- })
7
- test('getThetaOfVector', () => {
8
- expect(
9
- getThetaOfVector(new Vector(1, 1)) - 45 < Number.EPSILON,
10
- ).toBeTruthy()
11
- })
12
- })
@@ -1,50 +0,0 @@
1
- import { Vector } from '../../src/util/vector'
2
-
3
- describe('util/vector', () => {
4
- test('construct', () => {
5
- const v = new Vector(1, 2)
6
- expect(v.x).toEqual(1)
7
- expect(v[0]).toEqual(1)
8
-
9
- expect(v.y).toEqual(2)
10
- expect(v[1]).toEqual(2)
11
-
12
- expect(v.z).toEqual(0)
13
- expect(v[2]).toEqual(0)
14
- })
15
- test('add', () => {
16
- const v = new Vector(1, 2)
17
- const v1 = new Vector(3, 4)
18
- expect(v.add(v1)).toEqual(new Vector(4, 6))
19
- })
20
- test('subtract', () => {
21
- const v = new Vector(1, 2)
22
- const v1 = new Vector(3, 4)
23
- expect(v.subtract(v1)).toEqual(new Vector(-2, -2))
24
- })
25
- test('dot', () => {
26
- const v = new Vector(1, 2)
27
- const v1 = new Vector(3, 4)
28
- expect(v.dot(v1)).toEqual(11)
29
- })
30
- test('cross', () => {
31
- const v = new Vector(1, 2)
32
- const v1 = new Vector(3, 4)
33
- expect(v.cross(v1)).toEqual(new Vector(0, 0, -2))
34
- })
35
- test('getLength', () => {
36
- const v = new Vector(1, 2)
37
- expect(v.getLength()).toEqual(Math.sqrt(5))
38
- })
39
- test('normalize', () => {
40
- const v = new Vector(1, 2)
41
- expect(v.normalize()).toEqual(
42
- new Vector(1 / Math.sqrt(5), 2 / Math.sqrt(5)),
43
- )
44
- })
45
- test('angle', () => {
46
- const v = new Vector(1, 1)
47
- const v1 = new Vector(0, 1)
48
- expect(v.angle(v1) - Math.PI / 4 < Number.EPSILON).toBeTruthy()
49
- })
50
- })
@@ -1,10 +0,0 @@
1
- import { getZIndex, getMinIndex } from '../../src/util/zIndex'
2
-
3
- describe('util/zIndex', () => {
4
- test('getZIndex', () => {
5
- expect(getZIndex()).toBe(1001)
6
- })
7
- test('getMinIndex', () => {
8
- expect(getMinIndex()).toBe(998)
9
- })
10
- })