@immugio/three-math-extensions 0.2.28 → 0.2.29
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 +25 -99
- package/cjs/Line2D.js +13 -3
- package/cjs/Polygon.js +27 -0
- package/cjs/extendOrTrimPolylinesAtIntersections.js +12 -0
- package/cjs/index.js +5 -1
- package/cjs/offsetPolyline.js +10 -0
- package/esm/Line2D.js +13 -3
- package/esm/Polygon.js +27 -0
- package/esm/extendOrTrimPolylinesAtIntersections.js +8 -0
- package/esm/index.js +2 -0
- package/esm/offsetPolyline.js +6 -0
- package/package.json +1 -1
- package/src/Line2D.ts +14 -3
- package/src/Polygon.ts +32 -0
- package/src/extendOrTrimPolylinesAtIntersections.ts +11 -0
- package/src/index.ts +3 -1
- package/src/offsetPolyline.ts +8 -0
- package/types/Line2D.d.ts +9 -1
- package/types/Polygon.d.ts +6 -0
- package/types/extendOrTrimPolylinesAtIntersections.d.ts +2 -0
- package/types/index.d.ts +2 -0
- package/types/offsetPolyline.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,64 +7,18 @@ 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.
|
|
10
|
+
## [0.2.29](https://github.com/Immugio/three-math-extensions/compare/0.2.28...0.2.29)
|
|
11
11
|
|
|
12
12
|
### Commits
|
|
13
13
|
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
- Add eslint [`98e4912`](https://github.com/Immugio/three-math-extensions/commit/98e4912d637b42ba80e2f3267638b43296113019)
|
|
17
|
-
- Update jest packages [`af23b4f`](https://github.com/Immugio/three-math-extensions/commit/af23b4f08154bba3407f05b773865215e7e1cba8)
|
|
18
|
-
- Add Rectangle, update Polygon [`58ee875`](https://github.com/Immugio/three-math-extensions/commit/58ee87539af8f9ade186e5250cba9e01926da514)
|
|
19
|
-
- Documentation update [`905d178`](https://github.com/Immugio/three-math-extensions/commit/905d1787ed7ffffa370b77454222ee04e76f35b5)
|
|
20
|
-
- Documentation update [`70a5f24`](https://github.com/Immugio/three-math-extensions/commit/70a5f243f8af83da3ad5d30e223788cbd877b5f0)
|
|
21
|
-
- Add isPointInPolygon [`a59eb4b`](https://github.com/Immugio/three-math-extensions/commit/a59eb4be026f17a3106070ae626a0588cd4f4411)
|
|
22
|
-
- Packages update [`c2ef857`](https://github.com/Immugio/three-math-extensions/commit/c2ef857c01792e64c1558424fdd2f401f72720d0)
|
|
23
|
-
- Improve Line2D.closestPointToPoint, add Vec2.signedAngle [`151f214`](https://github.com/Immugio/three-math-extensions/commit/151f21462e0358057ad8e9d75d5782563a1061f6)
|
|
24
|
-
- Add Line2D.containsPoint, Line2D.covers, Improve Line2D.equals, Line2D.overlaps, add unit tests [`7b6daf7`](https://github.com/Immugio/three-math-extensions/commit/7b6daf7028303313b6937c16514838604d89515d)
|
|
25
|
-
- Add Line2D.getParallelLineInTheSameDirection [`d2e0846`](https://github.com/Immugio/three-math-extensions/commit/d2e0846024fbb29cf0a29bd5889f6e5c6811e4cb)
|
|
26
|
-
- Documentation update [`fc82582`](https://github.com/Immugio/three-math-extensions/commit/fc82582fa7d6042d51bf9ac5841cc94346211f3d)
|
|
27
|
-
- Improve documentation [`d0fcb51`](https://github.com/Immugio/three-math-extensions/commit/d0fcb5132f127b4382ac5f7291575a061b8ec121)
|
|
28
|
-
- Add isContinuousClosedShape, add Line2D.groupConnectedLines [`4ef8c2f`](https://github.com/Immugio/three-math-extensions/commit/4ef8c2fe83fdc71dd87fee4cbc478ddf0a086442)
|
|
29
|
-
- Vec3, Line3D - update documentation [`67d9c32`](https://github.com/Immugio/three-math-extensions/commit/67d9c328e08cc0a5599932d2f0529e97f31c9213)
|
|
30
|
-
- Add Polygon.containsPoint and Polygon.perimeter [`9bdf2dd`](https://github.com/Immugio/three-math-extensions/commit/9bdf2ddb5823878b5d41dadf14a225f7a1f0fd8f)
|
|
31
|
-
- Add Polygon [`629cff8`](https://github.com/Immugio/three-math-extensions/commit/629cff8ecbb963477e8ea76d7f8b16d95435cbad)
|
|
32
|
-
- Line3D.groupConnectedLines added [`29f372b`](https://github.com/Immugio/three-math-extensions/commit/29f372bc984c06b00c50fcd9428ce9a7b9cab799)
|
|
33
|
-
- Dependencies update and remove now duplicate Vec2.angleTo implementation [`4774abb`](https://github.com/Immugio/three-math-extensions/commit/4774abb81d882082df0da606c79a3c7bd3aecc57)
|
|
34
|
-
- Line2D.isCloserToHorizontal [`b6f1429`](https://github.com/Immugio/three-math-extensions/commit/b6f14292d1d2765f7314c45e4c74be91280ac764)
|
|
35
|
-
- Add Vec2.angleTo and tests [`dcf1e53`](https://github.com/Immugio/three-math-extensions/commit/dcf1e531aecf8c115f323e14e5e44059e5c5d15c)
|
|
36
|
-
- Add Vec2.signedAngle [`863c8f2`](https://github.com/Immugio/three-math-extensions/commit/863c8f27f11288cbda535e21bb688206259269ed)
|
|
37
|
-
- Add parallelism check to Line2D [`18064ee`](https://github.com/Immugio/three-math-extensions/commit/18064ee35a28e2c4d656f3dfb543b545044167dd)
|
|
38
|
-
- Add Vec2.fromPoints to accept multiple points [`a261402`](https://github.com/Immugio/three-math-extensions/commit/a2614027cf5fb8263189b48f7e0bb9a23a552c15)
|
|
39
|
-
- Add Polygon.rotate [`4f2d581`](https://github.com/Immugio/three-math-extensions/commit/4f2d5814cdb3df067ab0a0cefcdfdb7a71696312)
|
|
40
|
-
- Add Vec2.parallelTo [`989874d`](https://github.com/Immugio/three-math-extensions/commit/989874dcfe122d3ee84d8d56d79cb88e4e441736)
|
|
41
|
-
- Line2D.intersect - enable line segments intersection only [`1f1470e`](https://github.com/Immugio/three-math-extensions/commit/1f1470e1cf00118e643f5c44a135e0baf6b76d41)
|
|
42
|
-
- Add Polygon.translate [`a77136a`](https://github.com/Immugio/three-math-extensions/commit/a77136aea1c2dbdbba725c14ba0bc2115ae56ffc)
|
|
43
|
-
- Line3D.groupConnectedLines now supports line breaks [`417a9ea`](https://github.com/Immugio/three-math-extensions/commit/417a9ea471bf4c539f73f5fb170c962a78ee4ab4)
|
|
44
|
-
- Add Line2D.projectOn [`4c52c5c`](https://github.com/Immugio/three-math-extensions/commit/4c52c5c2e649fbddb72ce3fca60cfd3f1319f72f)
|
|
45
|
-
- Line2D.clipLines to support tolerances [`e397290`](https://github.com/Immugio/three-math-extensions/commit/e3972909339f01f0c018ad49e14b958d18e489e5)
|
|
46
|
-
- Add functionality for incrementing x, y, z coordinates [`b292dcc`](https://github.com/Immugio/three-math-extensions/commit/b292dcc4e8f7f0f2a63e1810c482d96ca6bebebe)
|
|
47
|
-
- Add Line3D.index [`7ed13d2`](https://github.com/Immugio/three-math-extensions/commit/7ed13d213748056c9dafd86288c3bcec9a28d1ba)
|
|
48
|
-
- Add Polygon.roundIfCloseToInteger, Vec3.roundIfCloseToInteger [`ee9a90d`](https://github.com/Immugio/three-math-extensions/commit/ee9a90de07eb9827d1a53cdac65be3a51862cdc2)
|
|
49
|
-
- Polygon from bounding size [`eae6701`](https://github.com/Immugio/three-math-extensions/commit/eae67012f57f426f8b5259b765000447ce06d608)
|
|
50
|
-
- Add Vec3.fromPoints [`62684d7`](https://github.com/Immugio/three-math-extensions/commit/62684d7f6dc1318d345ed74288bb6afd5394e1d3)
|
|
51
|
-
- Line2D and Line3D to return this instead of specific type [`761ef6a`](https://github.com/Immugio/three-math-extensions/commit/761ef6a9d8cc4e35120b666576794e521aa3b991)
|
|
52
|
-
- Line2D.in3DSpace added [`a6ce0ec`](https://github.com/Immugio/three-math-extensions/commit/a6ce0ecb67f5c7b2a75fcc283c28af626153a4af)
|
|
53
|
-
- Line3D.connectsTo added [`6d2cfa0`](https://github.com/Immugio/three-math-extensions/commit/6d2cfa0f5335c665f325a694a32c57b574ec326d)
|
|
54
|
-
- Line2D.hasIntersectionWithAngle to support optional tolerance [`b313bbe`](https://github.com/Immugio/three-math-extensions/commit/b313bbe118d435d53750deefd9a9e29ba6ec5c71)
|
|
55
|
-
- Line2D.hasIntersectionWithAngle - modulo all angles [`5409aa0`](https://github.com/Immugio/three-math-extensions/commit/5409aa0bc41510efa86d548e91837e44e5b6c343)
|
|
56
|
-
- Use Vec2 instead of Vector2 [`7e6a6ea`](https://github.com/Immugio/three-math-extensions/commit/7e6a6ea272f4441ef4bc78b3fdec23fc783fa1db)
|
|
57
|
-
- Update release instructions [`5b41a2e`](https://github.com/Immugio/three-math-extensions/commit/5b41a2ed7e15450dbb6088a7f7ed0031a013badc)
|
|
58
|
-
- Add Polygon to exports [`ed66775`](https://github.com/Immugio/three-math-extensions/commit/ed66775c33e961835b23843222b822cfd9c16b1d)
|
|
59
|
-
- Vec2.fromPoint and Vec3.fromPoint should accept null [`4b871af`](https://github.com/Immugio/three-math-extensions/commit/4b871af297bdcbe8584f1e2b99d602247b77687c)
|
|
60
|
-
- Add HalfPI [`7a6614c`](https://github.com/Immugio/three-math-extensions/commit/7a6614c3d6f59ac216e58986927112f94207a755)
|
|
61
|
-
- Dependencies update [`e8def7e`](https://github.com/Immugio/three-math-extensions/commit/e8def7e94575720cc25296681f844c4e53a9fc5c)
|
|
62
|
-
- Use double quotes [`c1f19db`](https://github.com/Immugio/three-math-extensions/commit/c1f19db2d0886a6ff5555bdbf353dfca20a70f0a)
|
|
63
|
-
- Documentation update [`d5c7a07`](https://github.com/Immugio/three-math-extensions/commit/d5c7a0765f6097f5d3a3be01967d4059f19682fb)
|
|
64
|
-
- Excluded files from build [`ec70614`](https://github.com/Immugio/three-math-extensions/commit/ec70614bc7df7a98f854c7a6693365118e04faf7)
|
|
65
|
-
- Correct test file extension [`91b5e2a`](https://github.com/Immugio/three-math-extensions/commit/91b5e2ad338e8404704381a36813dcce5f00d978)
|
|
14
|
+
- Add Polygon.offsetContour, Polygon.translateContourLine [`55bcd4b`](https://github.com/Immugio/three-math-extensions/commit/55bcd4b3765d26d76265cb89e1cbd37749ec6e06)
|
|
15
|
+
- Add Polygon.shiftToZero [`bd9db04`](https://github.com/Immugio/three-math-extensions/commit/bd9db0423b634fe82edeb70ddd43e71a66de699b)
|
|
66
16
|
|
|
67
|
-
## [
|
|
17
|
+
## [0.2.28](https://github.com/Immugio/three-math-extensions/compare/0.2.27...0.2.28) - 2024-09-11
|
|
18
|
+
|
|
19
|
+
### Commits
|
|
20
|
+
|
|
21
|
+
- Add Polygon.roundIfCloseToInteger, Vec3.roundIfCloseToInteger [`ee9a90d`](https://github.com/Immugio/three-math-extensions/commit/ee9a90de07eb9827d1a53cdac65be3a51862cdc2)
|
|
68
22
|
|
|
69
23
|
## [0.2.27](https://github.com/Immugio/three-math-extensions/compare/0.2.26...0.2.27) - 2024-09-10
|
|
70
24
|
|
|
@@ -301,48 +255,29 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
301
255
|
|
|
302
256
|
- Add Vec2 documentation [`f625e66`](https://github.com/Immugio/three-math-extensions/commit/f625e66b60ee0d90c5c788a80989f64013d60265)
|
|
303
257
|
|
|
304
|
-
## [0.0.11](https://github.com/Immugio/three-math-extensions/compare/0.0.
|
|
258
|
+
## [0.0.11](https://github.com/Immugio/three-math-extensions/compare/0.0.6...0.0.11) - 2022-12-20
|
|
305
259
|
|
|
306
260
|
### Commits
|
|
307
261
|
|
|
308
|
-
- Improve API, minor bug fix, improve test coverage [`881a5f0`](https://github.com/Immugio/three-math-extensions/commit/881a5f096823f0d5fd90faa76cd602f076291bc5)
|
|
309
262
|
- Add Line2D.extendToOrTrimAtIntersection [`ab82a36`](https://github.com/Immugio/three-math-extensions/commit/ab82a36db52b9ae83cf8bfb848362d295140d073)
|
|
310
263
|
- Added "isNear" to Vec2 & Vec3 as a shorthand for distanceTo <= maxDistance [`a27cff8`](https://github.com/Immugio/three-math-extensions/commit/a27cff8421472f625ed240439b9e6a7d2c430db8)
|
|
311
|
-
- Add .npmignore [`f58329a`](https://github.com/Immugio/three-math-extensions/commit/f58329a86b96589bb574d6ebed37d4cc4474663a)
|
|
312
264
|
- Add Vec2.moveTowards [`b46ba12`](https://github.com/Immugio/three-math-extensions/commit/b46ba1286f9924cd9bfecfb37200664202e964ba)
|
|
313
265
|
- Add Line2D.extendToOrTrimAtIntersection [`b22aa12`](https://github.com/Immugio/three-math-extensions/commit/b22aa120b5eb02562cebc4573374ebb61e2dba14)
|
|
314
|
-
- Correct change log version [`c6244bf`](https://github.com/Immugio/three-math-extensions/commit/c6244bf1488ad21bcc5589d1dff62c41d8182d48)
|
|
315
|
-
|
|
316
|
-
## [0.0.10](https://github.com/Immugio/three-math-extensions/compare/0.0.9...0.0.10) - 2022-11-21
|
|
317
|
-
|
|
318
|
-
### Commits
|
|
319
|
-
|
|
320
|
-
- Release 0.0.4 - tag pattern 6 [`c1c5454`](https://github.com/Immugio/three-math-extensions/commit/c1c54541ed400e1ad49bf42fe8926cd5293efefd)
|
|
321
|
-
|
|
322
|
-
## [0.0.9](https://github.com/Immugio/three-math-extensions/compare/0.0.8...0.0.9) - 2022-11-21
|
|
323
|
-
|
|
324
|
-
### Commits
|
|
325
|
-
|
|
326
|
-
- Release 0.0.4 - tag pattern 5 [`5245eed`](https://github.com/Immugio/three-math-extensions/commit/5245eed60195103e989c0fadf9bd642f39ef4589)
|
|
327
|
-
|
|
328
|
-
## [0.0.8](https://github.com/Immugio/three-math-extensions/compare/0.0.7...0.0.8) - 2022-11-21
|
|
329
|
-
|
|
330
|
-
### Commits
|
|
331
|
-
|
|
332
|
-
- Release 0.0.4 - tag pattern 4 [`ab9ad4e`](https://github.com/Immugio/three-math-extensions/commit/ab9ad4e49477a991482ed6d4d3a3ca4687a70b44)
|
|
333
|
-
|
|
334
|
-
## [0.0.7](https://github.com/Immugio/three-math-extensions/compare/0.0.6...0.0.7) - 2022-11-21
|
|
335
266
|
|
|
336
267
|
## [0.0.6](https://github.com/Immugio/three-math-extensions/compare/0.0.5...0.0.6) - 2022-11-24
|
|
337
268
|
|
|
338
|
-
##
|
|
269
|
+
## 0.0.5 - 2023-09-01
|
|
339
270
|
|
|
340
271
|
### Commits
|
|
341
272
|
|
|
273
|
+
- Automatic publish with change log [`a70c99d`](https://github.com/Immugio/three-math-extensions/commit/a70c99d0d42e60411ce01bcdb8dd4f3f489bb949)
|
|
274
|
+
- Switch to npm [`ed47a17`](https://github.com/Immugio/three-math-extensions/commit/ed47a1787522db3bde5a2112bfd02480fe2edc54)
|
|
275
|
+
- Initial commit [`3d1bf9e`](https://github.com/Immugio/three-math-extensions/commit/3d1bf9ef015570830007c9be99140c8c8d760d7f)
|
|
342
276
|
- Generate documentation using TSDoc [`304c3a8`](https://github.com/Immugio/three-math-extensions/commit/304c3a84b5dcc49183db57083f550d134ae641b2)
|
|
343
277
|
- Add eslint [`98e4912`](https://github.com/Immugio/three-math-extensions/commit/98e4912d637b42ba80e2f3267638b43296113019)
|
|
344
278
|
- Update jest packages [`af23b4f`](https://github.com/Immugio/three-math-extensions/commit/af23b4f08154bba3407f05b773865215e7e1cba8)
|
|
345
279
|
- Add Rectangle, update Polygon [`58ee875`](https://github.com/Immugio/three-math-extensions/commit/58ee87539af8f9ade186e5250cba9e01926da514)
|
|
280
|
+
- Add Line2D [`9a1dd0f`](https://github.com/Immugio/three-math-extensions/commit/9a1dd0f58352b7b25828693c688aa4770e95c174)
|
|
346
281
|
- Add isPointInPolygon [`a59eb4b`](https://github.com/Immugio/three-math-extensions/commit/a59eb4be026f17a3106070ae626a0588cd4f4411)
|
|
347
282
|
- Improve Line2D.closestPointToPoint, add Vec2.signedAngle [`151f214`](https://github.com/Immugio/three-math-extensions/commit/151f21462e0358057ad8e9d75d5782563a1061f6)
|
|
348
283
|
- Improve documentation [`d0fcb51`](https://github.com/Immugio/three-math-extensions/commit/d0fcb5132f127b4382ac5f7291575a061b8ec121)
|
|
@@ -356,6 +291,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
356
291
|
- Add Vec2.signedAngle [`863c8f2`](https://github.com/Immugio/three-math-extensions/commit/863c8f27f11288cbda535e21bb688206259269ed)
|
|
357
292
|
- Add intersect method to Line3D [`6fe47de`](https://github.com/Immugio/three-math-extensions/commit/6fe47de7caaa1807b47a4363e551510c463757d7)
|
|
358
293
|
- Add Line2D.extendToOrTrimAtIntersection [`ab82a36`](https://github.com/Immugio/three-math-extensions/commit/ab82a36db52b9ae83cf8bfb848362d295140d073)
|
|
294
|
+
- Readme, npm info [`dda4a28`](https://github.com/Immugio/three-math-extensions/commit/dda4a282a71a00308dcae858ffe53d67d4185be8)
|
|
359
295
|
- Add Vec2.fromPoints to accept multiple points [`a261402`](https://github.com/Immugio/three-math-extensions/commit/a2614027cf5fb8263189b48f7e0bb9a23a552c15)
|
|
360
296
|
- Improve documentation for Vec2 and Vec3 [`6a2373d`](https://github.com/Immugio/three-math-extensions/commit/6a2373d8b6754a87720dcaea5d98336bfa7bc5b5)
|
|
361
297
|
- Add Vec2.parallelTo [`989874d`](https://github.com/Immugio/three-math-extensions/commit/989874dcfe122d3ee84d8d56d79cb88e4e441736)
|
|
@@ -367,8 +303,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
367
303
|
- Add .npmignore [`f58329a`](https://github.com/Immugio/three-math-extensions/commit/f58329a86b96589bb574d6ebed37d4cc4474663a)
|
|
368
304
|
- Polygon from bounding size [`eae6701`](https://github.com/Immugio/three-math-extensions/commit/eae67012f57f426f8b5259b765000447ce06d608)
|
|
369
305
|
- Add Vec2 documentation [`f625e66`](https://github.com/Immugio/three-math-extensions/commit/f625e66b60ee0d90c5c788a80989f64013d60265)
|
|
306
|
+
- Run tests in CI on commit [`e3f77ca`](https://github.com/Immugio/three-math-extensions/commit/e3f77ca76e25f4d99eef0130e5779b5e7c5aec6b)
|
|
370
307
|
- Clean up documentation [`70c8d5e`](https://github.com/Immugio/three-math-extensions/commit/70c8d5efe8b7095d7a03af637df3af5d46615293)
|
|
308
|
+
- Remove babel.config.js [`c9a1e16`](https://github.com/Immugio/three-math-extensions/commit/c9a1e1607cffec8a3d74adcca644320a79ca4c43)
|
|
371
309
|
- Line2D and Line3D to return this instead of specific type [`761ef6a`](https://github.com/Immugio/three-math-extensions/commit/761ef6a9d8cc4e35120b666576794e521aa3b991)
|
|
310
|
+
- Initial changelog [`6c98aa6`](https://github.com/Immugio/three-math-extensions/commit/6c98aa6ad631cf5e73d32dd76276f99b3ba5089f)
|
|
372
311
|
- Line2D.in3DSpace added [`a6ce0ec`](https://github.com/Immugio/three-math-extensions/commit/a6ce0ecb67f5c7b2a75fcc283c28af626153a4af)
|
|
373
312
|
- Line3D.connectsTo added [`6d2cfa0`](https://github.com/Immugio/three-math-extensions/commit/6d2cfa0f5335c665f325a694a32c57b574ec326d)
|
|
374
313
|
- Line2D.hasIntersectionWithAngle to support optional tolerance [`b313bbe`](https://github.com/Immugio/three-math-extensions/commit/b313bbe118d435d53750deefd9a9e29ba6ec5c71)
|
|
@@ -377,36 +316,21 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
377
316
|
- Use Vec2 instead of Vector2 [`7e6a6ea`](https://github.com/Immugio/three-math-extensions/commit/7e6a6ea272f4441ef4bc78b3fdec23fc783fa1db)
|
|
378
317
|
- Add release instructions into README.md [`03653b1`](https://github.com/Immugio/three-math-extensions/commit/03653b1ffa55be606d3f9cd588e28a6084462c2e)
|
|
379
318
|
- Documentation improvements [`160db8b`](https://github.com/Immugio/three-math-extensions/commit/160db8ba6d6e5eb63a4e91ed9c40efd6fa70181a)
|
|
319
|
+
- Release 0.0.4 [`bdac840`](https://github.com/Immugio/three-math-extensions/commit/bdac840f33261a3f39ef33bc05c80772169cfe87)
|
|
380
320
|
- Update release instructions [`5b41a2e`](https://github.com/Immugio/three-math-extensions/commit/5b41a2ed7e15450dbb6088a7f7ed0031a013badc)
|
|
321
|
+
- Add test badge [`37c62e8`](https://github.com/Immugio/three-math-extensions/commit/37c62e809bdcdfc63f7fe135469fd131f190f950)
|
|
381
322
|
- Add Polygon to exports [`ed66775`](https://github.com/Immugio/three-math-extensions/commit/ed66775c33e961835b23843222b822cfd9c16b1d)
|
|
382
323
|
- Vec2.fromPoint and Vec3.fromPoint should accept null [`4b871af`](https://github.com/Immugio/three-math-extensions/commit/4b871af297bdcbe8584f1e2b99d602247b77687c)
|
|
383
324
|
- Documentation improvements [`2f3e676`](https://github.com/Immugio/three-math-extensions/commit/2f3e6768b3b0139b60688fc151a4084f15566f8d)
|
|
325
|
+
- Edit publish script condition [`dc77d89`](https://github.com/Immugio/three-math-extensions/commit/dc77d8978d87daab8732d6429ad1b01ba0ca6f97)
|
|
326
|
+
- CI to use node version 16 [`dc42650`](https://github.com/Immugio/three-math-extensions/commit/dc426508939de922cc0316b7652bbd09aeed4610)
|
|
327
|
+
- Action rename [`26a1f01`](https://github.com/Immugio/three-math-extensions/commit/26a1f014827faab2c02d30ca8ed18dac8f9ff8af)
|
|
384
328
|
- Documentation update [`d5c7a07`](https://github.com/Immugio/three-math-extensions/commit/d5c7a0765f6097f5d3a3be01967d4059f19682fb)
|
|
385
329
|
- Fix peer dependency version [`00dd116`](https://github.com/Immugio/three-math-extensions/commit/00dd1169f578d5769207031fa625f29c96a38c31)
|
|
386
330
|
- Add Line2D.extendToOrTrimAtIntersection [`b22aa12`](https://github.com/Immugio/three-math-extensions/commit/b22aa120b5eb02562cebc4573374ebb61e2dba14)
|
|
387
331
|
- Correct change log version [`c6244bf`](https://github.com/Immugio/three-math-extensions/commit/c6244bf1488ad21bcc5589d1dff62c41d8182d48)
|
|
388
332
|
- Release 0.0.4 - tag pattern 6 [`c1c5454`](https://github.com/Immugio/three-math-extensions/commit/c1c54541ed400e1ad49bf42fe8926cd5293efefd)
|
|
389
333
|
- Release 0.0.4 - tag pattern 5 [`5245eed`](https://github.com/Immugio/three-math-extensions/commit/5245eed60195103e989c0fadf9bd642f39ef4589)
|
|
390
|
-
- Excluded files from build [`ec70614`](https://github.com/Immugio/three-math-extensions/commit/ec70614bc7df7a98f854c7a6693365118e04faf7)
|
|
391
|
-
- Revert npm ignore [`590b26a`](https://github.com/Immugio/three-math-extensions/commit/590b26a9e57fc41466b51e711f3f5c648e2d56ed)
|
|
392
|
-
|
|
393
|
-
## 0.0.4 - 2022-11-21
|
|
394
|
-
|
|
395
|
-
### Commits
|
|
396
|
-
|
|
397
|
-
- Automatic publish with change log [`a70c99d`](https://github.com/Immugio/three-math-extensions/commit/a70c99d0d42e60411ce01bcdb8dd4f3f489bb949)
|
|
398
|
-
- Switch to npm [`ed47a17`](https://github.com/Immugio/three-math-extensions/commit/ed47a1787522db3bde5a2112bfd02480fe2edc54)
|
|
399
|
-
- Initial commit [`3d1bf9e`](https://github.com/Immugio/three-math-extensions/commit/3d1bf9ef015570830007c9be99140c8c8d760d7f)
|
|
400
|
-
- Add Line2D [`9a1dd0f`](https://github.com/Immugio/three-math-extensions/commit/9a1dd0f58352b7b25828693c688aa4770e95c174)
|
|
401
|
-
- Readme, npm info [`dda4a28`](https://github.com/Immugio/three-math-extensions/commit/dda4a282a71a00308dcae858ffe53d67d4185be8)
|
|
402
|
-
- Run tests in CI on commit [`e3f77ca`](https://github.com/Immugio/three-math-extensions/commit/e3f77ca76e25f4d99eef0130e5779b5e7c5aec6b)
|
|
403
|
-
- Remove babel.config.js [`c9a1e16`](https://github.com/Immugio/three-math-extensions/commit/c9a1e1607cffec8a3d74adcca644320a79ca4c43)
|
|
404
|
-
- Initial changelog [`6c98aa6`](https://github.com/Immugio/three-math-extensions/commit/6c98aa6ad631cf5e73d32dd76276f99b3ba5089f)
|
|
405
|
-
- Release 0.0.4 [`bdac840`](https://github.com/Immugio/three-math-extensions/commit/bdac840f33261a3f39ef33bc05c80772169cfe87)
|
|
406
|
-
- Add test badge [`37c62e8`](https://github.com/Immugio/three-math-extensions/commit/37c62e809bdcdfc63f7fe135469fd131f190f950)
|
|
407
|
-
- Edit publish script condition [`dc77d89`](https://github.com/Immugio/three-math-extensions/commit/dc77d8978d87daab8732d6429ad1b01ba0ca6f97)
|
|
408
|
-
- CI to use node version 16 [`dc42650`](https://github.com/Immugio/three-math-extensions/commit/dc426508939de922cc0316b7652bbd09aeed4610)
|
|
409
|
-
- Action rename [`26a1f01`](https://github.com/Immugio/three-math-extensions/commit/26a1f014827faab2c02d30ca8ed18dac8f9ff8af)
|
|
410
334
|
- Release 0.0.4 - tag pattern 4 [`ab9ad4e`](https://github.com/Immugio/three-math-extensions/commit/ab9ad4e49477a991482ed6d4d3a3ca4687a70b44)
|
|
411
335
|
- Release 0.0.4 - tag pattern 3 [`d7d4c8f`](https://github.com/Immugio/three-math-extensions/commit/d7d4c8f546e6550868ddd06a5213fdec6c68bcd2)
|
|
412
336
|
- Release 0.0.4 - tag pattern 2 [`0dcf801`](https://github.com/Immugio/three-math-extensions/commit/0dcf80190bd67a3ca93d45131a403201ab39e00f)
|
|
@@ -414,4 +338,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
414
338
|
- Release 0.0.5 [`c80d6bd`](https://github.com/Immugio/three-math-extensions/commit/c80d6bd12c25ddad0f67610cdf5c804d5759f084)
|
|
415
339
|
- Status badge update [`370843e`](https://github.com/Immugio/three-math-extensions/commit/370843ed0a28b024761555572b7d51ccbdb4b77d)
|
|
416
340
|
- Run tests in CI on commit [`aee8c55`](https://github.com/Immugio/three-math-extensions/commit/aee8c556ae1cab9025dbe0984dd17278fe6275a1)
|
|
341
|
+
- Excluded files from build [`ec70614`](https://github.com/Immugio/three-math-extensions/commit/ec70614bc7df7a98f854c7a6693365118e04faf7)
|
|
342
|
+
- Revert npm ignore [`590b26a`](https://github.com/Immugio/three-math-extensions/commit/590b26a9e57fc41466b51e711f3f5c648e2d56ed)
|
|
417
343
|
- Add Line2D to index [`a5fb6bd`](https://github.com/Immugio/three-math-extensions/commit/a5fb6bdeee5d9f07f325bfffc31ef96f0ce167d1)
|
package/cjs/Line2D.js
CHANGED
|
@@ -27,18 +27,28 @@ class Line2D {
|
|
|
27
27
|
/**
|
|
28
28
|
* Creates a polygon formed by an array of lines from points provided.
|
|
29
29
|
* The polygon will only be closed if either
|
|
30
|
-
* 1) the first and last points are the same or 2)
|
|
30
|
+
* 1) the first and last points are the same or 2) `@forceClosedPolygon` is true.
|
|
31
|
+
* Similar to Line2.fromVectors but creates new instances of Vec2.
|
|
31
32
|
*/
|
|
32
33
|
static fromPolygon(polygon, forceClosedPolygon = false) {
|
|
34
|
+
return Line2D.fromVectors(polygon?.map(p => Vec2_1.Vec2.fromPoint(p)), forceClosedPolygon);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates a polygon formed by an array of lines from points provided.
|
|
38
|
+
* The polygon will only be closed if either
|
|
39
|
+
* 1) the first and last points are the same or 2) `@forceClosedPolygon` is true.
|
|
40
|
+
* Similar to Line2.fromPolygon but keeps the original instances of Vec2.
|
|
41
|
+
*/
|
|
42
|
+
static fromVectors(polygon, forceClosedPolygon = false) {
|
|
33
43
|
if (!polygon || polygon.length < 2) {
|
|
34
44
|
return [];
|
|
35
45
|
}
|
|
36
|
-
if (forceClosedPolygon &&
|
|
46
|
+
if (forceClosedPolygon && !polygon[0].equals(polygon.at(-1))) {
|
|
37
47
|
polygon = [...polygon, polygon[0]];
|
|
38
48
|
}
|
|
39
49
|
const lines = [];
|
|
40
50
|
for (let i = 0; i < polygon.length - 1; i++) {
|
|
41
|
-
lines.push(Line2D
|
|
51
|
+
lines.push(new Line2D(polygon[i], polygon[i + 1], i));
|
|
42
52
|
}
|
|
43
53
|
return lines;
|
|
44
54
|
}
|
package/cjs/Polygon.js
CHANGED
|
@@ -6,6 +6,9 @@ const Rectangle_1 = require("./Rectangle");
|
|
|
6
6
|
const BoundingBox_1 = require("./BoundingBox");
|
|
7
7
|
const polygonPerimeter_1 = require("./polygonPerimeter");
|
|
8
8
|
const isPointInPolygon_1 = require("./isPointInPolygon");
|
|
9
|
+
const Line2D_1 = require("./Line2D");
|
|
10
|
+
const offsetPolyline_1 = require("./offsetPolyline");
|
|
11
|
+
const extendOrTrimPolylinesAtIntersections_1 = require("./extendOrTrimPolylinesAtIntersections");
|
|
9
12
|
class Polygon {
|
|
10
13
|
contour;
|
|
11
14
|
holes;
|
|
@@ -106,6 +109,30 @@ class Polygon {
|
|
|
106
109
|
this.holes?.forEach(hole => hole.forEach(p => p.add(translate)));
|
|
107
110
|
return this;
|
|
108
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Translates the polygon so that the lowest x and y values are 0.
|
|
114
|
+
*/
|
|
115
|
+
shiftToZero() {
|
|
116
|
+
let xMin = Infinity, yMin = Infinity; // Find the diff between the lowest x & y & 0
|
|
117
|
+
for (const point of this.contour) {
|
|
118
|
+
xMin = Math.min(xMin, point.x);
|
|
119
|
+
yMin = Math.min(yMin, point.y);
|
|
120
|
+
}
|
|
121
|
+
if (xMin !== 0 || yMin !== 0) { // Make the poly to start at 0
|
|
122
|
+
this.translate(new Vec2_1.Vec2(-xMin, -yMin));
|
|
123
|
+
}
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
offsetContour(offset) {
|
|
127
|
+
(0, offsetPolyline_1.offsetPolyline)(Line2D_1.Line2D.fromVectors(this.contour), offset);
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
translateContourLine(index, offset) {
|
|
131
|
+
const lines = Line2D_1.Line2D.fromVectors(this.contour);
|
|
132
|
+
lines[index].translateLeft(offset);
|
|
133
|
+
(0, extendOrTrimPolylinesAtIntersections_1.extendOrTrimPolylinesAtIntersections)(lines);
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
109
136
|
rotate(angle, center = this.center()) {
|
|
110
137
|
this.contour.forEach(p => p.rotateAround(center, angle));
|
|
111
138
|
this.holes?.forEach(hole => hole.forEach(p => p.rotateAround(center, angle)));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extendOrTrimPolylinesAtIntersections = void 0;
|
|
4
|
+
function extendOrTrimPolylinesAtIntersections(lines) {
|
|
5
|
+
for (let i = 0; i < lines.length; i++) {
|
|
6
|
+
const current = lines[i];
|
|
7
|
+
const next = lines[(i + 1) % lines.length];
|
|
8
|
+
current.extendToOrTrimAtIntersection(next);
|
|
9
|
+
next.extendToOrTrimAtIntersection(current);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.extendOrTrimPolylinesAtIntersections = extendOrTrimPolylinesAtIntersections;
|
package/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.polygonPerimeter = exports.isContinuousClosedShape = exports.directions2d = exports.directions = exports.isPointInPolygon = exports.HalfPI = exports.TwoPI = exports.normalizeAngleRadians = exports.normalizeAngleDegrees = exports.Rectangle = exports.BoundingBox = exports.Polygon = exports.Size2 = exports.Line3D = exports.Line2D = exports.Vec3 = exports.Vec2 = void 0;
|
|
3
|
+
exports.extendOrTrimPolylinesAtIntersections = exports.offsetPolyline = exports.polygonPerimeter = exports.isContinuousClosedShape = exports.directions2d = exports.directions = exports.isPointInPolygon = exports.HalfPI = exports.TwoPI = exports.normalizeAngleRadians = exports.normalizeAngleDegrees = exports.Rectangle = exports.BoundingBox = exports.Polygon = exports.Size2 = exports.Line3D = exports.Line2D = exports.Vec3 = exports.Vec2 = void 0;
|
|
4
4
|
var Vec2_1 = require("./Vec2");
|
|
5
5
|
Object.defineProperty(exports, "Vec2", { enumerable: true, get: function () { return Vec2_1.Vec2; } });
|
|
6
6
|
var Vec3_1 = require("./Vec3");
|
|
@@ -34,3 +34,7 @@ var isContinuousClosedShape_1 = require("./isContinuousClosedShape");
|
|
|
34
34
|
Object.defineProperty(exports, "isContinuousClosedShape", { enumerable: true, get: function () { return isContinuousClosedShape_1.isContinuousClosedShape; } });
|
|
35
35
|
var polygonPerimeter_1 = require("./polygonPerimeter");
|
|
36
36
|
Object.defineProperty(exports, "polygonPerimeter", { enumerable: true, get: function () { return polygonPerimeter_1.polygonPerimeter; } });
|
|
37
|
+
var offsetPolyline_1 = require("./offsetPolyline");
|
|
38
|
+
Object.defineProperty(exports, "offsetPolyline", { enumerable: true, get: function () { return offsetPolyline_1.offsetPolyline; } });
|
|
39
|
+
var extendOrTrimPolylinesAtIntersections_1 = require("./extendOrTrimPolylinesAtIntersections");
|
|
40
|
+
Object.defineProperty(exports, "extendOrTrimPolylinesAtIntersections", { enumerable: true, get: function () { return extendOrTrimPolylinesAtIntersections_1.extendOrTrimPolylinesAtIntersections; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.offsetPolyline = void 0;
|
|
4
|
+
const extendOrTrimPolylinesAtIntersections_1 = require("./extendOrTrimPolylinesAtIntersections");
|
|
5
|
+
function offsetPolyline(lines, offset) {
|
|
6
|
+
lines.forEach(line => line.translateLeft(offset));
|
|
7
|
+
(0, extendOrTrimPolylinesAtIntersections_1.extendOrTrimPolylinesAtIntersections)(lines);
|
|
8
|
+
return lines;
|
|
9
|
+
}
|
|
10
|
+
exports.offsetPolyline = offsetPolyline;
|
package/esm/Line2D.js
CHANGED
|
@@ -24,18 +24,28 @@ export class Line2D {
|
|
|
24
24
|
/**
|
|
25
25
|
* Creates a polygon formed by an array of lines from points provided.
|
|
26
26
|
* The polygon will only be closed if either
|
|
27
|
-
* 1) the first and last points are the same or 2)
|
|
27
|
+
* 1) the first and last points are the same or 2) `@forceClosedPolygon` is true.
|
|
28
|
+
* Similar to Line2.fromVectors but creates new instances of Vec2.
|
|
28
29
|
*/
|
|
29
30
|
static fromPolygon(polygon, forceClosedPolygon = false) {
|
|
31
|
+
return Line2D.fromVectors(polygon?.map(p => Vec2.fromPoint(p)), forceClosedPolygon);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a polygon formed by an array of lines from points provided.
|
|
35
|
+
* The polygon will only be closed if either
|
|
36
|
+
* 1) the first and last points are the same or 2) `@forceClosedPolygon` is true.
|
|
37
|
+
* Similar to Line2.fromPolygon but keeps the original instances of Vec2.
|
|
38
|
+
*/
|
|
39
|
+
static fromVectors(polygon, forceClosedPolygon = false) {
|
|
30
40
|
if (!polygon || polygon.length < 2) {
|
|
31
41
|
return [];
|
|
32
42
|
}
|
|
33
|
-
if (forceClosedPolygon &&
|
|
43
|
+
if (forceClosedPolygon && !polygon[0].equals(polygon.at(-1))) {
|
|
34
44
|
polygon = [...polygon, polygon[0]];
|
|
35
45
|
}
|
|
36
46
|
const lines = [];
|
|
37
47
|
for (let i = 0; i < polygon.length - 1; i++) {
|
|
38
|
-
lines.push(Line2D
|
|
48
|
+
lines.push(new Line2D(polygon[i], polygon[i + 1], i));
|
|
39
49
|
}
|
|
40
50
|
return lines;
|
|
41
51
|
}
|
package/esm/Polygon.js
CHANGED
|
@@ -3,6 +3,9 @@ import { Rectangle } from "./Rectangle";
|
|
|
3
3
|
import { BoundingBox } from "./BoundingBox";
|
|
4
4
|
import { polygonPerimeter } from "./polygonPerimeter";
|
|
5
5
|
import { isPointInPolygon } from "./isPointInPolygon";
|
|
6
|
+
import { Line2D } from "./Line2D";
|
|
7
|
+
import { offsetPolyline } from "./offsetPolyline";
|
|
8
|
+
import { extendOrTrimPolylinesAtIntersections } from "./extendOrTrimPolylinesAtIntersections";
|
|
6
9
|
export class Polygon {
|
|
7
10
|
contour;
|
|
8
11
|
holes;
|
|
@@ -103,6 +106,30 @@ export class Polygon {
|
|
|
103
106
|
this.holes?.forEach(hole => hole.forEach(p => p.add(translate)));
|
|
104
107
|
return this;
|
|
105
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Translates the polygon so that the lowest x and y values are 0.
|
|
111
|
+
*/
|
|
112
|
+
shiftToZero() {
|
|
113
|
+
let xMin = Infinity, yMin = Infinity; // Find the diff between the lowest x & y & 0
|
|
114
|
+
for (const point of this.contour) {
|
|
115
|
+
xMin = Math.min(xMin, point.x);
|
|
116
|
+
yMin = Math.min(yMin, point.y);
|
|
117
|
+
}
|
|
118
|
+
if (xMin !== 0 || yMin !== 0) { // Make the poly to start at 0
|
|
119
|
+
this.translate(new Vec2(-xMin, -yMin));
|
|
120
|
+
}
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
offsetContour(offset) {
|
|
124
|
+
offsetPolyline(Line2D.fromVectors(this.contour), offset);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
translateContourLine(index, offset) {
|
|
128
|
+
const lines = Line2D.fromVectors(this.contour);
|
|
129
|
+
lines[index].translateLeft(offset);
|
|
130
|
+
extendOrTrimPolylinesAtIntersections(lines);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
106
133
|
rotate(angle, center = this.center()) {
|
|
107
134
|
this.contour.forEach(p => p.rotateAround(center, angle));
|
|
108
135
|
this.holes?.forEach(hole => hole.forEach(p => p.rotateAround(center, angle)));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function extendOrTrimPolylinesAtIntersections(lines) {
|
|
2
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3
|
+
const current = lines[i];
|
|
4
|
+
const next = lines[(i + 1) % lines.length];
|
|
5
|
+
current.extendToOrTrimAtIntersection(next);
|
|
6
|
+
next.extendToOrTrimAtIntersection(current);
|
|
7
|
+
}
|
|
8
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -14,3 +14,5 @@ export { directions } from "./directions";
|
|
|
14
14
|
export { directions2d } from "./directions2d";
|
|
15
15
|
export { isContinuousClosedShape } from "./isContinuousClosedShape";
|
|
16
16
|
export { polygonPerimeter } from "./polygonPerimeter";
|
|
17
|
+
export { offsetPolyline } from "./offsetPolyline";
|
|
18
|
+
export { extendOrTrimPolylinesAtIntersections } from "./extendOrTrimPolylinesAtIntersections";
|
package/package.json
CHANGED
package/src/Line2D.ts
CHANGED
|
@@ -26,20 +26,31 @@ export class Line2D {
|
|
|
26
26
|
/**
|
|
27
27
|
* Creates a polygon formed by an array of lines from points provided.
|
|
28
28
|
* The polygon will only be closed if either
|
|
29
|
-
* 1) the first and last points are the same or 2)
|
|
29
|
+
* 1) the first and last points are the same or 2) `@forceClosedPolygon` is true.
|
|
30
|
+
* Similar to Line2.fromVectors but creates new instances of Vec2.
|
|
30
31
|
*/
|
|
31
32
|
public static fromPolygon(polygon: Point2[], forceClosedPolygon: boolean = false): Line2D[] {
|
|
33
|
+
return Line2D.fromVectors(polygon?.map(p => Vec2.fromPoint(p)), forceClosedPolygon);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates a polygon formed by an array of lines from points provided.
|
|
38
|
+
* The polygon will only be closed if either
|
|
39
|
+
* 1) the first and last points are the same or 2) `@forceClosedPolygon` is true.
|
|
40
|
+
* Similar to Line2.fromPolygon but keeps the original instances of Vec2.
|
|
41
|
+
*/
|
|
42
|
+
public static fromVectors(polygon: Vec2[], forceClosedPolygon: boolean = false): Line2D[] {
|
|
32
43
|
if (!polygon || polygon.length < 2) {
|
|
33
44
|
return [];
|
|
34
45
|
}
|
|
35
46
|
|
|
36
|
-
if (forceClosedPolygon &&
|
|
47
|
+
if (forceClosedPolygon && !polygon[0].equals(polygon.at(-1))) {
|
|
37
48
|
polygon = [...polygon, polygon[0]];
|
|
38
49
|
}
|
|
39
50
|
|
|
40
51
|
const lines: Line2D[] = [];
|
|
41
52
|
for (let i = 0; i < polygon.length - 1; i++) {
|
|
42
|
-
lines.push(Line2D
|
|
53
|
+
lines.push(new Line2D(polygon[i], polygon[i + 1], i));
|
|
43
54
|
}
|
|
44
55
|
|
|
45
56
|
return lines;
|
package/src/Polygon.ts
CHANGED
|
@@ -4,6 +4,9 @@ import { Rectangle } from "./Rectangle";
|
|
|
4
4
|
import { BoundingBox } from "./BoundingBox";
|
|
5
5
|
import { polygonPerimeter } from "./polygonPerimeter";
|
|
6
6
|
import { isPointInPolygon } from "./isPointInPolygon";
|
|
7
|
+
import { Line2D } from "./Line2D";
|
|
8
|
+
import { offsetPolyline } from "./offsetPolyline";
|
|
9
|
+
import { extendOrTrimPolylinesAtIntersections } from "./extendOrTrimPolylinesAtIntersections";
|
|
7
10
|
|
|
8
11
|
export class Polygon {
|
|
9
12
|
|
|
@@ -123,6 +126,35 @@ export class Polygon {
|
|
|
123
126
|
return this;
|
|
124
127
|
}
|
|
125
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Translates the polygon so that the lowest x and y values are 0.
|
|
131
|
+
*/
|
|
132
|
+
public shiftToZero(): this {
|
|
133
|
+
let xMin = Infinity, yMin = Infinity; // Find the diff between the lowest x & y & 0
|
|
134
|
+
for (const point of this.contour) {
|
|
135
|
+
xMin = Math.min(xMin, point.x);
|
|
136
|
+
yMin = Math.min(yMin, point.y);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (xMin !== 0 || yMin !== 0) { // Make the poly to start at 0
|
|
140
|
+
this.translate(new Vec2(-xMin, -yMin));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public offsetContour(offset: number): this {
|
|
147
|
+
offsetPolyline(Line2D.fromVectors(this.contour), offset);
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public translateContourLine(index: number, offset: number): this {
|
|
152
|
+
const lines = Line2D.fromVectors(this.contour);
|
|
153
|
+
lines[index].translateLeft(offset);
|
|
154
|
+
extendOrTrimPolylinesAtIntersections(lines);
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
|
|
126
158
|
public rotate(angle: number, center = this.center()): this {
|
|
127
159
|
this.contour.forEach(p => p.rotateAround(center, angle));
|
|
128
160
|
this.holes?.forEach(hole => hole.forEach(p => p.rotateAround(center, angle)));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Line2D } from "./Line2D";
|
|
2
|
+
|
|
3
|
+
export function extendOrTrimPolylinesAtIntersections(lines: Line2D[]): void {
|
|
4
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5
|
+
const current = lines[i];
|
|
6
|
+
const next = lines[(i + 1) % lines.length];
|
|
7
|
+
|
|
8
|
+
current.extendToOrTrimAtIntersection(next);
|
|
9
|
+
next.extendToOrTrimAtIntersection(current);
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -15,4 +15,6 @@ export { isPointInPolygon } from "./isPointInPolygon";
|
|
|
15
15
|
export { directions } from "./directions";
|
|
16
16
|
export { directions2d } from "./directions2d";
|
|
17
17
|
export { isContinuousClosedShape } from "./isContinuousClosedShape";
|
|
18
|
-
export { polygonPerimeter } from "./polygonPerimeter";
|
|
18
|
+
export { polygonPerimeter } from "./polygonPerimeter";
|
|
19
|
+
export { offsetPolyline } from "./offsetPolyline";
|
|
20
|
+
export { extendOrTrimPolylinesAtIntersections } from "./extendOrTrimPolylinesAtIntersections";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Line2D } from "./Line2D";
|
|
2
|
+
import { extendOrTrimPolylinesAtIntersections } from "./extendOrTrimPolylinesAtIntersections";
|
|
3
|
+
|
|
4
|
+
export function offsetPolyline(lines: Line2D[], offset: number): Line2D[] {
|
|
5
|
+
lines.forEach(line => line.translateLeft(offset));
|
|
6
|
+
extendOrTrimPolylinesAtIntersections(lines);
|
|
7
|
+
return lines;
|
|
8
|
+
}
|
package/types/Line2D.d.ts
CHANGED
|
@@ -13,9 +13,17 @@ export declare class Line2D {
|
|
|
13
13
|
/**
|
|
14
14
|
* Creates a polygon formed by an array of lines from points provided.
|
|
15
15
|
* The polygon will only be closed if either
|
|
16
|
-
* 1) the first and last points are the same or 2)
|
|
16
|
+
* 1) the first and last points are the same or 2) `@forceClosedPolygon` is true.
|
|
17
|
+
* Similar to Line2.fromVectors but creates new instances of Vec2.
|
|
17
18
|
*/
|
|
18
19
|
static fromPolygon(polygon: Point2[], forceClosedPolygon?: boolean): Line2D[];
|
|
20
|
+
/**
|
|
21
|
+
* Creates a polygon formed by an array of lines from points provided.
|
|
22
|
+
* The polygon will only be closed if either
|
|
23
|
+
* 1) the first and last points are the same or 2) `@forceClosedPolygon` is true.
|
|
24
|
+
* Similar to Line2.fromPolygon but keeps the original instances of Vec2.
|
|
25
|
+
*/
|
|
26
|
+
static fromVectors(polygon: Vec2[], forceClosedPolygon?: boolean): Line2D[];
|
|
19
27
|
static fromLength(length: number): Line2D;
|
|
20
28
|
get center(): Vec2;
|
|
21
29
|
/**
|
package/types/Polygon.d.ts
CHANGED
|
@@ -19,6 +19,12 @@ export declare class Polygon {
|
|
|
19
19
|
containsPoint(point: Vec2): boolean;
|
|
20
20
|
private flipSingle;
|
|
21
21
|
translate(translate: Vec2): this;
|
|
22
|
+
/**
|
|
23
|
+
* Translates the polygon so that the lowest x and y values are 0.
|
|
24
|
+
*/
|
|
25
|
+
shiftToZero(): this;
|
|
26
|
+
offsetContour(offset: number): this;
|
|
27
|
+
translateContourLine(index: number, offset: number): this;
|
|
22
28
|
rotate(angle: number, center?: Vec2): this;
|
|
23
29
|
toRectangle(): Rectangle;
|
|
24
30
|
clone(): Polygon;
|
package/types/index.d.ts
CHANGED
|
@@ -16,3 +16,5 @@ export { directions } from "./directions";
|
|
|
16
16
|
export { directions2d } from "./directions2d";
|
|
17
17
|
export { isContinuousClosedShape } from "./isContinuousClosedShape";
|
|
18
18
|
export { polygonPerimeter } from "./polygonPerimeter";
|
|
19
|
+
export { offsetPolyline } from "./offsetPolyline";
|
|
20
|
+
export { extendOrTrimPolylinesAtIntersections } from "./extendOrTrimPolylinesAtIntersections";
|