@immugio/three-math-extensions 0.2.21 → 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.
- package/CHANGELOG.md +18 -96
- package/README.md +183 -1
- package/cjs/Line2D.js +79 -12
- package/cjs/Line3D.js +1 -1
- package/docs/classes/BoundingBox.md +13 -9
- package/docs/classes/Line2D.md +325 -80
- package/docs/classes/Line3D.md +155 -84
- package/docs/classes/Polygon.md +23 -19
- package/docs/classes/Rectangle.md +23 -19
- package/docs/classes/Size2.md +9 -5
- package/docs/classes/Vec2.md +62 -12
- package/docs/classes/Vec3.md +65 -15
- package/docs/interfaces/Point2.md +3 -3
- package/docs/interfaces/Point3.md +4 -4
- package/docs/modules.md +86 -5
- package/esm/Line2D.js +79 -12
- package/esm/Line3D.js +1 -1
- package/package.json +1 -1
- package/src/Line2D.ts +93 -12
- package/src/Line3D.ts +1 -1
- package/types/Line2D.d.ts +28 -2
- package/types/Line3D.d.ts +1 -1
- package/docs/README.md +0 -90
package/docs/classes/Vec3.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[@immugio/three-math-extensions](
|
|
1
|
+
[@immugio/three-math-extensions](../../README.md) / [Exports](../modules.md) / Vec3
|
|
2
2
|
|
|
3
3
|
# Class: Vec3
|
|
4
4
|
|
|
@@ -20,6 +20,7 @@ Vec3 represents a 3D vector. It extends `Vector3` from the `threejs` library.
|
|
|
20
20
|
|
|
21
21
|
- [addX](Vec3.md#addx)
|
|
22
22
|
- [addY](Vec3.md#addy)
|
|
23
|
+
- [addZ](Vec3.md#addz)
|
|
23
24
|
- [clone](Vec3.md#clone)
|
|
24
25
|
- [closest](Vec3.md#closest)
|
|
25
26
|
- [horizontalDistanceTo](Vec3.md#horizontaldistanceto)
|
|
@@ -29,12 +30,13 @@ Vec3 represents a 3D vector. It extends `Vector3` from the `threejs` library.
|
|
|
29
30
|
- [onPlan](Vec3.md#onplan)
|
|
30
31
|
- [toPointWithFlippedYZ](Vec3.md#topointwithflippedyz)
|
|
31
32
|
- [fromPoint](Vec3.md#frompoint)
|
|
33
|
+
- [fromPoints](Vec3.md#frompoints)
|
|
32
34
|
|
|
33
35
|
## Constructors
|
|
34
36
|
|
|
35
37
|
### constructor
|
|
36
38
|
|
|
37
|
-
• **new Vec3**(`x?`, `y?`, `z?`)
|
|
39
|
+
• **new Vec3**(`x?`, `y?`, `z?`): [`Vec3`](Vec3.md)
|
|
38
40
|
|
|
39
41
|
#### Parameters
|
|
40
42
|
|
|
@@ -44,13 +46,17 @@ Vec3 represents a 3D vector. It extends `Vector3` from the `threejs` library.
|
|
|
44
46
|
| `y?` | `number` |
|
|
45
47
|
| `z?` | `number` |
|
|
46
48
|
|
|
49
|
+
#### Returns
|
|
50
|
+
|
|
51
|
+
[`Vec3`](Vec3.md)
|
|
52
|
+
|
|
47
53
|
#### Inherited from
|
|
48
54
|
|
|
49
55
|
Vector3.constructor
|
|
50
56
|
|
|
51
57
|
#### Defined in
|
|
52
58
|
|
|
53
|
-
node_modules/@types/three/src/math/Vector3.d.ts:
|
|
59
|
+
node_modules/@types/three/src/math/Vector3.d.ts:27
|
|
54
60
|
|
|
55
61
|
## Methods
|
|
56
62
|
|
|
@@ -72,7 +78,7 @@ Adds x amount to this Vec3 instance and return this
|
|
|
72
78
|
|
|
73
79
|
#### Defined in
|
|
74
80
|
|
|
75
|
-
[src/Vec3.ts:
|
|
81
|
+
[src/Vec3.ts:73](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L73)
|
|
76
82
|
|
|
77
83
|
___
|
|
78
84
|
|
|
@@ -94,7 +100,29 @@ Adds y amount to this Vec3 instance and return this
|
|
|
94
100
|
|
|
95
101
|
#### Defined in
|
|
96
102
|
|
|
97
|
-
[src/Vec3.ts:
|
|
103
|
+
[src/Vec3.ts:64](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L64)
|
|
104
|
+
|
|
105
|
+
___
|
|
106
|
+
|
|
107
|
+
### addZ
|
|
108
|
+
|
|
109
|
+
▸ **addZ**(`z`): [`Vec3`](Vec3.md)
|
|
110
|
+
|
|
111
|
+
Adds z amount to this Vec3 instance and return this
|
|
112
|
+
|
|
113
|
+
#### Parameters
|
|
114
|
+
|
|
115
|
+
| Name | Type |
|
|
116
|
+
| :------ | :------ |
|
|
117
|
+
| `z` | `number` |
|
|
118
|
+
|
|
119
|
+
#### Returns
|
|
120
|
+
|
|
121
|
+
[`Vec3`](Vec3.md)
|
|
122
|
+
|
|
123
|
+
#### Defined in
|
|
124
|
+
|
|
125
|
+
[src/Vec3.ts:82](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L82)
|
|
98
126
|
|
|
99
127
|
___
|
|
100
128
|
|
|
@@ -112,7 +140,7 @@ Vector3.clone
|
|
|
112
140
|
|
|
113
141
|
#### Defined in
|
|
114
142
|
|
|
115
|
-
[src/Vec3.ts:
|
|
143
|
+
[src/Vec3.ts:131](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L131)
|
|
116
144
|
|
|
117
145
|
___
|
|
118
146
|
|
|
@@ -134,7 +162,7 @@ Returns a clone of the point closest to this from the given points.
|
|
|
134
162
|
|
|
135
163
|
#### Defined in
|
|
136
164
|
|
|
137
|
-
[src/Vec3.ts:
|
|
165
|
+
[src/Vec3.ts:91](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L91)
|
|
138
166
|
|
|
139
167
|
___
|
|
140
168
|
|
|
@@ -156,7 +184,7 @@ Get distance to another vector while ignoring the y-axis.
|
|
|
156
184
|
|
|
157
185
|
#### Defined in
|
|
158
186
|
|
|
159
|
-
[src/Vec3.ts:
|
|
187
|
+
[src/Vec3.ts:115](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L115)
|
|
160
188
|
|
|
161
189
|
___
|
|
162
190
|
|
|
@@ -180,7 +208,7 @@ maxDistance is the maximum distance between the two vectors within which they ar
|
|
|
180
208
|
|
|
181
209
|
#### Defined in
|
|
182
210
|
|
|
183
|
-
[src/Vec3.ts:
|
|
211
|
+
[src/Vec3.ts:123](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L123)
|
|
184
212
|
|
|
185
213
|
___
|
|
186
214
|
|
|
@@ -204,7 +232,7 @@ This Vec3 instance.
|
|
|
204
232
|
|
|
205
233
|
#### Defined in
|
|
206
234
|
|
|
207
|
-
[src/Vec3.ts:
|
|
235
|
+
[src/Vec3.ts:51](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L51)
|
|
208
236
|
|
|
209
237
|
___
|
|
210
238
|
|
|
@@ -229,7 +257,7 @@ This Vec3 instance.
|
|
|
229
257
|
|
|
230
258
|
#### Defined in
|
|
231
259
|
|
|
232
|
-
[src/Vec3.ts:
|
|
260
|
+
[src/Vec3.ts:35](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L35)
|
|
233
261
|
|
|
234
262
|
___
|
|
235
263
|
|
|
@@ -245,7 +273,7 @@ Projects this Vec3 instance onto 2d plan. Vec3.z becomes Vec2.y and Vec3.y is ig
|
|
|
245
273
|
|
|
246
274
|
#### Defined in
|
|
247
275
|
|
|
248
|
-
[src/Vec3.ts:
|
|
276
|
+
[src/Vec3.ts:107](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L107)
|
|
249
277
|
|
|
250
278
|
___
|
|
251
279
|
|
|
@@ -261,13 +289,13 @@ Returns a clone of this Vec3 instance with y and z swapped.
|
|
|
261
289
|
|
|
262
290
|
#### Defined in
|
|
263
291
|
|
|
264
|
-
[src/Vec3.ts:
|
|
292
|
+
[src/Vec3.ts:100](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L100)
|
|
265
293
|
|
|
266
294
|
___
|
|
267
295
|
|
|
268
296
|
### fromPoint
|
|
269
297
|
|
|
270
|
-
▸
|
|
298
|
+
▸ **fromPoint**(`point`): [`Vec3`](Vec3.md)
|
|
271
299
|
|
|
272
300
|
Creates a new Vec3 instance from an {x, y, z} object.
|
|
273
301
|
|
|
@@ -285,4 +313,26 @@ A new Vec3 instance.
|
|
|
285
313
|
|
|
286
314
|
#### Defined in
|
|
287
315
|
|
|
288
|
-
[src/Vec3.ts:17](https://github.com/Immugio/three-math-extensions/blob/
|
|
316
|
+
[src/Vec3.ts:17](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L17)
|
|
317
|
+
|
|
318
|
+
___
|
|
319
|
+
|
|
320
|
+
### fromPoints
|
|
321
|
+
|
|
322
|
+
▸ **fromPoints**(`...points`): [`Vec3`](Vec3.md)[]
|
|
323
|
+
|
|
324
|
+
Creates a new Vec3[] array from arguments of {x, y, z} objects.
|
|
325
|
+
|
|
326
|
+
#### Parameters
|
|
327
|
+
|
|
328
|
+
| Name | Type | Description |
|
|
329
|
+
| :------ | :------ | :------ |
|
|
330
|
+
| `...points` | [`Point3`](../interfaces/Point3.md)[] | The ...{x, y, z} instances. |
|
|
331
|
+
|
|
332
|
+
#### Returns
|
|
333
|
+
|
|
334
|
+
[`Vec3`](Vec3.md)[]
|
|
335
|
+
|
|
336
|
+
#### Defined in
|
|
337
|
+
|
|
338
|
+
[src/Vec3.ts:25](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Vec3.ts#L25)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[@immugio/three-math-extensions](
|
|
1
|
+
[@immugio/three-math-extensions](../../README.md) / [Exports](../modules.md) / Point2
|
|
2
2
|
|
|
3
3
|
# Interface: Point2
|
|
4
4
|
|
|
@@ -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/
|
|
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/
|
|
30
|
+
[src/Point2.ts:3](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Point2.ts#L3)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[@immugio/three-math-extensions](
|
|
1
|
+
[@immugio/three-math-extensions](../../README.md) / [Exports](../modules.md) / Point3
|
|
2
2
|
|
|
3
3
|
# Interface: Point3
|
|
4
4
|
|
|
@@ -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/
|
|
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/
|
|
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/
|
|
41
|
+
[src/Point3.ts:4](https://github.com/Immugio/three-math-extensions/blob/336678b/src/Point3.ts#L4)
|
package/docs/modules.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[@immugio/three-math-extensions](README.md) / Exports
|
|
1
|
+
[@immugio/three-math-extensions](../README.md) / Exports
|
|
2
2
|
|
|
3
3
|
# @immugio/three-math-extensions
|
|
4
4
|
|
|
@@ -22,26 +22,107 @@
|
|
|
22
22
|
|
|
23
23
|
### Variables
|
|
24
24
|
|
|
25
|
+
- [HalfPI](modules.md#halfpi)
|
|
25
26
|
- [TwoPI](modules.md#twopi)
|
|
27
|
+
- [directions](modules.md#directions)
|
|
28
|
+
- [directions2d](modules.md#directions2d)
|
|
26
29
|
|
|
27
30
|
### Functions
|
|
28
31
|
|
|
32
|
+
- [isContinuousClosedShape](modules.md#iscontinuousclosedshape)
|
|
29
33
|
- [isPointInPolygon](modules.md#ispointinpolygon)
|
|
30
34
|
- [normalizeAngleDegrees](modules.md#normalizeangledegrees)
|
|
31
35
|
- [normalizeAngleRadians](modules.md#normalizeangleradians)
|
|
32
36
|
|
|
33
37
|
## Variables
|
|
34
38
|
|
|
39
|
+
### HalfPI
|
|
40
|
+
|
|
41
|
+
• `Const` **HalfPI**: `number`
|
|
42
|
+
|
|
43
|
+
#### Defined in
|
|
44
|
+
|
|
45
|
+
[src/MathConstants.ts:2](https://github.com/Immugio/three-math-extensions/blob/336678b/src/MathConstants.ts#L2)
|
|
46
|
+
|
|
47
|
+
___
|
|
48
|
+
|
|
35
49
|
### TwoPI
|
|
36
50
|
|
|
37
51
|
• `Const` **TwoPI**: `number`
|
|
38
52
|
|
|
39
53
|
#### Defined in
|
|
40
54
|
|
|
41
|
-
[src/MathConstants.ts:1](https://github.com/Immugio/three-math-extensions/blob/
|
|
55
|
+
[src/MathConstants.ts:1](https://github.com/Immugio/three-math-extensions/blob/336678b/src/MathConstants.ts#L1)
|
|
56
|
+
|
|
57
|
+
___
|
|
58
|
+
|
|
59
|
+
### directions
|
|
60
|
+
|
|
61
|
+
• `Const` **directions**: `Object`
|
|
62
|
+
|
|
63
|
+
#### Type declaration
|
|
64
|
+
|
|
65
|
+
| Name | Type |
|
|
66
|
+
| :------ | :------ |
|
|
67
|
+
| `Down` | [`Vec3`](classes/Vec3.md) |
|
|
68
|
+
| `East` | [`Vec3`](classes/Vec3.md) |
|
|
69
|
+
| `North` | [`Vec3`](classes/Vec3.md) |
|
|
70
|
+
| `South` | [`Vec3`](classes/Vec3.md) |
|
|
71
|
+
| `Up` | [`Vec3`](classes/Vec3.md) |
|
|
72
|
+
| `West` | [`Vec3`](classes/Vec3.md) |
|
|
73
|
+
|
|
74
|
+
#### Defined in
|
|
75
|
+
|
|
76
|
+
[src/directions.ts:3](https://github.com/Immugio/three-math-extensions/blob/336678b/src/directions.ts#L3)
|
|
77
|
+
|
|
78
|
+
___
|
|
79
|
+
|
|
80
|
+
### directions2d
|
|
81
|
+
|
|
82
|
+
• `Const` **directions2d**: `Object`
|
|
83
|
+
|
|
84
|
+
#### Type declaration
|
|
85
|
+
|
|
86
|
+
| Name | Type |
|
|
87
|
+
| :------ | :------ |
|
|
88
|
+
| `Down` | [`Vec2`](classes/Vec2.md) |
|
|
89
|
+
| `Left` | [`Vec2`](classes/Vec2.md) |
|
|
90
|
+
| `Right` | [`Vec2`](classes/Vec2.md) |
|
|
91
|
+
| `Up` | [`Vec2`](classes/Vec2.md) |
|
|
92
|
+
|
|
93
|
+
#### Defined in
|
|
94
|
+
|
|
95
|
+
[src/directions2d.ts:3](https://github.com/Immugio/three-math-extensions/blob/336678b/src/directions2d.ts#L3)
|
|
42
96
|
|
|
43
97
|
## Functions
|
|
44
98
|
|
|
99
|
+
### isContinuousClosedShape
|
|
100
|
+
|
|
101
|
+
▸ **isContinuousClosedShape**\<`T`\>(`lines`, `tolerance?`): `boolean`
|
|
102
|
+
|
|
103
|
+
#### Type parameters
|
|
104
|
+
|
|
105
|
+
| Name | Type |
|
|
106
|
+
| :------ | :------ |
|
|
107
|
+
| `T` | extends [`Line3D`](classes/Line3D.md) \| [`Line2D`](classes/Line2D.md) |
|
|
108
|
+
|
|
109
|
+
#### Parameters
|
|
110
|
+
|
|
111
|
+
| Name | Type | Default value |
|
|
112
|
+
| :------ | :------ | :------ |
|
|
113
|
+
| `lines` | `T`[] | `undefined` |
|
|
114
|
+
| `tolerance` | `number` | `0` |
|
|
115
|
+
|
|
116
|
+
#### Returns
|
|
117
|
+
|
|
118
|
+
`boolean`
|
|
119
|
+
|
|
120
|
+
#### Defined in
|
|
121
|
+
|
|
122
|
+
[src/isContinuousClosedShape.ts:4](https://github.com/Immugio/three-math-extensions/blob/336678b/src/isContinuousClosedShape.ts#L4)
|
|
123
|
+
|
|
124
|
+
___
|
|
125
|
+
|
|
45
126
|
### isPointInPolygon
|
|
46
127
|
|
|
47
128
|
▸ **isPointInPolygon**(`p`, `point`): `boolean`
|
|
@@ -59,7 +140,7 @@
|
|
|
59
140
|
|
|
60
141
|
#### Defined in
|
|
61
142
|
|
|
62
|
-
[src/isPointInPolygon.ts:3](https://github.com/Immugio/three-math-extensions/blob/
|
|
143
|
+
[src/isPointInPolygon.ts:3](https://github.com/Immugio/three-math-extensions/blob/336678b/src/isPointInPolygon.ts#L3)
|
|
63
144
|
|
|
64
145
|
___
|
|
65
146
|
|
|
@@ -81,7 +162,7 @@ Normalizes an angle in degrees to the range [0, 360].
|
|
|
81
162
|
|
|
82
163
|
#### Defined in
|
|
83
164
|
|
|
84
|
-
[src/normalizeAngleDegrees.ts:5](https://github.com/Immugio/three-math-extensions/blob/
|
|
165
|
+
[src/normalizeAngleDegrees.ts:5](https://github.com/Immugio/three-math-extensions/blob/336678b/src/normalizeAngleDegrees.ts#L5)
|
|
85
166
|
|
|
86
167
|
___
|
|
87
168
|
|
|
@@ -103,4 +184,4 @@ Normalize an angle in radians to the range of 0 to 2π.
|
|
|
103
184
|
|
|
104
185
|
#### Defined in
|
|
105
186
|
|
|
106
|
-
[src/normalizeAngleRadians.ts:7](https://github.com/Immugio/three-math-extensions/blob/
|
|
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";
|
|
@@ -10,6 +9,7 @@ export class Line2D {
|
|
|
10
9
|
start;
|
|
11
10
|
end;
|
|
12
11
|
index;
|
|
12
|
+
#target = new Vec2();
|
|
13
13
|
constructor(start, end, index = 0) {
|
|
14
14
|
this.start = start;
|
|
15
15
|
this.end = end;
|
|
@@ -138,6 +138,41 @@ export class Line2D {
|
|
|
138
138
|
get endpoints() {
|
|
139
139
|
return [this.start, this.end];
|
|
140
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Check that this line segment contains provided point.
|
|
143
|
+
* @param p
|
|
144
|
+
* @param tolerance
|
|
145
|
+
*/
|
|
146
|
+
containsPoint(p, tolerance = 0) {
|
|
147
|
+
const closestPointToPoint = this.closestPointToPoint(p, true, this.#target);
|
|
148
|
+
return closestPointToPoint.distanceTo(p) <= tolerance;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Distance from this line to the provided point.
|
|
152
|
+
* @param param
|
|
153
|
+
* @param clampToLine
|
|
154
|
+
*/
|
|
155
|
+
distanceToPoint(p, clampToLine = true) {
|
|
156
|
+
const closestPointToPoint = this.closestPointToPoint(p, clampToLine, this.#target);
|
|
157
|
+
return closestPointToPoint.distanceTo(p);
|
|
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
|
+
}
|
|
141
176
|
/**
|
|
142
177
|
* Returns the direction of this line.
|
|
143
178
|
*/
|
|
@@ -149,9 +184,9 @@ export class Line2D {
|
|
|
149
184
|
* Modifies this line.
|
|
150
185
|
*/
|
|
151
186
|
flip() {
|
|
152
|
-
|
|
187
|
+
this.#target.copy(this.start);
|
|
153
188
|
this.start.copy(this.end);
|
|
154
|
-
this.end.copy(
|
|
189
|
+
this.end.copy(this.#target);
|
|
155
190
|
return this;
|
|
156
191
|
}
|
|
157
192
|
/**
|
|
@@ -245,14 +280,32 @@ export class Line2D {
|
|
|
245
280
|
/**
|
|
246
281
|
* Returns true if there is any overlap between this line and the @other line section.
|
|
247
282
|
*/
|
|
248
|
-
overlaps(other) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
if (this.start.equals(other.start) && this.end.equals(other.end)) {
|
|
283
|
+
overlaps(other, distanceTolerance = 0, parallelTolerance = 0) {
|
|
284
|
+
// Special case
|
|
285
|
+
if (this.equals(other, distanceTolerance)) {
|
|
253
286
|
return true;
|
|
254
287
|
}
|
|
255
|
-
|
|
288
|
+
// Always have to be parallel
|
|
289
|
+
if (this.isParallelTo(other, parallelTolerance)) {
|
|
290
|
+
// To pass as overlapping, at least one point has to be within the other line, but they mush not be equal - "touching" is not considered overlapping
|
|
291
|
+
const otherStartEqualsToAnyOfThisPoint = other.start.distanceTo(this.start) <= distanceTolerance || other.start.distanceTo(this.end) <= distanceTolerance;
|
|
292
|
+
if (this.containsPoint(other.start, distanceTolerance) && !otherStartEqualsToAnyOfThisPoint) {
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
const otherEndEqualsToAnyOfThisPoint = other.end.distanceTo(this.start) <= distanceTolerance || other.end.distanceTo(this.end) <= distanceTolerance;
|
|
296
|
+
if (this.containsPoint(other.end, distanceTolerance) && !otherEndEqualsToAnyOfThisPoint) {
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
const thisStartEqualsToAnyOfOtherPoint = this.start.distanceTo(other.start) <= distanceTolerance || this.start.distanceTo(other.end) <= distanceTolerance;
|
|
300
|
+
if (other.containsPoint(this.start, distanceTolerance) && !thisStartEqualsToAnyOfOtherPoint) {
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
const thisEndEqualsToAnyOfOtherPoint = this.end.distanceTo(other.start) <= distanceTolerance || this.end.distanceTo(other.end) <= distanceTolerance;
|
|
304
|
+
if (other.containsPoint(this.end, distanceTolerance) && !thisEndEqualsToAnyOfOtherPoint) {
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return false;
|
|
256
309
|
}
|
|
257
310
|
/**
|
|
258
311
|
* Logical AND of this and the other line section.
|
|
@@ -324,6 +377,17 @@ export class Line2D {
|
|
|
324
377
|
}
|
|
325
378
|
return result;
|
|
326
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* Checks if the current line covers another line.
|
|
382
|
+
* A line is considered to cover another line if they are parallel and both the start and end points of the other line are contained within the current line.
|
|
383
|
+
* Both distance and angle tolerance can be provided.
|
|
384
|
+
*/
|
|
385
|
+
covers(other, tolerance = 0, parallelTolerance = 0) {
|
|
386
|
+
if (!this.isParallelTo(other, parallelTolerance)) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
return this.containsPoint(other.start, tolerance) && this.containsPoint(other.end, tolerance);
|
|
390
|
+
}
|
|
327
391
|
/**
|
|
328
392
|
* Returns a new line that is the projection of this line onto @other. Uses `closestPointToPoint` to find the projection.
|
|
329
393
|
* @param other
|
|
@@ -640,8 +704,11 @@ export class Line2D {
|
|
|
640
704
|
in3DSpace(y = 0) {
|
|
641
705
|
return new Line3D(this.start.in3DSpace(y), this.end.in3DSpace(y));
|
|
642
706
|
}
|
|
643
|
-
equals(other) {
|
|
644
|
-
|
|
707
|
+
equals(other, tolerance = 0) {
|
|
708
|
+
if (!tolerance) {
|
|
709
|
+
return !!other && this.start.equals(other.start) && this.end.equals(other.end);
|
|
710
|
+
}
|
|
711
|
+
return !!other && this.start.distanceTo(other.start) <= tolerance && this.end.distanceTo(other.end) <= tolerance;
|
|
645
712
|
}
|
|
646
713
|
/**
|
|
647
714
|
* Deep clone of this line
|
package/esm/Line3D.js
CHANGED
|
@@ -250,7 +250,7 @@ export class Line3D extends Line3 {
|
|
|
250
250
|
return closestPointToPoint.distanceTo(p) <= tolerance;
|
|
251
251
|
}
|
|
252
252
|
/**
|
|
253
|
-
* Distance from this line to provided point.
|
|
253
|
+
* Distance from this line to the provided point.
|
|
254
254
|
* @param p
|
|
255
255
|
* @param clampToLine
|
|
256
256
|
*/
|
package/package.json
CHANGED