@thi.ng/geom-clip-poly 2.1.91 → 2.1.92
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 +1 -1
- package/index.js +27 -37
- package/package.json +10 -7
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
|
@@ -2,42 +2,32 @@ import { intersectLineLine } from "@thi.ng/geom-isec/line-line";
|
|
|
2
2
|
import { centroid } from "@thi.ng/geom-poly-utils/centroid";
|
|
3
3
|
import { EPS } from "@thi.ng/math/api";
|
|
4
4
|
import { corner2 } from "@thi.ng/vectors/clockwise";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const sign = corner2(ca, cb, bc, eps);
|
|
24
|
-
for (let np = pts.length, k = np - 1, l = 0; l < np; k = l, l++) {
|
|
25
|
-
const p = pts[k];
|
|
26
|
-
const q = pts[l];
|
|
27
|
-
const cqsign = corner2(ca, cb, q, eps);
|
|
28
|
-
if (corner2(ca, cb, p, eps) === sign) {
|
|
29
|
-
clipped.push(cqsign !== sign
|
|
30
|
-
? intersectLineLine(ca, cb, p, q).isec
|
|
31
|
-
: q);
|
|
32
|
-
}
|
|
33
|
-
else if (cqsign === sign) {
|
|
34
|
-
clipped.push(intersectLineLine(ca, cb, p, q).isec, q);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (clipped.length < 2) {
|
|
38
|
-
return [];
|
|
39
|
-
}
|
|
40
|
-
pts = clipped;
|
|
5
|
+
const sutherlandHodgeman = (pts, bounds, bc, eps = EPS) => {
|
|
6
|
+
bc = bc || centroid(bounds);
|
|
7
|
+
for (let ne = bounds.length, j = ne - 1, i = 0; i < ne; j = i, i++) {
|
|
8
|
+
const clipped = [];
|
|
9
|
+
const ca = bounds[j];
|
|
10
|
+
const cb = bounds[i];
|
|
11
|
+
const sign = corner2(ca, cb, bc, eps);
|
|
12
|
+
for (let np = pts.length, k = np - 1, l = 0; l < np; k = l, l++) {
|
|
13
|
+
const p = pts[k];
|
|
14
|
+
const q = pts[l];
|
|
15
|
+
const cqsign = corner2(ca, cb, q, eps);
|
|
16
|
+
if (corner2(ca, cb, p, eps) === sign) {
|
|
17
|
+
clipped.push(
|
|
18
|
+
cqsign !== sign ? intersectLineLine(ca, cb, p, q).isec : q
|
|
19
|
+
);
|
|
20
|
+
} else if (cqsign === sign) {
|
|
21
|
+
clipped.push(intersectLineLine(ca, cb, p, q).isec, q);
|
|
22
|
+
}
|
|
41
23
|
}
|
|
42
|
-
|
|
24
|
+
if (clipped.length < 2) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
pts = clipped;
|
|
28
|
+
}
|
|
29
|
+
return pts;
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
sutherlandHodgeman
|
|
43
33
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/geom-clip-poly",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.92",
|
|
4
4
|
"description": "2D polygon clipping / offsetting (Sutherland-Hodgeman, Grainer-Hormann)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,13 +35,14 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/geom-isec": "^2.1.
|
|
37
|
-
"@thi.ng/geom-poly-utils": "^2.3.
|
|
38
|
-
"@thi.ng/math": "^5.7.
|
|
39
|
-
"@thi.ng/vectors": "^7.8.
|
|
38
|
+
"@thi.ng/geom-isec": "^2.1.92",
|
|
39
|
+
"@thi.ng/geom-poly-utils": "^2.3.76",
|
|
40
|
+
"@thi.ng/math": "^5.7.7",
|
|
41
|
+
"@thi.ng/vectors": "^7.8.9"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@microsoft/api-extractor": "^7.38.3",
|
|
45
|
+
"esbuild": "^0.19.8",
|
|
43
46
|
"rimraf": "^5.0.5",
|
|
44
47
|
"tools": "^0.0.1",
|
|
45
48
|
"typedoc": "^0.25.4",
|
|
@@ -81,5 +84,5 @@
|
|
|
81
84
|
],
|
|
82
85
|
"year": 2013
|
|
83
86
|
},
|
|
84
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
85
88
|
}
|