@logicflow/core 2.2.0-alpha.7 → 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.
- package/package.json +6 -1
- package/.turbo/turbo-build$colon$dev.log +0 -10
- package/.turbo/turbo-build.log +0 -33
- package/CHANGELOG.md +0 -1901
- package/__tests__/algorithm/egde.test.ts +0 -131
- package/__tests__/algorithm/index.test.ts +0 -74
- package/__tests__/algorithm/outline.test.ts +0 -43
- package/__tests__/bugs/1545-spec.test.ts +0 -42
- package/__tests__/event/event.test.ts +0 -22
- package/__tests__/history/history.test.ts +0 -28
- package/__tests__/logicflow.test.ts +0 -575
- package/__tests__/model/graphmodel.test.ts +0 -87
- package/__tests__/util/compatible.test.ts +0 -48
- package/__tests__/util/edge.test.ts +0 -224
- package/__tests__/util/geometry.test.ts +0 -14
- package/__tests__/util/graph.test.ts +0 -16
- package/__tests__/util/matrix.test.ts +0 -41
- package/__tests__/util/node.test.ts +0 -68
- package/__tests__/util/sampling.test.ts +0 -12
- package/__tests__/util/vector.test.ts +0 -50
- package/__tests__/util/zIndex.test.ts +0 -10
- package/src/LogicFlow.tsx +0 -2017
- package/src/algorithm/edge.ts +0 -67
- package/src/algorithm/index.ts +0 -70
- package/src/algorithm/outline.ts +0 -77
- package/src/algorithm/rotate.ts +0 -55
- package/src/common/drag.ts +0 -219
- package/src/common/history.ts +0 -108
- package/src/common/index.ts +0 -6
- package/src/common/keyboard.ts +0 -108
- package/src/common/matrix.ts +0 -122
- package/src/common/vector.ts +0 -93
- package/src/constant/index.ts +0 -179
- package/src/constant/theme.ts +0 -708
- package/src/event/event.md +0 -66
- package/src/event/eventArgs.ts +0 -643
- package/src/event/eventEmitter.ts +0 -156
- package/src/history/index.ts +0 -119
- package/src/index.less +0 -1
- package/src/index.ts +0 -26
- package/src/keyboard/index.ts +0 -112
- package/src/keyboard/shortcut.ts +0 -200
- package/src/model/BaseModel.ts +0 -250
- package/src/model/EditConfigModel.ts +0 -334
- package/src/model/GraphModel.ts +0 -1824
- package/src/model/NestedTransformModel.ts +0 -121
- package/src/model/SnaplineModel.ts +0 -256
- package/src/model/TransformModel.ts +0 -258
- package/src/model/edge/BaseEdgeModel.ts +0 -785
- package/src/model/edge/BezierEdgeModel.ts +0 -197
- package/src/model/edge/LineEdgeModel.ts +0 -36
- package/src/model/edge/PolylineEdgeModel.ts +0 -817
- package/src/model/edge/index.ts +0 -4
- package/src/model/index.ts +0 -9
- package/src/model/node/BaseNodeModel.ts +0 -959
- package/src/model/node/CircleNodeModel.ts +0 -91
- package/src/model/node/DiamondNodeModel.ts +0 -132
- package/src/model/node/EllipseNodeModel.ts +0 -98
- package/src/model/node/HtmlNodeModel.ts +0 -64
- package/src/model/node/PolygonNodeModel.ts +0 -152
- package/src/model/node/RectNodeModel.ts +0 -69
- package/src/model/node/TextNodeModel.ts +0 -54
- package/src/model/node/index.ts +0 -8
- package/src/options.ts +0 -150
- package/src/style/index.less +0 -262
- package/src/style/raw.ts +0 -221
- package/src/tool/MultipleSelectTool.tsx +0 -140
- package/src/tool/TextEditTool.tsx +0 -193
- package/src/tool/index.ts +0 -101
- package/src/typings.d.ts +0 -5
- package/src/util/animation.ts +0 -29
- package/src/util/browser.ts +0 -4
- package/src/util/compatible.ts +0 -15
- package/src/util/drag.ts +0 -219
- package/src/util/edge.ts +0 -1094
- package/src/util/geometry.ts +0 -154
- package/src/util/graph.ts +0 -46
- package/src/util/index.ts +0 -17
- package/src/util/matrix.ts +0 -129
- package/src/util/mobx.ts +0 -23
- package/src/util/node.ts +0 -543
- package/src/util/raf.ts +0 -28
- package/src/util/resize.ts +0 -606
- package/src/util/sampling.ts +0 -85
- package/src/util/theme.ts +0 -84
- package/src/util/uuid.ts +0 -26
- package/src/util/vector.ts +0 -93
- package/src/util/zIndex.ts +0 -6
- package/src/view/Anchor.tsx +0 -462
- package/src/view/Control.tsx +0 -510
- package/src/view/Graph.tsx +0 -141
- package/src/view/Rotate.tsx +0 -113
- package/src/view/behavior/dnd.ts +0 -162
- package/src/view/behavior/index.ts +0 -2
- package/src/view/behavior/snapline.ts +0 -16
- package/src/view/edge/AdjustPoint.tsx +0 -425
- package/src/view/edge/Arrow.tsx +0 -54
- package/src/view/edge/BaseEdge.tsx +0 -660
- package/src/view/edge/BezierEdge.tsx +0 -101
- package/src/view/edge/LineEdge.tsx +0 -81
- package/src/view/edge/PolylineEdge.tsx +0 -311
- package/src/view/edge/index.ts +0 -6
- package/src/view/index.ts +0 -8
- package/src/view/node/BaseNode.tsx +0 -585
- package/src/view/node/CircleNode.tsx +0 -21
- package/src/view/node/DiamondNode.tsx +0 -24
- package/src/view/node/EllipseNode.tsx +0 -22
- package/src/view/node/HtmlNode.tsx +0 -112
- package/src/view/node/PolygonNode.tsx +0 -28
- package/src/view/node/RectNode.tsx +0 -30
- package/src/view/node/TextNode.tsx +0 -39
- package/src/view/node/index.ts +0 -8
- package/src/view/overlay/BackgroundOverlay.tsx +0 -34
- package/src/view/overlay/BezierAdjustOverlay.tsx +0 -150
- package/src/view/overlay/CanvasOverlay.tsx +0 -290
- package/src/view/overlay/Grid.tsx +0 -319
- package/src/view/overlay/ModificationOverlay.tsx +0 -31
- package/src/view/overlay/OutlineOverlay.tsx +0 -158
- package/src/view/overlay/SnaplineOverlay.tsx +0 -44
- package/src/view/overlay/ToolOverlay.tsx +0 -65
- package/src/view/overlay/getTransformHoc.tsx +0 -50
- package/src/view/overlay/gridConfig.ts +0 -103
- package/src/view/overlay/index.ts +0 -8
- package/src/view/shape/Circle.tsx +0 -41
- package/src/view/shape/Ellipse.tsx +0 -42
- package/src/view/shape/Line.tsx +0 -39
- package/src/view/shape/Path.tsx +0 -22
- package/src/view/shape/Polygon.tsx +0 -54
- package/src/view/shape/Polyline.tsx +0 -31
- package/src/view/shape/Rect.tsx +0 -44
- package/src/view/shape/Text.tsx +0 -168
- package/src/view/shape/index.ts +0 -8
- package/src/view/text/BaseText.tsx +0 -134
- package/src/view/text/LineText.tsx +0 -168
- package/src/view/text/index.ts +0 -2
- package/stats.html +0 -4842
- 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
|
-
})
|