@immugio/three-math-extensions 0.2.22 → 0.2.23

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.
@@ -74,7 +74,7 @@ Adds x amount to this Vec3 instance and return this
74
74
 
75
75
  #### Defined in
76
76
 
77
- [src/Vec2.ts:53](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec2.ts#L53)
77
+ [src/Vec2.ts:53](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec2.ts#L53)
78
78
 
79
79
  ___
80
80
 
@@ -96,7 +96,7 @@ Adds y amount to this Vec3 instance and return this
96
96
 
97
97
  #### Defined in
98
98
 
99
- [src/Vec2.ts:44](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec2.ts#L44)
99
+ [src/Vec2.ts:44](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec2.ts#L44)
100
100
 
101
101
  ___
102
102
 
@@ -120,7 +120,7 @@ A new Vec3 instance.
120
120
 
121
121
  #### Defined in
122
122
 
123
- [src/Vec2.ts:78](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec2.ts#L78)
123
+ [src/Vec2.ts:78](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec2.ts#L78)
124
124
 
125
125
  ___
126
126
 
@@ -144,7 +144,7 @@ maxDistance is the maximum distance between the two vectors within which they ar
144
144
 
145
145
  #### Defined in
146
146
 
147
- [src/Vec2.ts:86](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec2.ts#L86)
147
+ [src/Vec2.ts:86](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec2.ts#L86)
148
148
 
149
149
  ___
150
150
 
@@ -169,7 +169,7 @@ This Vec2 instance.
169
169
 
170
170
  #### Defined in
171
171
 
172
- [src/Vec2.ts:34](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec2.ts#L34)
172
+ [src/Vec2.ts:34](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec2.ts#L34)
173
173
 
174
174
  ___
175
175
 
@@ -192,7 +192,7 @@ check if the angle between the two vectors is close enough to 0 or 180 degrees (
192
192
 
193
193
  #### Defined in
194
194
 
195
- [src/Vec2.ts:107](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec2.ts#L107)
195
+ [src/Vec2.ts:107](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec2.ts#L107)
196
196
 
197
197
  ___
198
198
 
@@ -216,7 +216,7 @@ This Vec2 instance.
216
216
 
217
217
  #### Defined in
218
218
 
219
- [src/Vec2.ts:63](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec2.ts#L63)
219
+ [src/Vec2.ts:63](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec2.ts#L63)
220
220
 
221
221
  ___
222
222
 
@@ -232,7 +232,7 @@ Returns the angle between this vector and positive x-axis, the return value is b
232
232
 
233
233
  #### Defined in
234
234
 
235
- [src/Vec2.ts:97](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec2.ts#L97)
235
+ [src/Vec2.ts:97](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec2.ts#L97)
236
236
 
237
237
  ___
238
238
 
@@ -256,7 +256,7 @@ A new Vec2 instance.
256
256
 
257
257
  #### Defined in
258
258
 
259
- [src/Vec2.ts:16](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec2.ts#L16)
259
+ [src/Vec2.ts:16](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec2.ts#L16)
260
260
 
261
261
  ___
262
262
 
@@ -279,4 +279,4 @@ Creates a new Vec2[] array from arguments of {x, y} objects.
279
279
 
280
280
  #### Defined in
281
281
 
282
- [src/Vec2.ts:24](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec2.ts#L24)
282
+ [src/Vec2.ts:24](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec2.ts#L24)
@@ -78,7 +78,7 @@ Adds x amount to this Vec3 instance and return this
78
78
 
79
79
  #### Defined in
80
80
 
81
- [src/Vec3.ts:73](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L73)
81
+ [src/Vec3.ts:73](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L73)
82
82
 
83
83
  ___
84
84
 
@@ -100,7 +100,7 @@ Adds y amount to this Vec3 instance and return this
100
100
 
101
101
  #### Defined in
102
102
 
103
- [src/Vec3.ts:64](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L64)
103
+ [src/Vec3.ts:64](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L64)
104
104
 
105
105
  ___
106
106
 
@@ -122,7 +122,7 @@ Adds z amount to this Vec3 instance and return this
122
122
 
123
123
  #### Defined in
124
124
 
125
- [src/Vec3.ts:82](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L82)
125
+ [src/Vec3.ts:82](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L82)
126
126
 
127
127
  ___
128
128
 
@@ -140,7 +140,7 @@ Vector3.clone
140
140
 
141
141
  #### Defined in
142
142
 
143
- [src/Vec3.ts:131](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L131)
143
+ [src/Vec3.ts:131](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L131)
144
144
 
145
145
  ___
146
146
 
@@ -162,7 +162,7 @@ Returns a clone of the point closest to this from the given points.
162
162
 
163
163
  #### Defined in
164
164
 
165
- [src/Vec3.ts:91](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L91)
165
+ [src/Vec3.ts:91](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L91)
166
166
 
167
167
  ___
168
168
 
@@ -184,7 +184,7 @@ Get distance to another vector while ignoring the y-axis.
184
184
 
185
185
  #### Defined in
186
186
 
187
- [src/Vec3.ts:115](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L115)
187
+ [src/Vec3.ts:115](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L115)
188
188
 
189
189
  ___
190
190
 
@@ -208,7 +208,7 @@ maxDistance is the maximum distance between the two vectors within which they ar
208
208
 
209
209
  #### Defined in
210
210
 
211
- [src/Vec3.ts:123](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L123)
211
+ [src/Vec3.ts:123](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L123)
212
212
 
213
213
  ___
214
214
 
@@ -232,7 +232,7 @@ This Vec3 instance.
232
232
 
233
233
  #### Defined in
234
234
 
235
- [src/Vec3.ts:51](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L51)
235
+ [src/Vec3.ts:51](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L51)
236
236
 
237
237
  ___
238
238
 
@@ -257,7 +257,7 @@ This Vec3 instance.
257
257
 
258
258
  #### Defined in
259
259
 
260
- [src/Vec3.ts:35](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L35)
260
+ [src/Vec3.ts:35](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L35)
261
261
 
262
262
  ___
263
263
 
@@ -273,7 +273,7 @@ Projects this Vec3 instance onto 2d plan. Vec3.z becomes Vec2.y and Vec3.y is ig
273
273
 
274
274
  #### Defined in
275
275
 
276
- [src/Vec3.ts:107](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L107)
276
+ [src/Vec3.ts:107](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L107)
277
277
 
278
278
  ___
279
279
 
@@ -289,7 +289,7 @@ Returns a clone of this Vec3 instance with y and z swapped.
289
289
 
290
290
  #### Defined in
291
291
 
292
- [src/Vec3.ts:100](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L100)
292
+ [src/Vec3.ts:100](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L100)
293
293
 
294
294
  ___
295
295
 
@@ -313,7 +313,7 @@ A new Vec3 instance.
313
313
 
314
314
  #### Defined in
315
315
 
316
- [src/Vec3.ts:17](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L17)
316
+ [src/Vec3.ts:17](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L17)
317
317
 
318
318
  ___
319
319
 
@@ -335,4 +335,4 @@ Creates a new Vec3[] array from arguments of {x, y, z} objects.
335
335
 
336
336
  #### Defined in
337
337
 
338
- [src/Vec3.ts:25](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Vec3.ts#L25)
338
+ [src/Vec3.ts:25](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L25)
@@ -17,7 +17,7 @@
17
17
 
18
18
  #### Defined in
19
19
 
20
- [src/Point2.ts:2](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Point2.ts#L2)
20
+ [src/Point2.ts:2](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Point2.ts#L2)
21
21
 
22
22
  ___
23
23
 
@@ -27,4 +27,4 @@ ___
27
27
 
28
28
  #### Defined in
29
29
 
30
- [src/Point2.ts:3](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Point2.ts#L3)
30
+ [src/Point2.ts:3](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Point2.ts#L3)
@@ -18,7 +18,7 @@
18
18
 
19
19
  #### Defined in
20
20
 
21
- [src/Point3.ts:2](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Point3.ts#L2)
21
+ [src/Point3.ts:2](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Point3.ts#L2)
22
22
 
23
23
  ___
24
24
 
@@ -28,7 +28,7 @@ ___
28
28
 
29
29
  #### Defined in
30
30
 
31
- [src/Point3.ts:3](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Point3.ts#L3)
31
+ [src/Point3.ts:3](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Point3.ts#L3)
32
32
 
33
33
  ___
34
34
 
@@ -38,4 +38,4 @@ ___
38
38
 
39
39
  #### Defined in
40
40
 
41
- [src/Point3.ts:4](https://github.com/Immugio/three-math-extensions/blob/905d178/src/Point3.ts#L4)
41
+ [src/Point3.ts:4](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Point3.ts#L4)
package/docs/modules.md CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
  #### Defined in
44
44
 
45
- [src/MathConstants.ts:2](https://github.com/Immugio/three-math-extensions/blob/905d178/src/MathConstants.ts#L2)
45
+ [src/MathConstants.ts:2](https://github.com/Immugio/three-math-extensions/blob/336678b/src/MathConstants.ts#L2)
46
46
 
47
47
  ___
48
48
 
@@ -52,7 +52,7 @@ ___
52
52
 
53
53
  #### Defined in
54
54
 
55
- [src/MathConstants.ts:1](https://github.com/Immugio/three-math-extensions/blob/905d178/src/MathConstants.ts#L1)
55
+ [src/MathConstants.ts:1](https://github.com/Immugio/three-math-extensions/blob/336678b/src/MathConstants.ts#L1)
56
56
 
57
57
  ___
58
58
 
@@ -73,7 +73,7 @@ ___
73
73
 
74
74
  #### Defined in
75
75
 
76
- [src/directions.ts:3](https://github.com/Immugio/three-math-extensions/blob/905d178/src/directions.ts#L3)
76
+ [src/directions.ts:3](https://github.com/Immugio/three-math-extensions/blob/336678b/src/directions.ts#L3)
77
77
 
78
78
  ___
79
79
 
@@ -92,7 +92,7 @@ ___
92
92
 
93
93
  #### Defined in
94
94
 
95
- [src/directions2d.ts:3](https://github.com/Immugio/three-math-extensions/blob/905d178/src/directions2d.ts#L3)
95
+ [src/directions2d.ts:3](https://github.com/Immugio/three-math-extensions/blob/336678b/src/directions2d.ts#L3)
96
96
 
97
97
  ## Functions
98
98
 
@@ -119,7 +119,7 @@ ___
119
119
 
120
120
  #### Defined in
121
121
 
122
- [src/isContinuousClosedShape.ts:4](https://github.com/Immugio/three-math-extensions/blob/905d178/src/isContinuousClosedShape.ts#L4)
122
+ [src/isContinuousClosedShape.ts:4](https://github.com/Immugio/three-math-extensions/blob/336678b/src/isContinuousClosedShape.ts#L4)
123
123
 
124
124
  ___
125
125
 
@@ -140,7 +140,7 @@ ___
140
140
 
141
141
  #### Defined in
142
142
 
143
- [src/isPointInPolygon.ts:3](https://github.com/Immugio/three-math-extensions/blob/905d178/src/isPointInPolygon.ts#L3)
143
+ [src/isPointInPolygon.ts:3](https://github.com/Immugio/three-math-extensions/blob/336678b/src/isPointInPolygon.ts#L3)
144
144
 
145
145
  ___
146
146
 
@@ -162,7 +162,7 @@ Normalizes an angle in degrees to the range [0, 360].
162
162
 
163
163
  #### Defined in
164
164
 
165
- [src/normalizeAngleDegrees.ts:5](https://github.com/Immugio/three-math-extensions/blob/905d178/src/normalizeAngleDegrees.ts#L5)
165
+ [src/normalizeAngleDegrees.ts:5](https://github.com/Immugio/three-math-extensions/blob/336678b/src/normalizeAngleDegrees.ts#L5)
166
166
 
167
167
  ___
168
168
 
@@ -184,4 +184,4 @@ Normalize an angle in radians to the range of 0 to 2π.
184
184
 
185
185
  #### Defined in
186
186
 
187
- [src/normalizeAngleRadians.ts:7](https://github.com/Immugio/three-math-extensions/blob/905d178/src/normalizeAngleRadians.ts#L7)
187
+ [src/normalizeAngleRadians.ts:7](https://github.com/Immugio/three-math-extensions/blob/336678b/src/normalizeAngleRadians.ts#L7)
package/esm/Line2D.js CHANGED
@@ -1,6 +1,5 @@
1
- import { Vector2 } from "three";
1
+ import { MathUtils, Vector2 } from "three";
2
2
  import { Vec2 } from "./Vec2";
3
- import { MathUtils } from "three";
4
3
  import { TwoPI } from "./MathConstants";
5
4
  import { Line3D } from "./Line3D";
6
5
  import { directions2d } from "./directions2d";
@@ -157,6 +156,23 @@ export class Line2D {
157
156
  const closestPointToPoint = this.closestPointToPoint(p, clampToLine, this.#target);
158
157
  return closestPointToPoint.distanceTo(p);
159
158
  }
159
+ /**
160
+ * Returns a copy of @other line, the direction of @other is reversed if needed.
161
+ * Returns null if lines are not parallel.
162
+ * @param other
163
+ * @param parallelTolerance
164
+ */
165
+ getParallelLineInTheSameDirection(other, parallelTolerance = 0) {
166
+ const direction = this.direction;
167
+ if (direction.angleTo(other.direction) <= parallelTolerance) {
168
+ return other.clone();
169
+ }
170
+ const otherLineOppositeDirection = other.clone().flip();
171
+ if (otherLineOppositeDirection.direction.angleTo(direction) <= parallelTolerance) {
172
+ return otherLineOppositeDirection;
173
+ }
174
+ return null;
175
+ }
160
176
  /**
161
177
  * Returns the direction of this line.
162
178
  */
@@ -168,9 +184,9 @@ export class Line2D {
168
184
  * Modifies this line.
169
185
  */
170
186
  flip() {
171
- const temp = this.start.clone();
187
+ this.#target.copy(this.start);
172
188
  this.start.copy(this.end);
173
- this.end.copy(temp);
189
+ this.end.copy(this.#target);
174
190
  return this;
175
191
  }
176
192
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immugio/three-math-extensions",
3
- "version": "0.2.22",
3
+ "version": "0.2.23",
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
@@ -1,7 +1,6 @@
1
1
  import { Point2 } from "./Point2";
2
- import { Vector2 } from "three";
2
+ import { MathUtils, Vector2 } from "three";
3
3
  import { Vec2 } from "./Vec2";
4
- import { MathUtils } from "three";
5
4
  import { TwoPI } from "./MathConstants";
6
5
  import { Line3D } from "./Line3D";
7
6
  import { directions2d } from "./directions2d";
@@ -183,6 +182,27 @@ export class Line2D {
183
182
  return closestPointToPoint.distanceTo(p);
184
183
  }
185
184
 
185
+ /**
186
+ * Returns a copy of @other line, the direction of @other is reversed if needed.
187
+ * Returns null if lines are not parallel.
188
+ * @param other
189
+ * @param parallelTolerance
190
+ */
191
+ public getParallelLineInTheSameDirection(other: Line2D, parallelTolerance: number = 0): Line2D {
192
+ const direction = this.direction;
193
+
194
+ if (direction.angleTo(other.direction) <= parallelTolerance) {
195
+ return other.clone();
196
+ }
197
+
198
+ const otherLineOppositeDirection = other.clone().flip();
199
+ if (otherLineOppositeDirection.direction.angleTo(direction) <= parallelTolerance) {
200
+ return otherLineOppositeDirection;
201
+ }
202
+
203
+ return null;
204
+ }
205
+
186
206
  /**
187
207
  * Returns the direction of this line.
188
208
  */
@@ -195,9 +215,9 @@ export class Line2D {
195
215
  * Modifies this line.
196
216
  */
197
217
  public flip(): this {
198
- const temp = this.start.clone();
218
+ this.#target.copy(this.start);
199
219
  this.start.copy(this.end);
200
- this.end.copy(temp);
220
+ this.end.copy(this.#target);
201
221
 
202
222
  return this;
203
223
  }
package/types/Line2D.d.ts CHANGED
@@ -68,6 +68,13 @@ export declare class Line2D {
68
68
  * @param clampToLine
69
69
  */
70
70
  distanceToPoint(p: Vector2, clampToLine?: boolean): number;
71
+ /**
72
+ * Returns a copy of @other line, the direction of @other is reversed if needed.
73
+ * Returns null if lines are not parallel.
74
+ * @param other
75
+ * @param parallelTolerance
76
+ */
77
+ getParallelLineInTheSameDirection(other: Line2D, parallelTolerance?: number): Line2D;
71
78
  /**
72
79
  * Returns the direction of this line.
73
80
  */