@immugio/three-math-extensions 0.2.13 → 0.2.14

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/CHANGELOG.md CHANGED
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
9
9
 
10
- ## [0.2.13](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.13)
10
+ ## [0.2.14](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.14)
11
11
 
12
12
  ### Commits
13
13
 
@@ -27,6 +27,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
27
27
  - Add Vec2.fromPoints to accept multiple points [`a261402`](https://github.com/Immugio/three-math-extensions/commit/a2614027cf5fb8263189b48f7e0bb9a23a552c15)
28
28
  - Add Vec2.parallelTo [`989874d`](https://github.com/Immugio/three-math-extensions/commit/989874dcfe122d3ee84d8d56d79cb88e4e441736)
29
29
  - Line2D.intersect - enable line segments intersection only [`1f1470e`](https://github.com/Immugio/three-math-extensions/commit/1f1470e1cf00118e643f5c44a135e0baf6b76d41)
30
+ - Line3D.groupConnectedLines now supports line breaks [`417a9ea`](https://github.com/Immugio/three-math-extensions/commit/417a9ea471bf4c539f73f5fb170c962a78ee4ab4)
30
31
  - Add Line2D.projectOn [`4c52c5c`](https://github.com/Immugio/three-math-extensions/commit/4c52c5c2e649fbddb72ce3fca60cfd3f1319f72f)
31
32
  - Add Line3D.index [`7ed13d2`](https://github.com/Immugio/three-math-extensions/commit/7ed13d213748056c9dafd86288c3bcec9a28d1ba)
32
33
  - Polygon from bounding size [`eae6701`](https://github.com/Immugio/three-math-extensions/commit/eae67012f57f426f8b5259b765000447ce06d608)
@@ -42,7 +43,13 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
42
43
  - Documentation update [`d5c7a07`](https://github.com/Immugio/three-math-extensions/commit/d5c7a0765f6097f5d3a3be01967d4059f19682fb)
43
44
  - Excluded files from build [`ec70614`](https://github.com/Immugio/three-math-extensions/commit/ec70614bc7df7a98f854c7a6693365118e04faf7)
44
45
 
45
- ## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.12...16.15.10) - 2023-01-02
46
+ ## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.13...16.15.10) - 2023-01-02
47
+
48
+ ## [0.2.13](https://github.com/Immugio/three-math-extensions/compare/0.2.12...0.2.13) - 2023-08-31
49
+
50
+ ### Commits
51
+
52
+ - Line3D.connectsTo added [`6d2cfa0`](https://github.com/Immugio/three-math-extensions/commit/6d2cfa0f5335c665f325a694a32c57b574ec326d)
46
53
 
47
54
  ## [0.2.12](https://github.com/Immugio/three-math-extensions/compare/0.2.11...0.2.12) - 2023-08-30
48
55
 
package/cjs/Line3D.js CHANGED
@@ -412,8 +412,9 @@ class Line3D extends three_1.Line3 {
412
412
  * Accepts an array of Line3D and groups them into arrays of connected lines
413
413
  * @param lines Lines to be grouped
414
414
  * @param tolerance Tolerance for considering lines as connected
415
+ * @param breakpoints
415
416
  */
416
- static groupConnectedLines(lines, tolerance = 0) {
417
+ static groupConnectedLines(lines, tolerance = 0, breakpoints = []) {
417
418
  const visited = new Set();
418
419
  // Use graph-based approach. Each line can be considered as an edge in the graph, and the endpoints of the lines can be considered as vertices.
419
420
  // Then use Depth-First Search (DFS) to find connected components in the graph.
@@ -424,7 +425,7 @@ class Line3D extends three_1.Line3 {
424
425
  group.push(line);
425
426
  lines.forEach((neighbor) => {
426
427
  if (!visited.has(neighbor)) {
427
- if (line.connectsTo(neighbor, tolerance)) {
428
+ if (line.connectsTo(neighbor, tolerance, breakpoints)) {
428
429
  dfs(neighbor, group);
429
430
  }
430
431
  }
@@ -441,15 +442,16 @@ class Line3D extends three_1.Line3 {
441
442
  return connectedLines;
442
443
  }
443
444
  /**
444
- * Returns true if any endpoint of this line if within the tolerance distance of any endpoint of the @other line.
445
+ * Returns true if any endpoint of this line is within the tolerance of any @other line's endpoints.
445
446
  * @param other
446
447
  * @param tolerance
448
+ * @param breakpoints
447
449
  */
448
- connectsTo(other, tolerance = 0) {
449
- return this.start.isNear(other.start, tolerance) ||
450
- this.start.isNear(other.end, tolerance) ||
451
- this.end.isNear(other.start, tolerance) ||
452
- this.end.isNear(other.end, tolerance);
450
+ connectsTo(other, tolerance = 0, breakpoints = []) {
451
+ return ((this.start.isNear(other.start, tolerance) && breakpoints.every(b => !b.isNear(this.start, tolerance))) ||
452
+ (this.start.isNear(other.end, tolerance) && breakpoints.every(b => !b.isNear(this.start, tolerance))) ||
453
+ (this.end.isNear(other.start, tolerance) && breakpoints.every(b => !b.isNear(this.end, tolerance))) ||
454
+ (this.end.isNear(other.end, tolerance) && breakpoints.every(b => !b.isNear(this.end, tolerance))));
453
455
  }
454
456
  /**
455
457
  * Project the line to 2D space, Y value is dropped
package/esm/Line3D.js CHANGED
@@ -409,8 +409,9 @@ export class Line3D extends Line3 {
409
409
  * Accepts an array of Line3D and groups them into arrays of connected lines
410
410
  * @param lines Lines to be grouped
411
411
  * @param tolerance Tolerance for considering lines as connected
412
+ * @param breakpoints
412
413
  */
413
- static groupConnectedLines(lines, tolerance = 0) {
414
+ static groupConnectedLines(lines, tolerance = 0, breakpoints = []) {
414
415
  const visited = new Set();
415
416
  // Use graph-based approach. Each line can be considered as an edge in the graph, and the endpoints of the lines can be considered as vertices.
416
417
  // Then use Depth-First Search (DFS) to find connected components in the graph.
@@ -421,7 +422,7 @@ export class Line3D extends Line3 {
421
422
  group.push(line);
422
423
  lines.forEach((neighbor) => {
423
424
  if (!visited.has(neighbor)) {
424
- if (line.connectsTo(neighbor, tolerance)) {
425
+ if (line.connectsTo(neighbor, tolerance, breakpoints)) {
425
426
  dfs(neighbor, group);
426
427
  }
427
428
  }
@@ -438,15 +439,16 @@ export class Line3D extends Line3 {
438
439
  return connectedLines;
439
440
  }
440
441
  /**
441
- * Returns true if any endpoint of this line if within the tolerance distance of any endpoint of the @other line.
442
+ * Returns true if any endpoint of this line is within the tolerance of any @other line's endpoints.
442
443
  * @param other
443
444
  * @param tolerance
445
+ * @param breakpoints
444
446
  */
445
- connectsTo(other, tolerance = 0) {
446
- return this.start.isNear(other.start, tolerance) ||
447
- this.start.isNear(other.end, tolerance) ||
448
- this.end.isNear(other.start, tolerance) ||
449
- this.end.isNear(other.end, tolerance);
447
+ connectsTo(other, tolerance = 0, breakpoints = []) {
448
+ return ((this.start.isNear(other.start, tolerance) && breakpoints.every(b => !b.isNear(this.start, tolerance))) ||
449
+ (this.start.isNear(other.end, tolerance) && breakpoints.every(b => !b.isNear(this.start, tolerance))) ||
450
+ (this.end.isNear(other.start, tolerance) && breakpoints.every(b => !b.isNear(this.end, tolerance))) ||
451
+ (this.end.isNear(other.end, tolerance) && breakpoints.every(b => !b.isNear(this.end, tolerance))));
450
452
  }
451
453
  /**
452
454
  * Project the line to 2D space, Y value is dropped
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immugio/three-math-extensions",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "Set of utilities for 2d and 3d line math built on top of three.js",
5
5
  "author": "Jan Mikeska <janmikeska@gmail.com>",
6
6
  "license": "ISC",
package/src/Line3D.ts CHANGED
@@ -506,8 +506,9 @@ export class Line3D extends Line3 {
506
506
  * Accepts an array of Line3D and groups them into arrays of connected lines
507
507
  * @param lines Lines to be grouped
508
508
  * @param tolerance Tolerance for considering lines as connected
509
+ * @param breakpoints
509
510
  */
510
- public static groupConnectedLines(lines: Line3D[], tolerance: number = 0): Line3D[][] {
511
+ public static groupConnectedLines(lines: Line3D[], tolerance: number = 0, breakpoints: Vec3[] = []): Line3D[][] {
511
512
  const visited: Set<Line3D> = new Set();
512
513
 
513
514
  // Use graph-based approach. Each line can be considered as an edge in the graph, and the endpoints of the lines can be considered as vertices.
@@ -520,7 +521,7 @@ export class Line3D extends Line3 {
520
521
  lines.forEach((neighbor) => {
521
522
  if (!visited.has(neighbor)) {
522
523
  if (
523
- line.connectsTo(neighbor, tolerance)
524
+ line.connectsTo(neighbor, tolerance, breakpoints)
524
525
  ) {
525
526
  dfs(neighbor, group);
526
527
  }
@@ -542,15 +543,18 @@ export class Line3D extends Line3 {
542
543
  }
543
544
 
544
545
  /**
545
- * Returns true if any endpoint of this line if within the tolerance distance of any endpoint of the @other line.
546
+ * Returns true if any endpoint of this line is within the tolerance of any @other line's endpoints.
546
547
  * @param other
547
548
  * @param tolerance
549
+ * @param breakpoints
548
550
  */
549
- public connectsTo(other: Line3D, tolerance: number = 0): boolean {
550
- return this.start.isNear(other.start, tolerance) ||
551
- this.start.isNear(other.end, tolerance) ||
552
- this.end.isNear(other.start, tolerance) ||
553
- this.end.isNear(other.end, tolerance);
551
+ public connectsTo(other: Line3D, tolerance: number = 0, breakpoints: Vec3[] = []): boolean {
552
+ return (
553
+ (this.start.isNear(other.start, tolerance) && breakpoints.every(b => !b.isNear(this.start, tolerance))) ||
554
+ (this.start.isNear(other.end, tolerance) && breakpoints.every(b => !b.isNear(this.start, tolerance))) ||
555
+ (this.end.isNear(other.start, tolerance) && breakpoints.every(b => !b.isNear(this.end, tolerance))) ||
556
+ (this.end.isNear(other.end, tolerance) && breakpoints.every(b => !b.isNear(this.end, tolerance)))
557
+ );
554
558
  }
555
559
 
556
560
  /**
package/types/Line3D.d.ts CHANGED
@@ -150,14 +150,16 @@ export declare class Line3D extends Line3 {
150
150
  * Accepts an array of Line3D and groups them into arrays of connected lines
151
151
  * @param lines Lines to be grouped
152
152
  * @param tolerance Tolerance for considering lines as connected
153
+ * @param breakpoints
153
154
  */
154
- static groupConnectedLines(lines: Line3D[], tolerance?: number): Line3D[][];
155
+ static groupConnectedLines(lines: Line3D[], tolerance?: number, breakpoints?: Vec3[]): Line3D[][];
155
156
  /**
156
- * Returns true if any endpoint of this line if within the tolerance distance of any endpoint of the @other line.
157
+ * Returns true if any endpoint of this line is within the tolerance of any @other line's endpoints.
157
158
  * @param other
158
159
  * @param tolerance
160
+ * @param breakpoints
159
161
  */
160
- connectsTo(other: Line3D, tolerance?: number): boolean;
162
+ connectsTo(other: Line3D, tolerance?: number, breakpoints?: Vec3[]): boolean;
161
163
  /**
162
164
  * Project the line to 2D space, Y value is dropped
163
165
  */