@thi.ng/geom-clip-line 2.1.36 → 2.2.0
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 +7 -1
- package/README.md +1 -1
- package/clip-poly.d.ts +11 -3
- package/clip-poly.js +51 -7
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-
|
|
3
|
+
- **Last updated**: 2022-12-10T14:04:38Z
|
|
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
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
|
|
9
|
+
* @param poly -
|
|
10
10
|
*/
|
|
11
|
-
export declare const clipLinePoly: (a: ReadonlyVec, b: ReadonlyVec,
|
|
12
|
-
export declare const clipLineSegmentPoly: (a: ReadonlyVec, b: ReadonlyVec,
|
|
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
|
|
12
|
+
* @param poly -
|
|
13
13
|
*/
|
|
14
|
-
export const clipLinePoly = (a, b,
|
|
15
|
-
const isecs = intersectRayPolylineAll(a, direction2([], a, b),
|
|
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,
|
|
19
|
-
const isecs = intersectLinePolylineAll(a, b,
|
|
20
|
-
const isAInside = pointInPolygon2(a,
|
|
21
|
-
const isBInside = pointInPolygon2(b,
|
|
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.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "2D line clipping (Liang-Barsky)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.5.
|
|
38
|
-
"@thi.ng/geom-isec": "^2.1.
|
|
39
|
-
"@thi.ng/vectors": "^7.5.
|
|
37
|
+
"@thi.ng/api": "^8.5.1",
|
|
38
|
+
"@thi.ng/geom-isec": "^2.1.37",
|
|
39
|
+
"@thi.ng/vectors": "^7.5.26"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@microsoft/api-extractor": "^7.33.5",
|
|
43
|
-
"@thi.ng/testament": "^0.3.
|
|
43
|
+
"@thi.ng/testament": "^0.3.6",
|
|
44
44
|
"rimraf": "^3.0.2",
|
|
45
45
|
"tools": "^0.0.1",
|
|
46
46
|
"typedoc": "^0.23.20",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
],
|
|
85
85
|
"year": 2013
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "5178ea1d7f4b2de86cf5101bdd73f6567518c0bd\n"
|
|
88
88
|
}
|