@immugio/three-math-extensions 0.2.17 → 0.2.19

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.17](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.17)
10
+ ## [0.2.19](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.19)
11
11
 
12
12
  ### Commits
13
13
 
@@ -27,6 +27,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
27
27
  - Line2D.isCloserToHorizontal [`b6f1429`](https://github.com/Immugio/three-math-extensions/commit/b6f14292d1d2765f7314c45e4c74be91280ac764)
28
28
  - Add Vec2.angleTo and tests [`dcf1e53`](https://github.com/Immugio/three-math-extensions/commit/dcf1e531aecf8c115f323e14e5e44059e5c5d15c)
29
29
  - Add Vec2.signedAngle [`863c8f2`](https://github.com/Immugio/three-math-extensions/commit/863c8f27f11288cbda535e21bb688206259269ed)
30
+ - Add parallelism check to Line2D [`18064ee`](https://github.com/Immugio/three-math-extensions/commit/18064ee35a28e2c4d656f3dfb543b545044167dd)
30
31
  - Add Vec2.fromPoints to accept multiple points [`a261402`](https://github.com/Immugio/three-math-extensions/commit/a2614027cf5fb8263189b48f7e0bb9a23a552c15)
31
32
  - Add Vec2.parallelTo [`989874d`](https://github.com/Immugio/three-math-extensions/commit/989874dcfe122d3ee84d8d56d79cb88e4e441736)
32
33
  - Line2D.intersect - enable line segments intersection only [`1f1470e`](https://github.com/Immugio/three-math-extensions/commit/1f1470e1cf00118e643f5c44a135e0baf6b76d41)
@@ -35,6 +36,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
35
36
  - Add functionality for incrementing x, y, z coordinates [`b292dcc`](https://github.com/Immugio/three-math-extensions/commit/b292dcc4e8f7f0f2a63e1810c482d96ca6bebebe)
36
37
  - Add Line3D.index [`7ed13d2`](https://github.com/Immugio/three-math-extensions/commit/7ed13d213748056c9dafd86288c3bcec9a28d1ba)
37
38
  - Polygon from bounding size [`eae6701`](https://github.com/Immugio/three-math-extensions/commit/eae67012f57f426f8b5259b765000447ce06d608)
39
+ - Add Vec3.fromPoints [`62684d7`](https://github.com/Immugio/three-math-extensions/commit/62684d7f6dc1318d345ed74288bb6afd5394e1d3)
38
40
  - Line2D and Line3D to return this instead of specific type [`761ef6a`](https://github.com/Immugio/three-math-extensions/commit/761ef6a9d8cc4e35120b666576794e521aa3b991)
39
41
  - Line2D.in3DSpace added [`a6ce0ec`](https://github.com/Immugio/three-math-extensions/commit/a6ce0ecb67f5c7b2a75fcc283c28af626153a4af)
40
42
  - Line3D.connectsTo added [`6d2cfa0`](https://github.com/Immugio/three-math-extensions/commit/6d2cfa0f5335c665f325a694a32c57b574ec326d)
@@ -49,7 +51,19 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
49
51
  - Documentation update [`d5c7a07`](https://github.com/Immugio/three-math-extensions/commit/d5c7a0765f6097f5d3a3be01967d4059f19682fb)
50
52
  - Excluded files from build [`ec70614`](https://github.com/Immugio/three-math-extensions/commit/ec70614bc7df7a98f854c7a6693365118e04faf7)
51
53
 
52
- ## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.16...16.15.10) - 2023-01-02
54
+ ## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.18...16.15.10) - 2023-01-02
55
+
56
+ ## [0.2.18](https://github.com/Immugio/three-math-extensions/compare/0.2.17...0.2.18) - 2024-02-08
57
+
58
+ ### Commits
59
+
60
+ - Add parallelism check to Line2D [`18064ee`](https://github.com/Immugio/three-math-extensions/commit/18064ee35a28e2c4d656f3dfb543b545044167dd)
61
+
62
+ ## [0.2.17](https://github.com/Immugio/three-math-extensions/compare/0.2.16...0.2.17) - 2023-12-26
63
+
64
+ ### Commits
65
+
66
+ - Packages update [`c2ef857`](https://github.com/Immugio/three-math-extensions/commit/c2ef857c01792e64c1558424fdd2f401f72720d0)
53
67
 
54
68
  ## [0.2.16](https://github.com/Immugio/three-math-extensions/compare/0.2.15...0.2.16) - 2023-11-21
55
69
 
package/cjs/Line2D.js CHANGED
@@ -80,6 +80,16 @@ class Line2D {
80
80
  this.moveEndPoint(amount / 2);
81
81
  return this;
82
82
  }
83
+ isParallelTo(other, angleTolerance = Number.EPSILON) {
84
+ const direction = this.direction;
85
+ const otherDirection = other.direction;
86
+ const angle = direction.angleTo(otherDirection);
87
+ if (angle <= angleTolerance) {
88
+ return true;
89
+ }
90
+ const opposite = direction.angleTo(otherDirection.negate());
91
+ return opposite <= angleTolerance;
92
+ }
83
93
  /*
84
94
  * Moves start point on the line by the given amount. Plus values move the point further away from the center.
85
95
  * Modifies this line.
package/cjs/Line3D.js CHANGED
@@ -282,16 +282,16 @@ class Line3D extends three_1.Line3 {
282
282
  /**
283
283
  * Check if @other is parallel to this line.
284
284
  * @param other
285
- * @param tolerance
285
+ * @param angleTolerance
286
286
  */
287
- isParallelTo(other, tolerance = Number.EPSILON) {
287
+ isParallelTo(other, angleTolerance = Number.EPSILON) {
288
288
  const direction = this.direction;
289
289
  const otherDirection = other.direction;
290
- const areTheSameDirection = direction.manhattanDistanceTo(otherDirection) <= tolerance;
290
+ const areTheSameDirection = direction.angleTo(otherDirection) <= angleTolerance;
291
291
  if (areTheSameDirection) {
292
292
  return true;
293
293
  }
294
- return direction.negate().manhattanDistanceTo(otherDirection) < tolerance;
294
+ return direction.negate().angleTo(otherDirection) < angleTolerance;
295
295
  }
296
296
  /*
297
297
  * Extends or reduces the line to the given length while keeping the center of the line constant.
package/cjs/Vec3.js CHANGED
@@ -16,6 +16,13 @@ class Vec3 extends three_1.Vector3 {
16
16
  static fromPoint(point) {
17
17
  return new Vec3(point?.x, point?.y, point?.z);
18
18
  }
19
+ /**
20
+ * Creates a new Vec3[] array from arguments of {x, y, z} objects.
21
+ * @param points - The ...{x, y, z} instances.
22
+ */
23
+ static fromPoints(...points) {
24
+ return points?.map(p => Vec3.fromPoint(p)) ?? [];
25
+ }
19
26
  /**
20
27
  * Moves this Vec3 instance towards the target Vec3 by the given amount.
21
28
  * @param target - The target Vec3.
package/esm/Line2D.js CHANGED
@@ -77,6 +77,16 @@ export class Line2D {
77
77
  this.moveEndPoint(amount / 2);
78
78
  return this;
79
79
  }
80
+ isParallelTo(other, angleTolerance = Number.EPSILON) {
81
+ const direction = this.direction;
82
+ const otherDirection = other.direction;
83
+ const angle = direction.angleTo(otherDirection);
84
+ if (angle <= angleTolerance) {
85
+ return true;
86
+ }
87
+ const opposite = direction.angleTo(otherDirection.negate());
88
+ return opposite <= angleTolerance;
89
+ }
80
90
  /*
81
91
  * Moves start point on the line by the given amount. Plus values move the point further away from the center.
82
92
  * Modifies this line.
package/esm/Line3D.js CHANGED
@@ -279,16 +279,16 @@ export class Line3D extends Line3 {
279
279
  /**
280
280
  * Check if @other is parallel to this line.
281
281
  * @param other
282
- * @param tolerance
282
+ * @param angleTolerance
283
283
  */
284
- isParallelTo(other, tolerance = Number.EPSILON) {
284
+ isParallelTo(other, angleTolerance = Number.EPSILON) {
285
285
  const direction = this.direction;
286
286
  const otherDirection = other.direction;
287
- const areTheSameDirection = direction.manhattanDistanceTo(otherDirection) <= tolerance;
287
+ const areTheSameDirection = direction.angleTo(otherDirection) <= angleTolerance;
288
288
  if (areTheSameDirection) {
289
289
  return true;
290
290
  }
291
- return direction.negate().manhattanDistanceTo(otherDirection) < tolerance;
291
+ return direction.negate().angleTo(otherDirection) < angleTolerance;
292
292
  }
293
293
  /*
294
294
  * Extends or reduces the line to the given length while keeping the center of the line constant.
package/esm/Vec3.js CHANGED
@@ -13,6 +13,13 @@ export class Vec3 extends Vector3 {
13
13
  static fromPoint(point) {
14
14
  return new Vec3(point?.x, point?.y, point?.z);
15
15
  }
16
+ /**
17
+ * Creates a new Vec3[] array from arguments of {x, y, z} objects.
18
+ * @param points - The ...{x, y, z} instances.
19
+ */
20
+ static fromPoints(...points) {
21
+ return points?.map(p => Vec3.fromPoint(p)) ?? [];
22
+ }
16
23
  /**
17
24
  * Moves this Vec3 instance towards the target Vec3 by the given amount.
18
25
  * @param target - The target Vec3.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immugio/three-math-extensions",
3
- "version": "0.2.17",
3
+ "version": "0.2.19",
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/Line2D.ts CHANGED
@@ -4,7 +4,7 @@ import { Vec2 } from "./Vec2";
4
4
  import { MathUtils } from "three";
5
5
  import { TwoPI } from "./MathConstants";
6
6
  import { Line3D } from "./Line3D";
7
- import {directions2d} from "./directions2d";
7
+ import { directions2d } from "./directions2d";
8
8
 
9
9
  const _startP = /*@__PURE__*/ new Vec2();
10
10
  const _startEnd = /*@__PURE__*/ new Vec2();
@@ -87,6 +87,19 @@ export class Line2D {
87
87
  return this;
88
88
  }
89
89
 
90
+ public isParallelTo(other: Line2D, angleTolerance: number = Number.EPSILON): boolean {
91
+ const direction = this.direction;
92
+ const otherDirection = other.direction;
93
+
94
+ const angle = direction.angleTo(otherDirection);
95
+ if (angle <= angleTolerance) {
96
+ return true;
97
+ }
98
+
99
+ const opposite = direction.angleTo(otherDirection.negate());
100
+ return opposite <= angleTolerance;
101
+ }
102
+
90
103
  /*
91
104
  * Moves start point on the line by the given amount. Plus values move the point further away from the center.
92
105
  * Modifies this line.
package/src/Line3D.ts CHANGED
@@ -339,18 +339,18 @@ export class Line3D extends Line3 {
339
339
  /**
340
340
  * Check if @other is parallel to this line.
341
341
  * @param other
342
- * @param tolerance
342
+ * @param angleTolerance
343
343
  */
344
- public isParallelTo(other: Line3D, tolerance: number = Number.EPSILON): boolean {
344
+ public isParallelTo(other: Line3D, angleTolerance: number = Number.EPSILON): boolean {
345
345
  const direction = this.direction;
346
346
  const otherDirection = other.direction;
347
347
 
348
- const areTheSameDirection = direction.manhattanDistanceTo(otherDirection) <= tolerance;
348
+ const areTheSameDirection = direction.angleTo(otherDirection) <= angleTolerance;
349
349
  if (areTheSameDirection) {
350
350
  return true;
351
351
  }
352
352
 
353
- return direction.negate().manhattanDistanceTo(otherDirection) < tolerance;
353
+ return direction.negate().angleTo(otherDirection) < angleTolerance;
354
354
  }
355
355
 
356
356
  /*
package/src/Vec3.ts CHANGED
@@ -18,6 +18,14 @@ export class Vec3 extends Vector3 {
18
18
  return new Vec3(point?.x, point?.y, point?.z);
19
19
  }
20
20
 
21
+ /**
22
+ * Creates a new Vec3[] array from arguments of {x, y, z} objects.
23
+ * @param points - The ...{x, y, z} instances.
24
+ */
25
+ public static fromPoints(...points: Point3[]): Vec3[] {
26
+ return points?.map(p => Vec3.fromPoint(p)) ?? [];
27
+ }
28
+
21
29
  /**
22
30
  * Moves this Vec3 instance towards the target Vec3 by the given amount.
23
31
  * @param target - The target Vec3.
package/types/Line2D.d.ts CHANGED
@@ -30,6 +30,7 @@ export declare class Line2D {
30
30
  */
31
31
  setCenter(value: Point2): this;
32
32
  resize(amount: number): this;
33
+ isParallelTo(other: Line2D, angleTolerance?: number): boolean;
33
34
  moveStartPoint(amount: number): this;
34
35
  /**
35
36
  * Moves end point on the line by the given amount. Plus values move the point further away from the center.
package/types/Line3D.d.ts CHANGED
@@ -109,9 +109,9 @@ export declare class Line3D extends Line3 {
109
109
  /**
110
110
  * Check if @other is parallel to this line.
111
111
  * @param other
112
- * @param tolerance
112
+ * @param angleTolerance
113
113
  */
114
- isParallelTo(other: Line3D, tolerance?: number): boolean;
114
+ isParallelTo(other: Line3D, angleTolerance?: number): boolean;
115
115
  resize(amount: number): this;
116
116
  moveStartPoint(amount: number): this;
117
117
  moveEndPoint(amount: number): this;
package/types/Vec3.d.ts CHANGED
@@ -12,6 +12,11 @@ export declare class Vec3 extends Vector3 {
12
12
  * @returns A new Vec3 instance.
13
13
  */
14
14
  static fromPoint(point: Point3): Vec3;
15
+ /**
16
+ * Creates a new Vec3[] array from arguments of {x, y, z} objects.
17
+ * @param points - The ...{x, y, z} instances.
18
+ */
19
+ static fromPoints(...points: Point3[]): Vec3[];
15
20
  /**
16
21
  * Moves this Vec3 instance towards the target Vec3 by the given amount.
17
22
  * @param target - The target Vec3.