@immugio/three-math-extensions 0.0.4 → 0.0.6

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.
@@ -1,28 +0,0 @@
1
- name: Build
2
-
3
- on:
4
- push:
5
- branches: [ master ]
6
- pull_request:
7
- branches: [ master ]
8
-
9
- jobs:
10
- build:
11
-
12
- runs-on: ubuntu-latest
13
-
14
- strategy:
15
- matrix:
16
- node-version: [16.x]
17
-
18
- steps:
19
- - uses: actions/checkout@v3
20
-
21
- - name: Use Node.js ${{ matrix.node-version }}
22
- uses: actions/setup-node@v3
23
-
24
- with:
25
- node-version: ${{ matrix.node-version }}
26
- - run: npm ci
27
- - run: npm run build --if-present
28
- - run: npm test
@@ -1,51 +0,0 @@
1
- name: Publish to NPM
2
-
3
- on:
4
- push:
5
- tags:
6
- - '[0-9]+.[0-9]+.[0-9]+'
7
- jobs:
8
- build:
9
- runs-on: ubuntu-latest
10
-
11
- strategy:
12
- matrix:
13
- node-version: [16.x]
14
-
15
- steps:
16
- - uses: actions/checkout@v2
17
- - name: Use Node.js ${{ matrix.node-version }}
18
- uses: actions/setup-node@v1
19
- with:
20
- node-version: ${{ matrix.node-version }}
21
- - uses: actions/cache@v2
22
- with:
23
- path: node_modules
24
- key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
25
- restore-keys: |
26
- ${{ runner.os }}-node-
27
-
28
- - name: Install Dependencies
29
- run: npm install
30
-
31
- - name: Building
32
- run: npm run build
33
-
34
- - name: Publish to NPM
35
- run: |
36
- npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
37
- npm publish
38
- env:
39
- NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
40
- - name: Package lib
41
- run: npm pack
42
-
43
- - name: Release
44
- uses: docker://antonyurchenko/git-release:v3
45
- env:
46
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47
- ALLOW_EMPTY_CHANGELOG: "false"
48
- ALLOW_TAG_PREFIX: "true"
49
- with:
50
- args: |
51
- three-math-extensions-*.tgz
package/jest.config.js DELETED
@@ -1,6 +0,0 @@
1
- /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
- // eslint-disable-next-line no-undef
3
- module.exports = {
4
- preset: "ts-jest",
5
- testEnvironment: "node",
6
- };
@@ -1,358 +0,0 @@
1
- import { Line2D } from "../Line2D";
2
- import { Vector2 } from "three";
3
- import { Vec2 } from "../Vec2";
4
- import { Point2 } from "../Point2";
5
-
6
- describe("Line2D", () => {
7
- it("should be created", () => {
8
- const start = new Vec2(1, 2);
9
- const end = new Vec2(3, 4);
10
- const line = new Line2D(start, end, 20);
11
- expect(line).toEqual(new Line2D(start, end, 20));
12
- expect(line.start).toBe(start);
13
- expect(line.end).toBe(end);
14
- });
15
-
16
- it("should be created fromCoordinates", () => {
17
- const line = Line2D.fromCoordinates(1, 2, 3, 4, 10);
18
- expect(line.start.x).toEqual(1);
19
- expect(line.start.y).toEqual(2);
20
- expect(line.end.x).toEqual(3);
21
- expect(line.end.y).toEqual(4);
22
- expect(line.index).toEqual(10);
23
- });
24
-
25
- it("should be created fromPoints", () => {
26
- const line = Line2D.fromPoints({ x: 1, y: 2 }, { x: 3, y: 4 }, 10);
27
- expect(line).toEqual(new Line2D(new Vec2(1, 2), new Vec2(3, 4), 10));
28
- });
29
-
30
- it("should create a single line polygon from a 2 points polygon", () => {
31
- const start = new Vec2(1, 2);
32
- const end = new Vec2(3, 4);
33
- const lines = Line2D.fromPolygon([start, end]);
34
- expect(lines.length).toEqual(1);
35
- expect(lines[0]).toEqual(new Line2D(start, end));
36
- });
37
-
38
- it("should create a 2 lines polygon from a 3 points polygon", () => {
39
- const p1 = new Vec2(1, 2);
40
- const p2 = new Vec2(3, 4);
41
- const p3 = new Vec2(5, 2);
42
- const lines = Line2D.fromPolygon([p1, p2, p3]);
43
- expect(lines.length).toEqual(2);
44
- expect(lines[0]).toEqual(new Line2D(p1, p2, 0));
45
- expect(lines[1]).toEqual(new Line2D(p2, p3, 1));
46
- });
47
-
48
- it("should create a closed 3 lines polygon from a 3 points polygon", () => {
49
- const p1 = new Vec2(1, 2);
50
- const p2 = new Vec2(3, 4);
51
- const p3 = new Vec2(5, 2);
52
- const lines = Line2D.fromPolygon([p1, p2, p3], true);
53
- expect(lines.length).toEqual(3);
54
- expect(lines[0]).toEqual(new Line2D(p1, p2, 0));
55
- expect(lines[1]).toEqual(new Line2D(p2, p3, 1));
56
- expect(lines[2]).toEqual(new Line2D(p3, p1, 2));
57
- });
58
-
59
- test("center should return the center of the line", () => {
60
- const line = Line2D.fromCoordinates(-2, -2, 2, 2);
61
- expect(line.center.x).toEqual(0);
62
- expect(line.center.y).toEqual(0);
63
- });
64
-
65
- test("resize should resize the line by the given length", () => {
66
- const line = Line2D.fromCoordinates(-2, 1, 2, 1);
67
- const originalCenter = line.center;
68
- expect(line.length).toEqual(4);
69
-
70
- const resizeDistance = 2;
71
- line.resize(resizeDistance);
72
-
73
- expect(line.length).toEqual(6);
74
- expect(line.center).toEqual(originalCenter);
75
- expect(line.start.x).toEqual(-3);
76
- expect(line.end.x).toEqual(3);
77
- });
78
-
79
- test("moveStartPoint should move p1 on the line by the given amount", () => {
80
- const line = Line2D.fromCoordinates(-2, 1, 2, 1);
81
- expect(line.length).toEqual(4);
82
-
83
- line.moveStartPoint(2);
84
- expect(line.length).toEqual(6);
85
- expect(line.start.x).toEqual(-4);
86
- });
87
-
88
- test("moveEndPoint should move p1 on the line by the given amount", () => {
89
- const line = Line2D.fromCoordinates(-2, 1, 2, 1);
90
- expect(line.length).toEqual(4);
91
-
92
- line.moveEndPoint(2);
93
- expect(line.length).toEqual(6);
94
- expect(line.end.x).toEqual(4);
95
- });
96
-
97
- test("flip should swap the end points", () => {
98
- const line = Line2D.fromCoordinates(-2, 1, 2, 1);
99
- const original = line.clone();
100
- line.flip();
101
- expect(line.start.equals(original.end)).toBe(true);
102
- expect(line.end.equals(original.start)).toBe(true);
103
- });
104
-
105
- test("rotate should rotate the endpoints around the line center", () => {
106
- const line = Line2D.fromCoordinates(10, 0, 20, 0);
107
- line.rotate(Math.PI / 2); // 90 degrees counterclockwise
108
- expect(line.start.x).toEqual(15);
109
- expect(line.start.y).toEqual(-5);
110
- expect(line.end.x).toEqual(15);
111
- expect(line.end.y).toEqual(5);
112
- });
113
-
114
- test("translate should rotate the endpoints around the line center", () => {
115
- const line = Line2D.fromCoordinates(10, 0, 20, 0);
116
- line.translate({ x: 10, y: 100 });
117
- expect(line.start.x).toEqual(20);
118
- expect(line.start.y).toEqual(100);
119
- expect(line.end.x).toEqual(30);
120
- expect(line.end.y).toEqual(100);
121
- });
122
-
123
- test.each([
124
- [Line2D.fromCoordinates(5, 5, 15, 15), 5, 5, true],
125
- [Line2D.fromCoordinates(5, 5, 15, 15), 10, 10, true],
126
- [Line2D.fromCoordinates(5, 5, 15, 15), 15, 15, true],
127
- [Line2D.fromCoordinates(5, 5, 15, 15), 16, 16, false],
128
- [Line2D.fromCoordinates(5, 5, 15, 15), 10, 16, false],
129
- [Line2D.fromCoordinates(5, 5, 15, 15), 10, 4, false],
130
- [Line2D.fromCoordinates(5, 5, 15, 15), 4, 4, false],
131
- [Line2D.fromCoordinates(5, 5, 15, 15), 15, 16, false],
132
- ])("Line.isPointOnLineSection should return true if the point is on the line section", (line: Line2D, x, y, expected: boolean) => {
133
- expect(line.isPointOnLineSection({x, y})).toBe(expected);
134
- });
135
-
136
- test.each([
137
- [Line2D.fromCoordinates(5, 5, 15, 5), 10, 6, .9, false],
138
- [Line2D.fromCoordinates(5, 5, 15, 5), 10, 6, 1, true],
139
- ])("Line.isPointCloseToAndBesideLineSection should return true if the point is within expected distance of the line section", (line: Line2D, x, y, tolerance, expected: boolean) => {
140
- expect(line.isPointCloseToAndBesideLineSection({x, y}, tolerance)).toBe(expected);
141
- });
142
-
143
- test.each([
144
- [Line2D.fromCoordinates(5, 5, 15, 15), 5, 5, true],
145
- [Line2D.fromCoordinates(5, 5, 15, 15), 10, 10, true],
146
- [Line2D.fromCoordinates(5, 5, 15, 15), 15, 15, true],
147
- [Line2D.fromCoordinates(5, 5, 15, 15), 16, 16, false],
148
- [Line2D.fromCoordinates(5, 5, 15, 15), 10, 16, true],
149
- [Line2D.fromCoordinates(5, 5, 15, 15), 10, 4, true],
150
- [Line2D.fromCoordinates(5, 5, 15, 15), 4, 4, false],
151
- [Line2D.fromCoordinates(5, 5, 15, 15), 15, 16, false],
152
- ])("Line.isPointBesideLineSection should return true if the point is beside the line section", (line: Line2D, x, y, expected: boolean) => {
153
- expect(line.isPointBesideLineSection({x, y})).toBe(expected);
154
- });
155
-
156
- test.each([
157
- [Line2D.fromCoordinates(5, 5, 15, 15), 5, 5, 0],
158
- [Line2D.fromCoordinates(5, 5, 15, 15), 10, 10, 0],
159
- [Line2D.fromCoordinates(5, 5, 15, 15), 15, 15, 0],
160
- [Line2D.fromCoordinates(5, 5, 15, 15), 16, 16, 0],
161
- [Line2D.fromCoordinates(5, 5, 15, 15), 10, 16, 4.242640687119285],
162
- [Line2D.fromCoordinates(5, 5, 15, 15), 10, 4, 4.242640687119285],
163
- [Line2D.fromCoordinates(5, 5, 15, 15), 4, 4, 0],
164
- [Line2D.fromCoordinates(5, 5, 15, 15), 10, 11, 0.7071067811865476],
165
- ])("Line.distanceToPointOnInfiniteLine should return true if the point is beside the line section. Line: (%s, x: %s, y: %s) expected: %s", (line: Line2D, x, y, expected: number) => {
166
- expect(line.distanceToPointOnInfiniteLine({x, y})).toBe(expected);
167
- });
168
-
169
- test.each([
170
- [Line2D.fromCoordinates(5, 5, 15, 15), 5, 5, true],
171
- [Line2D.fromCoordinates(5, 5, 15, 15), 10, 10, true],
172
- [Line2D.fromCoordinates(5, 5, 15, 15), 15, 15, true],
173
- [Line2D.fromCoordinates(5, 5, 15, 15), 16, 16, true],
174
- [Line2D.fromCoordinates(5, 5, 15, 15), 4, 4, true],
175
- [Line2D.fromCoordinates(5, 5, 15, 15), 15, 16, false],
176
- ])("Line.isPointOnInfiniteLine should return true if the point is on the infinite line", (line: Line2D, x, y, expected: boolean) => {
177
- expect(line.isPointOnInfiniteLine({x, y})).toBe(expected);
178
- });
179
-
180
- test.each([
181
- [Line2D.fromCoordinates(10, 5, 15, 5), Line2D.fromCoordinates(15, 5, 20, 5), true], // Other on the right, touching
182
- [Line2D.fromCoordinates(5, 5, 15, 15), Line2D.fromCoordinates(15, 15, 16, 16), true], // Other on the right, touching, angle
183
- [Line2D.fromCoordinates(10, 5, 15, 5), Line2D.fromCoordinates(15, 5, 20, 6), false], // Other on the right, touching but lines are not collinear
184
- [Line2D.fromCoordinates(10, 5, 15, 5), Line2D.fromCoordinates(14, 5, 20, 5), true], // Other on the right, overlapping
185
- [Line2D.fromCoordinates(10, 5, 15, 5), Line2D.fromCoordinates(9, 5, 20, 5), true], // Other completely covers Line
186
- [Line2D.fromCoordinates(10, 5, 15, 5), Line2D.fromCoordinates(16, 5, 20, 5), false], // Other on the left, with gap
187
- ])("Line.canJoinLine should return true if the point is on the line %s, other: %s, expected: %s" , (line: Line2D, other: Line2D, expected: boolean) => {
188
- expect(line.isCollinearWithTouchOrOverlap(other)).toBe(expected);
189
- });
190
-
191
- test.each([
192
- [Line2D.fromCoordinates(10, 5, 15, 5), Line2D.fromCoordinates(15, 5, 20, 5), Line2D.fromCoordinates(10, 5, 20, 5)], // Other on the right, touching
193
- [Line2D.fromCoordinates(5, 5, 15, 15), Line2D.fromCoordinates(15, 15, 16, 16), Line2D.fromCoordinates(5, 5, 16, 16)], // Other on the right, touching, angle
194
- [Line2D.fromCoordinates(10, 5, 15, 5), Line2D.fromCoordinates(15, 5, 20, 6), null], // Other on the right, touching but lines are not collinear
195
- [Line2D.fromCoordinates(10, 5, 15, 5), Line2D.fromCoordinates(14, 5, 20, 5), Line2D.fromCoordinates(10, 5, 20, 5)], // Other on the right, overlapping
196
- [Line2D.fromCoordinates(10, 5, 15, 5), Line2D.fromCoordinates(9, 5, 20, 5), Line2D.fromCoordinates(9, 5, 20, 5)], // Other completely covers Line
197
- [Line2D.fromCoordinates(10, 5, 15, 5), Line2D.fromCoordinates(16, 5, 20, 5), null], // Other on the left, with gap
198
- ])("Line.joinLine returns correctly joined lines", (line: Line2D, other: Line2D, expected: Line2D) => {
199
- const result = Line2D.joinLine(line, other);
200
- if (result === null) {
201
- expect(result).toBe(null);
202
- } else {
203
- expect(result.start.x).toEqual(expected.start.x);
204
- expect(result.start.y).toEqual(expected.start.y);
205
- expect(result.end.x).toEqual(expected.end.x);
206
- expect(result.end.y).toEqual(expected.end.y);
207
- }
208
- });
209
-
210
- test("joinLines returns correctly joined lines", () => {
211
- const gr1_Line1 = Line2D.fromCoordinates(15, 0, 20, 0);
212
- const gr1_Line2 = Line2D.fromCoordinates(20, 0, 55, 0);
213
-
214
- const gr2_Line1 = Line2D.fromCoordinates(915, 0, 920, 0);
215
- const gr2_Line2 = Line2D.fromCoordinates(920, 0, 955, 0);
216
-
217
- const result = Line2D.joinLines([gr1_Line1, gr1_Line2, gr2_Line1, gr2_Line2]);
218
- expect(result.length).toEqual(2);
219
-
220
- const gr1 = result.filter(l => l.start.equals(gr1_Line1.start) && l.end.equals(gr1_Line2.end));
221
- expect(gr1.length).toEqual(1);
222
-
223
- const gr2 = result.filter(l => l.start.equals(gr2_Line1.start) && l.end.equals(gr2_Line2.end));
224
- expect(gr2.length).toEqual(1);
225
- });
226
-
227
- test("closestPointOnInfiniteLine returns the closes point to the infinite line", () => {
228
- const line = Line2D.fromCoordinates(0, 0, 10, 0);
229
- const point = new Vector2(11, 1);
230
- const closest = line.closestPointOnInfiniteLine(point);
231
- expect(closest.x).toEqual(11);
232
- expect(closest.y).toEqual(0);
233
- });
234
-
235
- test("clipOverflow clip the overlapping sections from the other line", () => {
236
- const line = Line2D.fromCoordinates(0, 0, 10, 0);
237
- const other = Line2D.fromCoordinates(-5, 0, 15, 0);
238
- line.trimExcess(other);
239
- expect(other.start).toEqual(line.start);
240
- expect(other.end).toEqual(line.end);
241
- });
242
-
243
- test("clipOverflow clip the overlapping sections from the other line", () => {
244
- const line = Line2D.fromCoordinates(0, 0, 15, 0);
245
- const other = Line2D.fromCoordinates(1, 0, 10, 0);
246
- line.extendToEnds(other, 1);
247
- expect(other.start).toEqual(line.start); // Only the first point is extended because it's within tolerance
248
- expect(other.end.x).toEqual(10); // The second point is not extended because it's outside tolerance
249
- });
250
-
251
- test.each([
252
- [new Vector2(15, 0), new Vector2(7.5, 7.5)],
253
- [new Vector2(2, 2), new Vector2(2, 2)],
254
- [new Vector2(-1, -5), new Vector2(0, 0)],
255
- [new Vector2(20, 30), new Vector2(15, 15)],
256
- ])("Line.closestPointOnLine should return a point laying directly on the line", (source: Vector2, expected: Vector2) => {
257
- const line = Line2D.fromCoordinates(0, 0, 15, 15);
258
- const closest = line.closestPointOnLine(source);
259
- expect(closest).toEqual(expected);
260
- });
261
-
262
- test.each([
263
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(0, 0, 10, 0), "Touch from the left but not overlapping", false],
264
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(20, 0, 30, 0), "Touch from the right but not overlapping", false],
265
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(22, 0, 30, 0), "Not touch, no overlap", false],
266
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(0, 1, 11, 0), "Not a real overlap, lines are not collinear", false],
267
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(0, 0, 11, 0), "Overlap from the left", true],
268
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(19, 0, 30, 0), "Overlap from the right", true],
269
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(11, 0, 19, 0), "Line completely covers Other", true],
270
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(0, 0, 30, 0), "Line is completely covered by Other", true],
271
- ])("Line.overlaps should return true if the lines overlap. Line: %s, other: %s, description: %s expected: %s", (line: Line2D, other: Line2D, description: string, expected: boolean) => {
272
- expect(line.overlaps(other)).toBe(expected);
273
- });
274
-
275
- test.each([
276
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(0, 0, 10, 0), "Touch from the left but not overlapping", null],
277
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(20, 0, 30, 0), "Touch from the right but not overlapping", null],
278
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(22, 0, 30, 0), "Not touch, no overlap", null],
279
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(0, 1, 11, 0), "Not a real overlap, lines are not collinear", null],
280
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(0, 0, 11, 0), "Overlap from the left", Line2D.fromCoordinates(10, 0, 11, 0)],
281
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(19, 0, 30, 0), "Overlap from the right", Line2D.fromCoordinates(19, 0, 20, 0)],
282
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(11, 0, 19, 0), "Line completely covers Other", Line2D.fromCoordinates(11, 0, 19, 0)],
283
- [Line2D.fromCoordinates(10, 0, 20, 0), Line2D.fromCoordinates(0, 0, 30, 0), "Line is completely covered by Other", Line2D.fromCoordinates(10, 0, 20, 0)],
284
- [Line2D.fromCoordinates(3600, 1350, 3600, 2050), Line2D.fromCoordinates(3600, 1950, 3600, 2650), "Vertical Line is covered by Other on bottom", Line2D.fromCoordinates(3600, 1950, 3600, 2050)],
285
- ])("Line.getOverlap should return overlap. Line: %s, other: %s, description: %s expected: %s", (line: Line2D, other: Line2D, description: string, expected: Line2D) => {
286
- const result = line.getOverlap(other);
287
- if (expected) {
288
- expect(result.start.equals(expected.start)).toBe(true);
289
- expect(result.end.equals(expected.end)).toBe(true);
290
- } else {
291
- expect(result).toBeNull();
292
- }
293
- });
294
-
295
- test.each([
296
- [
297
- Line2D.fromCoordinates(3550, 2400, 150, 2400),
298
- [Line2D.fromCoordinates(650, 2400, 150, 2400), Line2D.fromCoordinates(3550, 2400, 3050, 2400), Line2D.fromCoordinates(2404, 2400, 1604, 2400)],
299
- "Horizontal line with 2 clips on on the ends and one middle",
300
- [Line2D.fromCoordinates(3050, 2400, 2404, 2400), Line2D.fromCoordinates(1604, 2400, 650, 2400)],
301
- ],
302
- [
303
- Line2D.fromCoordinates(3600, 150, 3600, 2450),
304
- [Line2D.fromCoordinates(3600, 927, 3600, 1427)],
305
- "Vertical line with 1 clip in the middle middle",
306
- [Line2D.fromCoordinates(3600, 150, 3600, 927), Line2D.fromCoordinates(3600, 1427, 3600, 2450)],
307
- ],
308
- [
309
- Line2D.fromCoordinates(6050, 3100, 3800, 3100),
310
- [Line2D.fromCoordinates(6150, 3100, 3700, 3100)],
311
- "Clip line overlaps the source line on both ends",
312
- [],
313
- ],
314
- ])("Line.clipLines should return clipLines. Line: %s, others: %s, description: %s expected: %s", (line: Line2D, others: Line2D[], description: string, expected: Line2D[]) => {
315
- const result = Line2D.clipLines(line, others);
316
- expect(result.length).toEqual(expected.length);
317
- expected.forEach((e, i) => {
318
- expect(result[i].equals(e)).toBe(true);
319
- });
320
- });
321
-
322
- test.each([
323
- [
324
- Line2D.fromCoordinates(0, 50, 100, 50),
325
- Line2D.fromCoordinates(50, 0, 50, 100),
326
- "Horizontal with vertical, intersected in the middle",
327
- { x: 50, y: 50 }
328
- ],
329
- [
330
- Line2D.fromCoordinates(0, 50, 100, 50),
331
- Line2D.fromCoordinates(50, 0, 51, 100),
332
- "Horizontal with vertical, intersected in the middle, but the angle in not 90 degrees",
333
- null
334
- ],
335
- [
336
- Line2D.fromCoordinates(0, 50, 100, 50),
337
- Line2D.fromCoordinates(50, 0, 50, 49),
338
- "Horizontal with vertical, 1 unit away from intersection",
339
- null
340
- ],
341
- ])("Line.hasIntersectionWithAngle should return expected intersection. Line: %s, others: %s, description: %s expected: %s", (line: Line2D, other: Line2D, description: string, expected: Point2) => {
342
- const result = line.hasIntersectionWithAngle(other, Math.PI / 2);
343
- expect(result).toEqual(expected);
344
- });
345
-
346
- test("Line.chunk should split lines in to multiple with expected length", () => {
347
- const size = 10;
348
- const line = Line2D.fromCoordinates(0, 0, 88, 0);
349
- const chunks = line.chunk(size);
350
- expect(chunks.length).toEqual(9);
351
-
352
- expect(chunks[0].length).toEqual(size);
353
- expect(chunks[0].start.equals(line.start)).toBe(true);
354
-
355
- expect(chunks[chunks.length - 1].length).toEqual(8);
356
- expect(chunks[chunks.length - 1].end.equals(line.end)).toBe(true);
357
- });
358
- });
@@ -1,28 +0,0 @@
1
- import { Line3D } from "../Line3D";
2
- import { Vec3 } from "../Vec3";
3
-
4
- describe("Line3d.jointLine", () => {
5
- describe.each([
6
- { message: "Same direction - Lines aren't parallel", a: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)), b: new Line3D(new Vec3(10, 0, 0), new Vec3(20, 0, 1)), expected: null },
7
- { message: "Same direction - Lines don't overlap" ,a: new Line3D(new Vec3(0, 0, 0), new Vec3(5, 0, 0)), b: new Line3D(new Vec3(11, 0, 0), new Vec3(12, 0, 0)), expected: null},
8
- { message: "Same direction - This line entirely covers the other line", a: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)), b: new Line3D(new Vec3(1, 0, 0), new Vec3(9, 0, 0)), expected: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)) },
9
- { message: "Same direction - The other line entirely covers this line", a: new Line3D(new Vec3(1, 0, 0), new Vec3(9, 0, 0)), b: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)), expected: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)) },
10
- { message: "Same direction - This line is overlapped by the start of the other line", a: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)), b: new Line3D(new Vec3(5, 0, 0), new Vec3(15, 0, 0)), expected: new Line3D(new Vec3(0, 0, 0), new Vec3(15, 0, 0)) },
11
- { message: "Same direction - This line is overlapped by the end of the other line", a: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)), b: new Line3D(new Vec3(-5, 0, 0), new Vec3(5, 0, 0)), expected: new Line3D(new Vec3(-5, 0, 0), new Vec3(10, 0, 0)) },
12
-
13
- { message: "Opposite direction - Lines aren't parallel", a: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)), b: new Line3D(new Vec3(20, 0, 0), new Vec3(10, 0, 1)), expected: null },
14
- { message: "Opposite direction - Lines don't overlap", a: new Line3D(new Vec3(0, 0, 0), new Vec3(5, 0, 0)), b: new Line3D(new Vec3(12, 0, 0), new Vec3(11, 0, 0)), expected: null },
15
- { message: "Opposite direction - This line entirely covers the other line", a: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)), b: new Line3D(new Vec3(9, 0, 0), new Vec3(1, 0, 0)), expected: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)) },
16
- { message: "Opposite direction - The other line entirely covers this line", a: new Line3D(new Vec3(1, 0, 0), new Vec3(9, 0, 0)), b: new Line3D(new Vec3(10, 0, 0), new Vec3(0, 0, 0)), expected: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)) },
17
- { message: "Opposite direction - This line is overlapped by the start of the other line", a: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)), b: new Line3D(new Vec3(15, 0, 0), new Vec3(5, 0, 0)), expected: new Line3D(new Vec3(0, 0, 0), new Vec3(15, 0, 0)) },
18
- { message: "Opposite direction - This line is overlapped by the end of the other line", a: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)), b: new Line3D(new Vec3(5, 0, 0), new Vec3(-5, 0, 0)), expected: new Line3D(new Vec3(-5, 0, 0), new Vec3(10, 0, 0)) },
19
-
20
- { message: "Angle - Lines aren't parallel", a: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 9, 0)), b: new Line3D(new Vec3(5, 5, 0), new Vec3(15, 15, 0)), expected: null },
21
- { message: "Angle - This line is overlapped by the start of the other line", a: new Line3D(new Vec3(0, 0, 0), new Vec3(10, 10, 0)), b: new Line3D(new Vec3(5, 5, 0), new Vec3(15, 15, 0)), expected: new Line3D(new Vec3(0, 0, 0), new Vec3(15, 15, 0)) },
22
- ])("joint", ({message, a, b, expected }) => {
23
- const result = a.joinLine(b);
24
- test(`${message} - expected ${JSON.stringify(expected)}, received: ${JSON.stringify(result)}`, () => {
25
- expect(result).toEqual(expected);
26
- });
27
- });
28
- });
@@ -1,72 +0,0 @@
1
- import { Line3D } from "../Line3D";
2
- import { Vec3 } from "../Vec3";
3
-
4
- describe("Line3d.jointLines", () => {
5
- describe.each([
6
- {
7
- message: "Single line",
8
- source: [
9
- new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)),
10
- ], expected: [
11
- new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)),
12
- ]
13
- },
14
- {
15
- message: "2 lines with gap",
16
- source: [
17
- new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)),
18
- new Line3D(new Vec3(11, 0, 0), new Vec3(20, 0, 0)),
19
- ], expected: [
20
- new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)),
21
- new Line3D(new Vec3(11, 0, 0), new Vec3(20, 0, 0)),
22
- ]
23
- },
24
- {
25
- message: "Three lines touching",
26
- source: [
27
- new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)),
28
- new Line3D(new Vec3(10, 0, 0), new Vec3(20, 0, 0)),
29
- new Line3D(new Vec3(20, 0, 0), new Vec3(30, 0, 0)),
30
- ], expected: [
31
- new Line3D(new Vec3(0, 0, 0), new Vec3(30, 0, 0)),
32
- ]
33
- },
34
- {
35
- message: "Three lines touching, not ordered",
36
- source: [
37
- new Line3D(new Vec3(10, 0, 0), new Vec3(20, 0, 0)),
38
- new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)),
39
- new Line3D(new Vec3(20, 0, 0), new Vec3(30, 0, 0)),
40
- ], expected: [
41
- new Line3D(new Vec3(0, 0, 0), new Vec3(30, 0, 0)),
42
- ]
43
- },
44
- {
45
- message: "Sources is composed of complex overlapping, covering and duplicated lines",
46
- source: [
47
- new Line3D(new Vec3(10, 0, 0), new Vec3(20, 0, 0)), // Group 1
48
- new Line3D(new Vec3(0, 0, 0), new Vec3(10, 0, 0)),
49
- new Line3D(new Vec3(20, 0, 0), new Vec3(30, 0, 0)),
50
- new Line3D(new Vec3(10, 0, 0), new Vec3(20, 0, 0)),
51
- new Line3D(new Vec3(-5, 0, 0), new Vec3(10, 0, 0)),
52
- new Line3D(new Vec3(29, 0, 0), new Vec3(35, 0, 0)),
53
-
54
- new Line3D(new Vec3(100 + 10, 0, 0), new Vec3(100 + 20, 0, 0)), // Group 2 - same axes but shifted by x: 100
55
- new Line3D(new Vec3(100, 0, 0), new Vec3(100 + 10, 0, 0)),
56
- new Line3D(new Vec3(100 + 20, 0, 0), new Vec3(100 + 30, 0, 0)),
57
- new Line3D(new Vec3(100 + 10, 0, 0), new Vec3(100 + 20, 0, 0)),
58
- new Line3D(new Vec3(100 + -5, 0, 0), new Vec3(100 + 10, 0, 0)),
59
- new Line3D(new Vec3(100 + 29, 0, 0), new Vec3(100 + 35, 0, 0)),
60
- ], expected: [
61
- new Line3D(new Vec3(-5, 0, 0), new Vec3(35, 0, 0)),
62
- new Line3D(new Vec3(100 + -5, 0, 0), new Vec3(100 + 35, 0, 0)),
63
- ]
64
- },
65
- ])("jointLines", ({ message, source, expected }) => {
66
- const result = Line3D.joinLines(source);
67
- result.sort((a, b) => a.start.x - b.start.x); // Order of the result is not guaranteed
68
- test(`${message} - expected ${JSON.stringify(expected)}, received: ${JSON.stringify(result)}`, () => {
69
- expect(result).toEqual(expected);
70
- });
71
- });
72
- });