@thi.ng/geom-clip-line 2.1.37 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-11-30T22:27:37Z
3
+ - **Last updated**: 2022-12-16T12:52:25Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom-clip-line@2.2.0) (2022-12-10)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add clipPolylinePoly() ([445ccd6](https://github.com/thi-ng/umbrella/commit/445ccd6))
17
+
12
18
  ### [2.1.22](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom-clip-line@2.1.22) (2022-08-06)
13
19
 
14
20
  #### ⏱ Performance improvements
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  <!-- This file is generated - DO NOT EDIT! -->
2
2
 
3
- # ![geom-clip-line](https://media.thi.ng/umbrella/banners-20220914/thing-geom-clip-line.svg?8ca4f323)
3
+ # ![@thi.ng/geom-clip-line](https://media.thi.ng/umbrella/banners-20220914/thing-geom-clip-line.svg?8ca4f323)
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@thi.ng/geom-clip-line.svg)](https://www.npmjs.com/package/@thi.ng/geom-clip-line)
6
6
  ![npm downloads](https://img.shields.io/npm/dm/@thi.ng/geom-clip-line.svg)
7
- [![Twitter Follow](https://img.shields.io/twitter/follow/thing_umbrella.svg?style=flat-square&label=twitter)](https://twitter.com/thing_umbrella)
7
+ [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  This project is part of the
10
10
  [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo.
@@ -20,7 +20,7 @@ This project is part of the
20
20
 
21
21
  ## About
22
22
 
23
- 2D line clipping (Liang-Barsky). This is a support package for [@thi.ng/geom](https://github.com/thi-ng/umbrella/tree/develop/packages/geom).
23
+ 2D line clipping (Liang-Barsky)
24
24
 
25
25
  Current implementation is based on [toxiclibs](http://toxiclibs.org)
26
26
  (Java) and Clojure version [thi.ng/geom-clj](http://thi.ng/geom-clj).
@@ -54,14 +54,11 @@ ES module import:
54
54
 
55
55
  For Node.js REPL:
56
56
 
57
- ```text
58
- # with flag only for < v16
59
- node --experimental-repl-await
60
-
61
- > const geomClipLine = await import("@thi.ng/geom-clip-line");
57
+ ```js
58
+ const geomClipLine = await import("@thi.ng/geom-clip-line");
62
59
  ```
63
60
 
64
- Package sizes (brotli'd, pre-treeshake): ESM: 522 bytes
61
+ Package sizes (brotli'd, pre-treeshake): ESM: 661 bytes
65
62
 
66
63
  ## Dependencies
67
64
 
@@ -99,7 +96,7 @@ liangBarsky2(
99
96
 
100
97
  ## Authors
101
98
 
102
- Karsten Schmidt
99
+ - [Karsten Schmidt](https://thi.ng)
103
100
 
104
101
  If this project contributes to an academic publication, please cite it as:
105
102
 
@@ -114,4 +111,4 @@ If this project contributes to an academic publication, please cite it as:
114
111
 
115
112
  ## License
116
113
 
117
- &copy; 2013 - 2022 Karsten Schmidt // Apache Software License 2.0
114
+ &copy; 2013 - 2022 Karsten Schmidt // Apache License 2.0
package/clip-poly.d.ts CHANGED
@@ -6,8 +6,16 @@ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
6
6
  *
7
7
  * @param a -
8
8
  * @param b -
9
- * @param pts -
9
+ * @param poly -
10
10
  */
11
- export declare const clipLinePoly: (a: ReadonlyVec, b: ReadonlyVec, pts: ReadonlyVec[]) => Vec[][] | undefined;
12
- export declare const clipLineSegmentPoly: (a: ReadonlyVec, b: ReadonlyVec, pts: ReadonlyVec[]) => Vec[][] | undefined;
11
+ export declare const clipLinePoly: (a: ReadonlyVec, b: ReadonlyVec, poly: ReadonlyVec[]) => Vec[][] | undefined;
12
+ export declare const clipLineSegmentPoly: (a: ReadonlyVec, b: ReadonlyVec, poly: ReadonlyVec[]) => Vec[][] | undefined;
13
+ /**
14
+ * Similar to {@link clipLineSegmentPoly}, but for polylines. Returns array of
15
+ * new vertex chunks where the given polyline is inside the given bounding poly.
16
+ *
17
+ * @param pts
18
+ * @param poly
19
+ */
20
+ export declare const clipPolylinePoly: (pts: ReadonlyVec[], poly: ReadonlyVec[]) => ReadonlyVec[][];
13
21
  //# sourceMappingURL=clip-poly.d.ts.map
package/clip-poly.js CHANGED
@@ -9,16 +9,16 @@ import { direction2 } from "@thi.ng/vectors/direction";
9
9
  *
10
10
  * @param a -
11
11
  * @param b -
12
- * @param pts -
12
+ * @param poly -
13
13
  */
14
- export const clipLinePoly = (a, b, pts) => {
15
- const isecs = intersectRayPolylineAll(a, direction2([], a, b), pts, true).isec;
14
+ export const clipLinePoly = (a, b, poly) => {
15
+ const isecs = intersectRayPolylineAll(a, direction2([], a, b), poly, true).isec;
16
16
  return isecs ? collectSegments(isecs) : undefined;
17
17
  };
18
- export const clipLineSegmentPoly = (a, b, pts) => {
19
- const isecs = intersectLinePolylineAll(a, b, pts, true).isec;
20
- const isAInside = pointInPolygon2(a, pts);
21
- const isBInside = pointInPolygon2(b, pts);
18
+ export const clipLineSegmentPoly = (a, b, poly) => {
19
+ const isecs = intersectLinePolylineAll(a, b, poly, true).isec;
20
+ const isAInside = pointInPolygon2(a, poly);
21
+ const isBInside = pointInPolygon2(b, poly);
22
22
  if (!isecs) {
23
23
  return isAInside && isBInside ? [[a, b]] : undefined;
24
24
  }
@@ -26,6 +26,50 @@ export const clipLineSegmentPoly = (a, b, pts) => {
26
26
  isBInside && isecs.push(b);
27
27
  return collectSegments(isecs);
28
28
  };
29
+ /**
30
+ * Similar to {@link clipLineSegmentPoly}, but for polylines. Returns array of
31
+ * new vertex chunks where the given polyline is inside the given bounding poly.
32
+ *
33
+ * @param pts
34
+ * @param poly
35
+ */
36
+ export const clipPolylinePoly = (pts, poly) => {
37
+ let res = [];
38
+ if (pts.length < 2)
39
+ return res;
40
+ let isAInside = pointInPolygon2(pts[0], poly);
41
+ for (let i = 0, n = pts.length - 1; i < n; i++) {
42
+ const a = pts[i];
43
+ const b = pts[i + 1];
44
+ const isBInside = pointInPolygon2(b, poly);
45
+ const isecs = intersectLinePolylineAll(a, b, poly, true).isec;
46
+ if (!isecs) {
47
+ if (isAInside && isBInside) {
48
+ if (res.length)
49
+ res[res.length - 1].push(b);
50
+ else
51
+ res.push([a, b]);
52
+ }
53
+ }
54
+ else {
55
+ isAInside && isecs.unshift(a);
56
+ isBInside && isecs.push(b);
57
+ const [first, ...segments] = collectSegments(isecs);
58
+ if (isAInside) {
59
+ if (res.length)
60
+ res[res.length - 1].push(first[1]);
61
+ else
62
+ res.push(first);
63
+ }
64
+ else {
65
+ res.push(first);
66
+ }
67
+ res.push(...segments);
68
+ }
69
+ isAInside = isBInside;
70
+ }
71
+ return res;
72
+ };
29
73
  const collectSegments = (isecs) => {
30
74
  const segments = [];
31
75
  for (let i = 0, n = isecs.length - 1; i < n; i += 2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/geom-clip-line",
3
- "version": "2.1.37",
3
+ "version": "2.2.1",
4
4
  "description": "2D line clipping (Liang-Barsky)",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -21,7 +21,7 @@
21
21
  "url": "https://patreon.com/thing_umbrella"
22
22
  }
23
23
  ],
24
- "author": "Karsten Schmidt <k+npm@thi.ng>",
24
+ "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
27
  "build": "yarn clean && tsc --declaration",
@@ -34,17 +34,17 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.5.1",
38
- "@thi.ng/geom-isec": "^2.1.37",
39
- "@thi.ng/vectors": "^7.5.26"
37
+ "@thi.ng/api": "^8.6.0",
38
+ "@thi.ng/geom-isec": "^2.1.38",
39
+ "@thi.ng/vectors": "^7.5.27"
40
40
  },
41
41
  "devDependencies": {
42
- "@microsoft/api-extractor": "^7.33.5",
43
- "@thi.ng/testament": "^0.3.6",
42
+ "@microsoft/api-extractor": "^7.33.7",
43
+ "@thi.ng/testament": "^0.3.7",
44
44
  "rimraf": "^3.0.2",
45
45
  "tools": "^0.0.1",
46
- "typedoc": "^0.23.20",
47
- "typescript": "^4.8.4"
46
+ "typedoc": "^0.23.22",
47
+ "typescript": "^4.9.4"
48
48
  },
49
49
  "keywords": [
50
50
  "2d",
@@ -84,5 +84,5 @@
84
84
  ],
85
85
  "year": 2013
86
86
  },
87
- "gitHead": "1fe40da507070653f420156d91e6b27cf682004f\n"
87
+ "gitHead": "f445a9cc8022bcdebbf6ff91fd66ced016d72f01\n"
88
88
  }