poly-extrude 0.16.0 → 0.17.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/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/poly-extrude.js +380 -47
- package/dist/poly-extrude.js.map +1 -1
- package/dist/poly-extrude.min.js +2 -2
- package/dist/poly-extrude.mjs +379 -48
- package/dist/poly-extrude.mjs.map +1 -1
- package/dist/polygon.d.ts +1 -0
- package/dist/polygon.js +43 -33
- package/dist/polygon.js.map +1 -1
- package/dist/polygonpath.d.ts +11 -0
- package/dist/polygonpath.js +262 -0
- package/dist/polygonpath.js.map +1 -0
- package/dist/util.d.ts +7 -1
- package/dist/util.js +63 -0
- package/dist/util.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +107 -6
- package/src/index.ts +5 -2
- package/src/polygon.ts +50 -32
- package/src/polygonpath.ts +315 -0
- package/src/util.ts +68 -1
package/src/util.ts
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
import { Vector3 } from './math/Vector3';
|
2
|
-
import { PolylineType, ResultType } from './type';
|
2
|
+
import { PolygonType, PolylineType, ResultType } from './type';
|
3
3
|
|
4
|
+
export function mergeArray(array1, array2) {
|
5
|
+
let index = array1.length - 1;
|
6
|
+
for (let i = 0, len = array2.length; i < len; i++) {
|
7
|
+
array1[++index] = array2[i];
|
8
|
+
}
|
9
|
+
}
|
4
10
|
/**
|
5
11
|
* https://github.com/Turfjs/turf/blob/master/packages/turf-boolean-clockwise/index.ts
|
6
12
|
* @param {*} ring
|
@@ -22,6 +28,67 @@ export function isClockwise(ring: PolylineType) {
|
|
22
28
|
return sum > 0;
|
23
29
|
}
|
24
30
|
|
31
|
+
|
32
|
+
export function validateRing(ring: PolylineType) {
|
33
|
+
if (!isClosedRing(ring)) {
|
34
|
+
ring.push(ring[0]);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
export function isClosedRing(ring: PolylineType) {
|
39
|
+
const len = ring.length;
|
40
|
+
const [x1, y1] = ring[0], [x2, y2] = ring[len - 1];
|
41
|
+
return (x1 === x2 && y1 === y2);
|
42
|
+
}
|
43
|
+
|
44
|
+
export function calPolygonPointsCount(polygon: PolygonType) {
|
45
|
+
let count = 0;
|
46
|
+
let i = 0;
|
47
|
+
const len = polygon.length;
|
48
|
+
while (i < len) {
|
49
|
+
count += (polygon[i].length);
|
50
|
+
i++;
|
51
|
+
}
|
52
|
+
return count;
|
53
|
+
}
|
54
|
+
|
55
|
+
export function getPolygonsBBOX(polygons, bbox?) {
|
56
|
+
bbox = bbox || [Infinity, Infinity, -Infinity, -Infinity];
|
57
|
+
for (let i = 0, len = polygons.length; i < len; i++) {
|
58
|
+
const p = polygons[i];
|
59
|
+
if (Array.isArray(p[0][0])) {
|
60
|
+
getPolygonsBBOX(p, bbox);
|
61
|
+
} else {
|
62
|
+
for (let j = 0, len1 = p.length; j < len1; j++) {
|
63
|
+
const c = p[j];
|
64
|
+
const [x, y] = c;
|
65
|
+
bbox[0] = Math.min(bbox[0], x);
|
66
|
+
bbox[1] = Math.min(bbox[1], y);
|
67
|
+
bbox[2] = Math.max(bbox[2], x);
|
68
|
+
bbox[3] = Math.max(bbox[3], y);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
return bbox;
|
73
|
+
}
|
74
|
+
|
75
|
+
export function validatePolygon(polygon: PolygonType) {
|
76
|
+
for (let i = 0, len = polygon.length; i < len; i++) {
|
77
|
+
const ring = polygon[i];
|
78
|
+
validateRing(ring);
|
79
|
+
if (i === 0) {
|
80
|
+
if (!isClockwise(ring)) {
|
81
|
+
polygon[i] = ring.reverse();
|
82
|
+
}
|
83
|
+
} else if (isClockwise(ring)) {
|
84
|
+
polygon[i] = ring.reverse();
|
85
|
+
}
|
86
|
+
if (isClosedRing(ring)) {
|
87
|
+
ring.splice(ring.length - 1, 1);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
25
92
|
function v3Sub(out, v1, v2) {
|
26
93
|
out[0] = v1[0] - v2[0];
|
27
94
|
out[1] = v1[1] - v2[1];
|