@thi.ng/geom-clip-poly 2.1.90 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/index.js +27 -37
  3. package/package.json +10 -8
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-03T12:13:31Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
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.
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
- * Extended version of Sutherland-Hodgeman convex polygon clipping supporting
7
- * any convex boundary polygon (not only rects). Returns new array of clipped
8
- * vertices.
9
- *
10
- * https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm
11
- *
12
- * @param pts - subject poly vertices
13
- * @param bounds - clipping boundary vertices
14
- * @param bc - pre-computed boundary centroid
15
- * @param eps - edge classification tolerance
16
- */
17
- export const sutherlandHodgeman = (pts, bounds, bc, eps = EPS) => {
18
- bc = bc || centroid(bounds);
19
- for (let ne = bounds.length, j = ne - 1, i = 0; i < ne; j = i, i++) {
20
- const clipped = [];
21
- const ca = bounds[j];
22
- const cb = bounds[i];
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
- return pts;
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.90",
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 clean && tsc --declaration",
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,14 +35,14 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/geom-isec": "^2.1.90",
37
- "@thi.ng/geom-poly-utils": "^2.3.74",
38
- "@thi.ng/math": "^5.7.5",
39
- "@thi.ng/vectors": "^7.8.7"
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",
43
- "@thi.ng/testament": "^0.4.3",
45
+ "esbuild": "^0.19.8",
44
46
  "rimraf": "^5.0.5",
45
47
  "tools": "^0.0.1",
46
48
  "typedoc": "^0.25.4",
@@ -82,5 +84,5 @@
82
84
  ],
83
85
  "year": 2013
84
86
  },
85
- "gitHead": "04d1de79f256d7a53c6b5fd157b37f49bc88e11d\n"
87
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
86
88
  }