@immugio/three-math-extensions 0.2.24 → 0.2.26
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 +118 -3
- package/cjs/Line2D.js +2 -2
- package/cjs/Polygon.js +5 -0
- package/docs/classes/BoundingBox.md +7 -7
- package/docs/classes/Line2D.md +69 -67
- package/docs/classes/Line3D.md +35 -35
- package/docs/classes/Polygon.md +51 -15
- package/docs/classes/Rectangle.md +17 -17
- package/docs/classes/Size2.md +3 -3
- package/docs/classes/Vec2.md +10 -10
- package/docs/classes/Vec3.md +13 -13
- package/docs/interfaces/Point2.md +2 -2
- package/docs/interfaces/Point3.md +3 -3
- package/docs/modules.md +30 -8
- package/esm/Line2D.js +2 -2
- package/esm/Polygon.js +5 -0
- package/package.json +1 -1
- package/src/Line2D.ts +3 -3
- package/src/Polygon.ts +10 -4
- package/types/Line2D.d.ts +2 -2
- package/types/Polygon.d.ts +4 -3
package/docs/classes/Vec2.md
CHANGED
|
@@ -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/
|
|
77
|
+
[src/Vec2.ts:53](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
99
|
+
[src/Vec2.ts:44](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
123
|
+
[src/Vec2.ts:78](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
147
|
+
[src/Vec2.ts:86](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
172
|
+
[src/Vec2.ts:34](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
195
|
+
[src/Vec2.ts:107](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
219
|
+
[src/Vec2.ts:63](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
235
|
+
[src/Vec2.ts:97](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
259
|
+
[src/Vec2.ts:16](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
282
|
+
[src/Vec2.ts:24](https://github.com/Immugio/three-math-extensions/blob/e397290/src/Vec2.ts#L24)
|
package/docs/classes/Vec3.md
CHANGED
|
@@ -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/
|
|
81
|
+
[src/Vec3.ts:73](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
103
|
+
[src/Vec3.ts:64](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
125
|
+
[src/Vec3.ts:82](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
143
|
+
[src/Vec3.ts:131](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
165
|
+
[src/Vec3.ts:91](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
187
|
+
[src/Vec3.ts:115](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
211
|
+
[src/Vec3.ts:123](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
235
|
+
[src/Vec3.ts:51](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
260
|
+
[src/Vec3.ts:35](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
276
|
+
[src/Vec3.ts:107](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
292
|
+
[src/Vec3.ts:100](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
316
|
+
[src/Vec3.ts:17](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
338
|
+
[src/Vec3.ts:25](https://github.com/Immugio/three-math-extensions/blob/e397290/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/
|
|
20
|
+
[src/Point2.ts:2](https://github.com/Immugio/three-math-extensions/blob/e397290/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/e397290/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/
|
|
21
|
+
[src/Point3.ts:2](https://github.com/Immugio/three-math-extensions/blob/e397290/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/e397290/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/e397290/src/Point3.ts#L4)
|
package/docs/modules.md
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
- [isPointInPolygon](modules.md#ispointinpolygon)
|
|
34
34
|
- [normalizeAngleDegrees](modules.md#normalizeangledegrees)
|
|
35
35
|
- [normalizeAngleRadians](modules.md#normalizeangleradians)
|
|
36
|
+
- [polygonPerimeter](modules.md#polygonperimeter)
|
|
36
37
|
|
|
37
38
|
## Variables
|
|
38
39
|
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
|
|
43
44
|
#### Defined in
|
|
44
45
|
|
|
45
|
-
[src/MathConstants.ts:2](https://github.com/Immugio/three-math-extensions/blob/
|
|
46
|
+
[src/MathConstants.ts:2](https://github.com/Immugio/three-math-extensions/blob/e397290/src/MathConstants.ts#L2)
|
|
46
47
|
|
|
47
48
|
___
|
|
48
49
|
|
|
@@ -52,7 +53,7 @@ ___
|
|
|
52
53
|
|
|
53
54
|
#### Defined in
|
|
54
55
|
|
|
55
|
-
[src/MathConstants.ts:1](https://github.com/Immugio/three-math-extensions/blob/
|
|
56
|
+
[src/MathConstants.ts:1](https://github.com/Immugio/three-math-extensions/blob/e397290/src/MathConstants.ts#L1)
|
|
56
57
|
|
|
57
58
|
___
|
|
58
59
|
|
|
@@ -73,7 +74,7 @@ ___
|
|
|
73
74
|
|
|
74
75
|
#### Defined in
|
|
75
76
|
|
|
76
|
-
[src/directions.ts:3](https://github.com/Immugio/three-math-extensions/blob/
|
|
77
|
+
[src/directions.ts:3](https://github.com/Immugio/three-math-extensions/blob/e397290/src/directions.ts#L3)
|
|
77
78
|
|
|
78
79
|
___
|
|
79
80
|
|
|
@@ -92,7 +93,7 @@ ___
|
|
|
92
93
|
|
|
93
94
|
#### Defined in
|
|
94
95
|
|
|
95
|
-
[src/directions2d.ts:3](https://github.com/Immugio/three-math-extensions/blob/
|
|
96
|
+
[src/directions2d.ts:3](https://github.com/Immugio/three-math-extensions/blob/e397290/src/directions2d.ts#L3)
|
|
96
97
|
|
|
97
98
|
## Functions
|
|
98
99
|
|
|
@@ -119,7 +120,7 @@ ___
|
|
|
119
120
|
|
|
120
121
|
#### Defined in
|
|
121
122
|
|
|
122
|
-
[src/isContinuousClosedShape.ts:4](https://github.com/Immugio/three-math-extensions/blob/
|
|
123
|
+
[src/isContinuousClosedShape.ts:4](https://github.com/Immugio/three-math-extensions/blob/e397290/src/isContinuousClosedShape.ts#L4)
|
|
123
124
|
|
|
124
125
|
___
|
|
125
126
|
|
|
@@ -140,7 +141,7 @@ ___
|
|
|
140
141
|
|
|
141
142
|
#### Defined in
|
|
142
143
|
|
|
143
|
-
[src/isPointInPolygon.ts:3](https://github.com/Immugio/three-math-extensions/blob/
|
|
144
|
+
[src/isPointInPolygon.ts:3](https://github.com/Immugio/three-math-extensions/blob/e397290/src/isPointInPolygon.ts#L3)
|
|
144
145
|
|
|
145
146
|
___
|
|
146
147
|
|
|
@@ -162,7 +163,7 @@ Normalizes an angle in degrees to the range [0, 360].
|
|
|
162
163
|
|
|
163
164
|
#### Defined in
|
|
164
165
|
|
|
165
|
-
[src/normalizeAngleDegrees.ts:5](https://github.com/Immugio/three-math-extensions/blob/
|
|
166
|
+
[src/normalizeAngleDegrees.ts:5](https://github.com/Immugio/three-math-extensions/blob/e397290/src/normalizeAngleDegrees.ts#L5)
|
|
166
167
|
|
|
167
168
|
___
|
|
168
169
|
|
|
@@ -184,4 +185,25 @@ Normalize an angle in radians to the range of 0 to 2π.
|
|
|
184
185
|
|
|
185
186
|
#### Defined in
|
|
186
187
|
|
|
187
|
-
[src/normalizeAngleRadians.ts:7](https://github.com/Immugio/three-math-extensions/blob/
|
|
188
|
+
[src/normalizeAngleRadians.ts:7](https://github.com/Immugio/three-math-extensions/blob/e397290/src/normalizeAngleRadians.ts#L7)
|
|
189
|
+
|
|
190
|
+
___
|
|
191
|
+
|
|
192
|
+
### polygonPerimeter
|
|
193
|
+
|
|
194
|
+
▸ **polygonPerimeter**(`polygon`, `forceClosedPolygon?`): `number`
|
|
195
|
+
|
|
196
|
+
#### Parameters
|
|
197
|
+
|
|
198
|
+
| Name | Type | Default value |
|
|
199
|
+
| :------ | :------ | :------ |
|
|
200
|
+
| `polygon` | [`Vec2`](classes/Vec2.md)[] | `undefined` |
|
|
201
|
+
| `forceClosedPolygon` | `boolean` | `false` |
|
|
202
|
+
|
|
203
|
+
#### Returns
|
|
204
|
+
|
|
205
|
+
`number`
|
|
206
|
+
|
|
207
|
+
#### Defined in
|
|
208
|
+
|
|
209
|
+
[src/polygonPerimeter.ts:3](https://github.com/Immugio/three-math-extensions/blob/e397290/src/polygonPerimeter.ts#L3)
|
package/esm/Line2D.js
CHANGED
|
@@ -457,7 +457,7 @@ export class Line2D {
|
|
|
457
457
|
* @param source
|
|
458
458
|
* @param clips
|
|
459
459
|
*/
|
|
460
|
-
static clipLines(source, clips) {
|
|
460
|
+
static clipLines(source, clips, distanceTolerance = 0, parallelTolerance = 0) {
|
|
461
461
|
if (!clips || clips.length === 0)
|
|
462
462
|
return [source];
|
|
463
463
|
clips = clips.map(c => {
|
|
@@ -473,7 +473,7 @@ export class Line2D {
|
|
|
473
473
|
let isFree = true;
|
|
474
474
|
const tested = sources.pop();
|
|
475
475
|
for (const cover of clips) {
|
|
476
|
-
if (tested.overlaps(cover)) {
|
|
476
|
+
if (tested.overlaps(cover, distanceTolerance, parallelTolerance)) {
|
|
477
477
|
isFree = false;
|
|
478
478
|
const subtracted = this.subtractSingle(tested, cover);
|
|
479
479
|
sources.push(...subtracted);
|
package/esm/Polygon.js
CHANGED
|
@@ -98,6 +98,11 @@ export class Polygon {
|
|
|
98
98
|
point.x = point.x < centerX ? centerX + xDistanceToCenter : centerX - xDistanceToCenter;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
+
translate(translate) {
|
|
102
|
+
this.contour.forEach(p => p.add(translate));
|
|
103
|
+
this.holes?.forEach(hole => hole.forEach(p => p.add(translate)));
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
101
106
|
toRectangle() {
|
|
102
107
|
const bounding = this.boundingBox();
|
|
103
108
|
return new Rectangle(bounding.minX, bounding.maxX, bounding.minY, bounding.maxY);
|
package/package.json
CHANGED
package/src/Line2D.ts
CHANGED
|
@@ -504,7 +504,7 @@ export class Line2D {
|
|
|
504
504
|
return target.subVectors(this.end, this.start);
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
-
public closestPointToPointParameter(point, clampToLine): number {
|
|
507
|
+
public closestPointToPointParameter(point: Vector2, clampToLine: boolean): number {
|
|
508
508
|
_startP.subVectors(point, this.start);
|
|
509
509
|
_startEnd.subVectors(this.end, this.start);
|
|
510
510
|
|
|
@@ -538,7 +538,7 @@ export class Line2D {
|
|
|
538
538
|
* @param source
|
|
539
539
|
* @param clips
|
|
540
540
|
*/
|
|
541
|
-
public static clipLines(source: Line2D, clips: Line2D[]): Line2D[] {
|
|
541
|
+
public static clipLines(source: Line2D, clips: Line2D[], distanceTolerance: number = 0, parallelTolerance: number = 0): Line2D[] {
|
|
542
542
|
if (!clips || clips.length === 0) return [source];
|
|
543
543
|
|
|
544
544
|
clips = clips.map(c => {
|
|
@@ -560,7 +560,7 @@ export class Line2D {
|
|
|
560
560
|
|
|
561
561
|
for (const cover of clips) {
|
|
562
562
|
|
|
563
|
-
if (tested.overlaps(cover)) {
|
|
563
|
+
if (tested.overlaps(cover, distanceTolerance, parallelTolerance)) {
|
|
564
564
|
isFree = false;
|
|
565
565
|
const subtracted = this.subtractSingle(tested, cover);
|
|
566
566
|
sources.push(...subtracted);
|
package/src/Polygon.ts
CHANGED
|
@@ -28,7 +28,7 @@ export class Polygon {
|
|
|
28
28
|
return new Vec2(maxX - minX, maxY - minY);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
public centerOnOrigin():
|
|
31
|
+
public centerOnOrigin(): this {
|
|
32
32
|
const center = this.center();
|
|
33
33
|
|
|
34
34
|
function centerPoints(points: Vec2[]): void {
|
|
@@ -56,7 +56,7 @@ export class Polygon {
|
|
|
56
56
|
return new Vec2(x, y);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
public ensureLastPoint():
|
|
59
|
+
public ensureLastPoint(): this {
|
|
60
60
|
function ensure(points: Vec2[]): void {
|
|
61
61
|
if (!points[0].equals(points.at(-1))) {
|
|
62
62
|
points.push(points[0].clone());
|
|
@@ -95,7 +95,7 @@ export class Polygon {
|
|
|
95
95
|
]);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
public flip():
|
|
98
|
+
public flip(): this {
|
|
99
99
|
const centerX = this.center().x;
|
|
100
100
|
this.flipSingle(centerX, this.contour);
|
|
101
101
|
this.holes?.forEach(hole => this.flipSingle(centerX, hole));
|
|
@@ -110,13 +110,19 @@ export class Polygon {
|
|
|
110
110
|
return isPointInPolygon(this.contour, point) && (this.holes || []).every(hole => !isPointInPolygon(hole, point));
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
private flipSingle(centerX: number, poly: Vec2[]) {
|
|
113
|
+
private flipSingle(centerX: number, poly: Vec2[]): void {
|
|
114
114
|
for (const point of poly) {
|
|
115
115
|
const xDistanceToCenter = Math.abs(centerX - point.x);
|
|
116
116
|
point.x = point.x < centerX ? centerX + xDistanceToCenter : centerX - xDistanceToCenter;
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
public translate(translate: Vec2): this {
|
|
121
|
+
this.contour.forEach(p => p.add(translate));
|
|
122
|
+
this.holes?.forEach(hole => hole.forEach(p => p.add(translate)));
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
|
|
120
126
|
public toRectangle(): Rectangle {
|
|
121
127
|
const bounding = this.boundingBox();
|
|
122
128
|
return new Rectangle(bounding.minX, bounding.maxX, bounding.minY, bounding.maxY);
|
package/types/Line2D.d.ts
CHANGED
|
@@ -185,7 +185,7 @@ export declare class Line2D {
|
|
|
185
185
|
*/
|
|
186
186
|
closestPointToPoint(point: Vector2, clampToLine?: boolean, target?: Vec2): Vec2;
|
|
187
187
|
delta(target: Vec2): Vec2;
|
|
188
|
-
closestPointToPointParameter(point:
|
|
188
|
+
closestPointToPointParameter(point: Vector2, clampToLine: boolean): number;
|
|
189
189
|
/**
|
|
190
190
|
* Returns the distance between the **infinite** line and the point.
|
|
191
191
|
* @param point
|
|
@@ -198,7 +198,7 @@ export declare class Line2D {
|
|
|
198
198
|
* @param source
|
|
199
199
|
* @param clips
|
|
200
200
|
*/
|
|
201
|
-
static clipLines(source: Line2D, clips: Line2D[]): Line2D[];
|
|
201
|
+
static clipLines(source: Line2D, clips: Line2D[], distanceTolerance?: number, parallelTolerance?: number): Line2D[];
|
|
202
202
|
/**
|
|
203
203
|
* Returns the original line section split into two parts, if the line **sections** overlap, otherwise null
|
|
204
204
|
*/
|
package/types/Polygon.d.ts
CHANGED
|
@@ -9,15 +9,16 @@ export declare class Polygon {
|
|
|
9
9
|
static fromPoints(contour: Point2[], holes?: Point2[][]): Polygon;
|
|
10
10
|
static fromSize(width: number, height: number): Polygon;
|
|
11
11
|
get size(): Vec2;
|
|
12
|
-
centerOnOrigin():
|
|
12
|
+
centerOnOrigin(): this;
|
|
13
13
|
center(): Vec2;
|
|
14
|
-
ensureLastPoint():
|
|
14
|
+
ensureLastPoint(): this;
|
|
15
15
|
boundingBox(): BoundingBox;
|
|
16
16
|
toBoundingPolygon(): Polygon;
|
|
17
|
-
flip():
|
|
17
|
+
flip(): this;
|
|
18
18
|
perimeter(): number;
|
|
19
19
|
containsPoint(point: Vec2): boolean;
|
|
20
20
|
private flipSingle;
|
|
21
|
+
translate(translate: Vec2): this;
|
|
21
22
|
toRectangle(): Rectangle;
|
|
22
23
|
clone(): Polygon;
|
|
23
24
|
equals(other: Polygon): boolean;
|