@math.gl/polygon 3.5.6 → 3.6.0-alpha.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.
Files changed (80) hide show
  1. package/dist/cut-by-grid.d.ts +20 -0
  2. package/dist/cut-by-grid.d.ts.map +1 -0
  3. package/dist/cut-by-grid.js +216 -0
  4. package/dist/cut-by-mercator-bounds.d.ts +16 -0
  5. package/dist/cut-by-mercator-bounds.d.ts.map +1 -0
  6. package/dist/cut-by-mercator-bounds.js +145 -0
  7. package/dist/{esm/earcut.d.ts → earcut.d.ts} +4 -2
  8. package/dist/earcut.d.ts.map +1 -0
  9. package/dist/earcut.js +611 -0
  10. package/dist/es5/cut-by-grid.js +70 -79
  11. package/dist/es5/cut-by-grid.js.map +1 -1
  12. package/dist/es5/cut-by-mercator-bounds.js +55 -87
  13. package/dist/es5/cut-by-mercator-bounds.js.map +1 -1
  14. package/dist/es5/earcut.js +97 -102
  15. package/dist/es5/earcut.js.map +1 -1
  16. package/dist/es5/index.js +14 -14
  17. package/dist/es5/index.js.map +1 -1
  18. package/dist/es5/lineclip.js +38 -41
  19. package/dist/es5/lineclip.js.map +1 -1
  20. package/dist/es5/polygon-utils.js +61 -69
  21. package/dist/es5/polygon-utils.js.map +1 -1
  22. package/dist/es5/polygon.js +35 -43
  23. package/dist/es5/polygon.js.map +1 -1
  24. package/dist/es5/utils.js +11 -12
  25. package/dist/es5/utils.js.map +1 -1
  26. package/dist/esm/cut-by-grid.js +4 -4
  27. package/dist/esm/cut-by-grid.js.map +1 -1
  28. package/dist/esm/cut-by-mercator-bounds.js +5 -5
  29. package/dist/esm/cut-by-mercator-bounds.js.map +1 -1
  30. package/dist/esm/earcut.js +9 -10
  31. package/dist/esm/earcut.js.map +1 -1
  32. package/dist/esm/index.js.map +1 -1
  33. package/dist/esm/lineclip.js +5 -5
  34. package/dist/esm/lineclip.js.map +1 -1
  35. package/dist/esm/polygon-utils.js +7 -4
  36. package/dist/esm/polygon-utils.js.map +1 -1
  37. package/dist/esm/polygon.js +7 -0
  38. package/dist/esm/polygon.js.map +1 -1
  39. package/dist/esm/utils.js.map +1 -1
  40. package/dist/index.d.ts +8 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +8 -0
  43. package/dist/lineclip.d.ts +31 -0
  44. package/dist/lineclip.d.ts.map +1 -0
  45. package/dist/lineclip.js +178 -0
  46. package/dist/{es5/polygon-utils.d.ts → polygon-utils.d.ts} +28 -64
  47. package/dist/polygon-utils.d.ts.map +1 -0
  48. package/dist/polygon-utils.js +140 -0
  49. package/dist/polygon.d.ts +40 -0
  50. package/dist/polygon.d.ts.map +1 -0
  51. package/dist/polygon.js +67 -0
  52. package/dist/utils.d.ts +4 -0
  53. package/dist/utils.d.ts.map +1 -0
  54. package/dist/utils.js +34 -0
  55. package/package.json +4 -3
  56. package/src/{cut-by-grid.js → cut-by-grid.ts} +32 -4
  57. package/src/{cut-by-mercator-bounds.js → cut-by-mercator-bounds.ts} +26 -7
  58. package/src/{earcut.js → earcut.ts} +25 -13
  59. package/src/{index.js → index.ts} +0 -0
  60. package/src/{lineclip.js → lineclip.ts} +48 -20
  61. package/src/polygon-utils.ts +225 -0
  62. package/src/{polygon.js → polygon.ts} +40 -9
  63. package/src/{utils.js → utils.ts} +0 -0
  64. package/dist/es5/cut-by-grid.d.ts +0 -24
  65. package/dist/es5/cut-by-mercator-bounds.d.ts +0 -23
  66. package/dist/es5/earcut.d.ts +0 -9
  67. package/dist/es5/lineclip.d.ts +0 -25
  68. package/dist/es5/polygon.d.ts +0 -36
  69. package/dist/esm/cut-by-grid.d.ts +0 -24
  70. package/dist/esm/cut-by-mercator-bounds.d.ts +0 -23
  71. package/dist/esm/lineclip.d.ts +0 -25
  72. package/dist/esm/polygon-utils.d.ts +0 -117
  73. package/dist/esm/polygon.d.ts +0 -36
  74. package/src/cut-by-grid.d.ts +0 -24
  75. package/src/cut-by-mercator-bounds.d.ts +0 -23
  76. package/src/earcut.d.ts +0 -9
  77. package/src/lineclip.d.ts +0 -25
  78. package/src/polygon-utils.d.ts +0 -117
  79. package/src/polygon-utils.js +0 -127
  80. package/src/polygon.d.ts +0 -36
@@ -0,0 +1,225 @@
1
+ /* eslint-disable max-statements, max-depth, complexity, no-unused-expressions */
2
+
3
+ import {equals} from '@math.gl/core';
4
+ import type {NumericArray} from '@math.gl/core';
5
+
6
+ export enum WINDING {
7
+ CLOCKWISE = 1,
8
+ COUNTER_CLOCKWISE = -1
9
+ }
10
+
11
+ /** Polygon representation where each point is represented as a separate array of positions. */
12
+ type PointsArray = NumericArray[];
13
+
14
+ /** Segment visitor callback type for polygons defined with flat arrays, */
15
+ type SegmentVisitorFlat = (
16
+ p1x: number,
17
+ p1y: number,
18
+ p2x: number,
19
+ p2y: number,
20
+ i1: number,
21
+ i2: number
22
+ ) => void;
23
+
24
+ /** Segment visitor callback type for polygons defined with array of points. */
25
+ export type SegmentVisitorPoints = (
26
+ p1: NumericArray,
27
+ p2: NumericArray,
28
+ i1: number,
29
+ i2: number
30
+ ) => void;
31
+
32
+ /** Parameters of a polygon. */
33
+ type PolygonParams = {
34
+ start?: number; // Start index of the polygon in the array of positions. Defaults to 0.
35
+ end?: number; // End index of the polygon in the array of positions. Defaults to number of positions.
36
+ size?: number; // Size of a point, 2 (XZ) or 3 (XYZ). Defaults to 2. Affects only polygons stored in flat arrays.
37
+ isClosed?: boolean; // Indicates that the first point of the polygon is equal to the last point, and additional checks should be ommited.
38
+ };
39
+
40
+ /**
41
+ * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
42
+ * Note: points are modified in-place.
43
+ * @param points An array that represents points of the polygon.
44
+ * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.
45
+ * @param options Parameters of the polygon.
46
+ * @return Returns true if the winding direction was changed.
47
+ */
48
+ export function modifyPolygonWindingDirection(
49
+ points: NumericArray,
50
+ direction: number,
51
+ options: PolygonParams = {}
52
+ ): boolean {
53
+ const windingDirection = getPolygonWindingDirection(points, options);
54
+ if (windingDirection !== direction) {
55
+ reversePolygon(points, options);
56
+ return true;
57
+ }
58
+ return false;
59
+ }
60
+
61
+ /**
62
+ * Returns winding direction of the polygon.
63
+ * @param points An array that represents points of the polygon.
64
+ * @param options Parameters of the polygon.
65
+ * @returns Winding direction of the polygon.
66
+ */
67
+ export function getPolygonWindingDirection(
68
+ points: NumericArray,
69
+ options: PolygonParams = {}
70
+ ): number {
71
+ return Math.sign(getPolygonSignedArea(points, options));
72
+ }
73
+
74
+ /**
75
+ * Returns signed area of the polygon.
76
+ * @param points An array that represents points of the polygon.
77
+ * @param options Parameters of the polygon.
78
+ * @returns Signed area of the polygon.
79
+ * https://en.wikipedia.org/wiki/Shoelace_formula
80
+ */
81
+ export function getPolygonSignedArea(points: NumericArray, options: PolygonParams = {}): number {
82
+ const {start = 0, end = points.length} = options;
83
+ const dim = options.size || 2;
84
+ let area = 0;
85
+ for (let i = start, j = end - dim; i < end; i += dim) {
86
+ area += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);
87
+ j = i;
88
+ }
89
+ return area / 2;
90
+ }
91
+
92
+ /**
93
+ * Calls the visitor callback for each segment in the polygon.
94
+ * @param points An array that represents points of the polygon
95
+ * @param visitor A callback to call for each segment.
96
+ * @param options Parameters of the polygon.
97
+ */
98
+ export function forEachSegmentInPolygon(
99
+ points: NumericArray,
100
+ visitor: SegmentVisitorFlat,
101
+ options: PolygonParams = {}
102
+ ): void {
103
+ const {start = 0, end = points.length, size = 2, isClosed} = options;
104
+
105
+ const numPoints = (end - start) / size;
106
+ for (let i = 0; i < numPoints - 1; ++i) {
107
+ visitor(
108
+ points[start + i * size],
109
+ points[start + i * size + 1],
110
+ points[start + (i + 1) * size],
111
+ points[start + (i + 1) * size + 1],
112
+ i,
113
+ i + 1
114
+ );
115
+ }
116
+
117
+ const endPointIndex = start + (numPoints - 1) * size;
118
+ const isClosedEx =
119
+ isClosed ||
120
+ (equals(points[start], points[endPointIndex]) &&
121
+ equals(points[start + 1], points[endPointIndex + 1]));
122
+
123
+ if (!isClosedEx) {
124
+ visitor(
125
+ points[endPointIndex],
126
+ points[endPointIndex + 1],
127
+ points[start],
128
+ points[start + 1],
129
+ numPoints - 1,
130
+ 0
131
+ );
132
+ }
133
+ }
134
+
135
+ function reversePolygon(points, options) {
136
+ const {start = 0, end = points.length, size = 2} = options;
137
+
138
+ const numPoints = (end - start) / size;
139
+ const numSwaps = Math.floor(numPoints / 2);
140
+ for (let i = 0; i < numSwaps; ++i) {
141
+ const b1 = start + i * size;
142
+ const b2 = start + (numPoints - 1 - i) * size;
143
+ for (let j = 0; j < size; ++j) {
144
+ const tmp = points[b1 + j];
145
+ points[b1 + j] = points[b2 + j];
146
+ points[b2 + j] = tmp;
147
+ }
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
153
+ * Note: points are modified in-place.
154
+ * @param points Array of points that represent the polygon.
155
+ * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.
156
+ * @param options Parameters of the polygon.
157
+ * @return Returns true if the winding direction was changed.
158
+ */
159
+ export function modifyPolygonWindingDirectionPoints(
160
+ points: PointsArray,
161
+ direction: number,
162
+ options: PolygonParams = {}
163
+ ): boolean {
164
+ const currentDirection = getPolygonWindingDirectionPoints(points, options);
165
+ if (currentDirection !== direction) {
166
+ points.reverse();
167
+ return true;
168
+ }
169
+ return false;
170
+ }
171
+
172
+ /**
173
+ * Returns winding direction of the polygon.
174
+ * @param points Array of points that represent the polygon.
175
+ * @param options Parameters of the polygon.
176
+ * @returns Winding direction of the polygon.
177
+ */
178
+ export function getPolygonWindingDirectionPoints(
179
+ points: PointsArray,
180
+ options: PolygonParams = {}
181
+ ): number {
182
+ return Math.sign(getPolygonSignedAreaPoints(points, options));
183
+ }
184
+
185
+ /**
186
+ * Returns signed area of the polygon.
187
+ * @param points Array of points that represent the polygon.
188
+ * @param options Parameters of the polygon.
189
+ * @returns Signed area of the polygon.
190
+ */
191
+ export function getPolygonSignedAreaPoints(
192
+ points: PointsArray,
193
+ options: PolygonParams = {}
194
+ ): number {
195
+ // https://en.wikipedia.org/wiki/Shoelace_formula
196
+ const {start = 0, end = points.length} = options;
197
+ let area = 0;
198
+ for (let i = start, j = end - 1; i < end; ++i) {
199
+ area += (points[i][0] - points[j][0]) * (points[i][1] + points[j][1]);
200
+ j = i;
201
+ }
202
+ return area / 2;
203
+ }
204
+
205
+ /**
206
+ * Calls visitor callback for each segment in the polygon.
207
+ * @param points Array of points that represent the polygon.
208
+ * @param visitor A callback to call for each segment.
209
+ * @param options Parameters of the polygon.
210
+ */
211
+ export function forEachSegmentInPolygonPoints(
212
+ points: PointsArray,
213
+ visitor: SegmentVisitorPoints,
214
+ options: PolygonParams = {}
215
+ ): void {
216
+ const {start = 0, end = points.length, isClosed} = options;
217
+ for (let i = start; i < end - 1; ++i) {
218
+ visitor(points[i], points[i + 1], i, i + 1);
219
+ }
220
+
221
+ const isClosedEx = isClosed || equals(points[end - 1], points[0]);
222
+ if (!isClosedEx) {
223
+ visitor(points[end - 1], points[0], end - 1, 0);
224
+ }
225
+ }
@@ -1,7 +1,6 @@
1
- /* eslint-disable no-undef */
2
- /* eslint-disable no-console */
3
-
1
+ /* eslint-disable no-undef, no-console */
4
2
  import {isArray} from '@math.gl/core';
3
+ import type {SegmentVisitorPoints} from './polygon-utils';
5
4
 
6
5
  import {
7
6
  getPolygonSignedArea,
@@ -12,8 +11,19 @@ import {
12
11
  modifyPolygonWindingDirectionPoints
13
12
  } from './polygon-utils';
14
13
 
14
+ export type PolygonOptions = {
15
+ start?: number;
16
+ end?: number;
17
+ size?: number;
18
+ isClosed?: boolean;
19
+ };
20
+
15
21
  export default class Polygon {
16
- constructor(points, options = {}) {
22
+ points; // : number[];
23
+ isFlatArray: boolean;
24
+ options: PolygonOptions;
25
+
26
+ constructor(points /* : number[] */, options: PolygonOptions = {}) {
17
27
  this.points = points;
18
28
  this.isFlatArray = !isArray(points[0]);
19
29
 
@@ -27,21 +37,37 @@ export default class Polygon {
27
37
  Object.freeze(this);
28
38
  }
29
39
 
30
- getSignedArea() {
40
+ /**
41
+ * Returns signed area of the polygon.
42
+ * @returns Signed area of the polygon.
43
+ */
44
+ getSignedArea(): number {
31
45
  if (this.isFlatArray) return getPolygonSignedArea(this.points, this.options);
32
46
 
33
47
  return getPolygonSignedAreaPoints(this.points, this.options);
34
48
  }
35
49
 
36
- getArea() {
50
+ /**
51
+ * Returns absolute area of the polygon.
52
+ * @returns Absolute area of the polygon.
53
+ */
54
+ getArea(): number {
37
55
  return Math.abs(this.getSignedArea());
38
56
  }
39
57
 
40
- getWindingDirection() {
58
+ /**
59
+ * Returns winding direction of the polygon.
60
+ * @returns Winding direction of the polygon. 1 is for clockwise, -1 for counterclockwise winding direction.
61
+ */
62
+ getWindingDirection(): number {
41
63
  return Math.sign(this.getSignedArea());
42
64
  }
43
65
 
44
- forEachSegment(visitor) {
66
+ /**
67
+ * Calls the visitor callback for each segment in the polygon.
68
+ * @param visitor A callback to call for each segment.
69
+ */
70
+ forEachSegment(visitor: SegmentVisitorPoints): void {
45
71
  if (this.isFlatArray) {
46
72
  forEachSegmentInPolygon(
47
73
  this.points,
@@ -57,7 +83,12 @@ export default class Polygon {
57
83
  }
58
84
  }
59
85
 
60
- modifyWindingDirection(direction) {
86
+ /**
87
+ * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
88
+ * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.
89
+ * @return Returns true if the winding direction was changed.
90
+ */
91
+ modifyWindingDirection(direction: number): boolean {
61
92
  if (this.isFlatArray) {
62
93
  return modifyPolygonWindingDirection(this.points, direction, this.options);
63
94
  }
File without changes
@@ -1,24 +0,0 @@
1
- type Polygon = {positions: Array<number>, holeIndices?: Array<number>, vertexTypes?: Array<Number>};
2
-
3
- export function cutPolylineByGrid(
4
- positions : Array<number>,
5
- options? : {
6
- size? : number,
7
- broken? : boolean,
8
- gridResolution? : number,
9
- gridOffset? : [number, number],
10
- startIndex? : number,
11
- endIndex? : number
12
- }
13
- ) : Array<number> | Array<Array<number>>;
14
-
15
- export function cutPolygonByGrid(
16
- positions : Array<number>,
17
- holeIndices : Array<number> | null,
18
- options? : {
19
- size? : number,
20
- gridResolution? : number,
21
- gridOffset? : [number, number],
22
- edgeTypes? : boolean
23
- }
24
- ) : Array<Polygon>;
@@ -1,23 +0,0 @@
1
- import {Polygon} from "./cut-by-grid";
2
-
3
- export function cutPolylineByMercatorBounds(
4
- positions : Array<number>,
5
- options? : {
6
- size? : number,
7
- startIndex? : number,
8
- endIndex? : number,
9
- normalize? : boolean
10
- }
11
- ) : Array<number>;
12
-
13
- export function cutPolygonByMercatorBounds(
14
- positions : Array<number>,
15
- holeIndices : Array<number> | null,
16
- options? : {
17
- size? : number,
18
- normalize? : boolean,
19
- maxLatitude?: number,
20
- edgeTypes? : boolean
21
- }
22
- ) : Array<Polygon>;
23
-
@@ -1,9 +0,0 @@
1
- /**
2
- * Computes a triangulation of a polygon
3
- * @param positions a flat array of the vertex positions that define the polygon.
4
- * @param holeIndices an array of hole indices if any (e.g. [5, 8] for a 12-vertex input would mean one hole with vertices 5–7 and another with 8–11).
5
- * @param size the number of elements in each vertex. Size `2` will interpret `positions` as `[x0, y0, x1, y1, ...]` and size `3` will interpret `positions` as `[x0, y0, z0, x1, y1, z1, ...]`. Default `2`.
6
- * @param areas areas of outer polygon and holes as computed by `getPolygonSignedArea()`. Can be optionally supplied to speed up triangulation
7
- * @returns array of indices into the `positions` array that describes the triangulation of the polygon
8
- */
9
- export function earcut(positions: number[], holeIndices?: number[], size?: number, areas?: number[]): number[];
@@ -1,25 +0,0 @@
1
- type BoundingBox = [number, number, number, number];
2
-
3
- export function clipPolyline(
4
- positions : Array<number>,
5
- bbox : BoundingBox,
6
- options? : {
7
- size? : number,
8
- startIndex? : number,
9
- endIndex? : number
10
- }
11
- ) : Array<Array<number>>;
12
-
13
- export function clipPolygon(
14
- positions: Array<number>,
15
- bbox: BoundingBox,
16
- options? : {
17
- size? : number,
18
- startIndex? : number,
19
- endIndex? : number
20
- }
21
- ) : Array<number>;
22
-
23
- export function intersect(a : Array<number>, b : Array<number>, edge : number, bbox : BoundingBox, out? : Array<number>);
24
-
25
- export function bitCode(p: Array<number>, bbox : BoundingBox) : number;
@@ -1,36 +0,0 @@
1
- import {SegmentVisitorPoints} from './polygon-utils';
2
-
3
- export default class Polygon {
4
- constructor(points: number[], options: {start?: number, end?: number,size?: number, isClosed?: boolean});
5
-
6
- /**
7
- * Returns signed area of the polygon.
8
- * @returns Signed area of the polygon.
9
- */
10
- getSignedArea(): number;
11
-
12
- /**
13
- * Returns absolute area of the polygon.
14
- * @returns Absolute area of the polygon.
15
- */
16
- getArea(): number;
17
-
18
- /**
19
- * Returns winding direction of the polygon.
20
- * @returns Winding direction of the polygon. 1 is for clockwise, -1 for counterclockwise winding direction.
21
- */
22
- getWindingDirection(): number;
23
-
24
- /**
25
- * Calls the visitor callback for each segment in the polygon.
26
- * @param visitor A callback to call for each segment.
27
- */
28
- forEachSegment(SegmentVisitorPoints): void;
29
-
30
- /**
31
- * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
32
- * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.
33
- * @return Returns true if the winding direction was changed.
34
- */
35
- modifyWindingDirection(direction: number): boolean;
36
- }
@@ -1,24 +0,0 @@
1
- type Polygon = {positions: Array<number>, holeIndices?: Array<number>, vertexTypes?: Array<Number>};
2
-
3
- export function cutPolylineByGrid(
4
- positions : Array<number>,
5
- options? : {
6
- size? : number,
7
- broken? : boolean,
8
- gridResolution? : number,
9
- gridOffset? : [number, number],
10
- startIndex? : number,
11
- endIndex? : number
12
- }
13
- ) : Array<number> | Array<Array<number>>;
14
-
15
- export function cutPolygonByGrid(
16
- positions : Array<number>,
17
- holeIndices : Array<number> | null,
18
- options? : {
19
- size? : number,
20
- gridResolution? : number,
21
- gridOffset? : [number, number],
22
- edgeTypes? : boolean
23
- }
24
- ) : Array<Polygon>;
@@ -1,23 +0,0 @@
1
- import {Polygon} from "./cut-by-grid";
2
-
3
- export function cutPolylineByMercatorBounds(
4
- positions : Array<number>,
5
- options? : {
6
- size? : number,
7
- startIndex? : number,
8
- endIndex? : number,
9
- normalize? : boolean
10
- }
11
- ) : Array<number>;
12
-
13
- export function cutPolygonByMercatorBounds(
14
- positions : Array<number>,
15
- holeIndices : Array<number> | null,
16
- options? : {
17
- size? : number,
18
- normalize? : boolean,
19
- maxLatitude?: number,
20
- edgeTypes? : boolean
21
- }
22
- ) : Array<Polygon>;
23
-
@@ -1,25 +0,0 @@
1
- type BoundingBox = [number, number, number, number];
2
-
3
- export function clipPolyline(
4
- positions : Array<number>,
5
- bbox : BoundingBox,
6
- options? : {
7
- size? : number,
8
- startIndex? : number,
9
- endIndex? : number
10
- }
11
- ) : Array<Array<number>>;
12
-
13
- export function clipPolygon(
14
- positions: Array<number>,
15
- bbox: BoundingBox,
16
- options? : {
17
- size? : number,
18
- startIndex? : number,
19
- endIndex? : number
20
- }
21
- ) : Array<number>;
22
-
23
- export function intersect(a : Array<number>, b : Array<number>, edge : number, bbox : BoundingBox, out? : Array<number>);
24
-
25
- export function bitCode(p: Array<number>, bbox : BoundingBox) : number;
@@ -1,117 +0,0 @@
1
- import {NumberArray} from '@math.gl/core/';
2
-
3
- export const WINDING: {
4
- CLOCKWISE: number;
5
- COUNTER_CLOCKWISE: number;
6
- };
7
-
8
- // Polygon representation where each point is represented as a separate array of positions.
9
- type PointsArray = NumberArray[];
10
-
11
- // Segment visitor callback type for polygons defined with flat arrays,
12
- type SegmentVisitorFlat = (
13
- p1x: number,
14
- p1y: number,
15
- p2x: number,
16
- p2y: number,
17
- i1: number,
18
- i2: number
19
- ) => void;
20
-
21
- // Segment visitor callback type for polygons defined with array of points.
22
- export type SegmentVisitorPoints = (p1: NumberArray, p2: NumberArray, i1: number, i2: number) => void;
23
-
24
- // Parameters of a polygon.
25
- type PolygonParams = {
26
- start?: number; // Start index of the polygon in the array of positions. Defaults to 0.
27
- end?: number; // End index of the polygon in the array of positions. Defaults to number of positions.
28
- size?: number; // Size of a point, 2 (XZ) or 3 (XYZ). Defaults to 2. Affects only polygons stored in flat arrays.
29
- isClosed?: boolean; // Indicates that the first point of the polygon is equal to the last point, and additional checks should be ommited.
30
- };
31
-
32
- /**
33
- * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
34
- * Note: points are modified in-place.
35
- * @param points An array that represents points of the polygon.
36
- * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.
37
- * @param options Parameters of the polygon.
38
- * @return Returns true if the winding direction was changed.
39
- */
40
- export function modifyPolygonWindingDirection(
41
- points: NumberArray,
42
- direction: number,
43
- options?: PolygonParams
44
- ): boolean;
45
-
46
- /**
47
- * Returns winding direction of the polygon.
48
- * @param points An array that represents points of the polygon.
49
- * @param options Parameters of the polygon.
50
- * @returns Winding direction of the polygon.
51
- */
52
- export function getPolygonWindingDirection(points: NumberArray, options?: PolygonParams): number;
53
-
54
- /**
55
- * Returns signed area of the polygon.
56
- * @param points An array that represents points of the polygon.
57
- * @param options Parameters of the polygon.
58
- * @returns Signed area of the polygon.
59
- */
60
- export function getPolygonSignedArea(points: NumberArray, options?: PolygonParams): number;
61
-
62
- /**
63
- * Calls the visitor callback for each segment in the polygon.
64
- * @param points An array that represents points of the polygon
65
- * @param visitor A callback to call for each segment.
66
- * @param options Parameters of the polygon.
67
- */
68
- export function forEachSegmentInPolygon(
69
- points: NumberArray,
70
- visitor: SegmentVisitorFlat,
71
- options?: PolygonParams
72
- ): void;
73
-
74
- /**
75
- * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
76
- * Note: points are modified in-place.
77
- * @param points Array of points that represent the polygon.
78
- * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.
79
- * @param options Parameters of the polygon.
80
- * @return Returns true if the winding direction was changed.
81
- */
82
- export function modifyPolygonWindingDirectionPoints(
83
- points: PointsArray,
84
- direction: number,
85
- options?: PolygonParams
86
- ): boolean;
87
-
88
- /**
89
- * Returns winding direction of the polygon.
90
- * @param points Array of points that represent the polygon.
91
- * @param options Parameters of the polygon.
92
- * @returns Winding direction of the polygon.
93
- */
94
- export function getPolygonWindingDirectionPoints(
95
- points: PointsArray,
96
- options?: PolygonParams
97
- ): number;
98
-
99
- /**
100
- * Returns signed area of the polygon.
101
- * @param points Array of points that represent the polygon.
102
- * @param options Parameters of the polygon.
103
- * @returns Signed area of the polygon.
104
- */
105
- export function getPolygonSignedAreaPoints(points: PointsArray, options?: PolygonParams): number;
106
-
107
- /**
108
- * Calls visitor callback for each segment in the polygon.
109
- * @param points Array of points that represent the polygon.
110
- * @param visitor A callback to call for each segment.
111
- * @param options Parameters of the polygon.
112
- */
113
- export function forEachSegmentInPolygonPoints(
114
- points: PointsArray,
115
- visitor: SegmentVisitorPoints,
116
- options?: PolygonParams
117
- ): void;
@@ -1,36 +0,0 @@
1
- import {SegmentVisitorPoints} from './polygon-utils';
2
-
3
- export default class Polygon {
4
- constructor(points: number[], options: {start?: number, end?: number,size?: number, isClosed?: boolean});
5
-
6
- /**
7
- * Returns signed area of the polygon.
8
- * @returns Signed area of the polygon.
9
- */
10
- getSignedArea(): number;
11
-
12
- /**
13
- * Returns absolute area of the polygon.
14
- * @returns Absolute area of the polygon.
15
- */
16
- getArea(): number;
17
-
18
- /**
19
- * Returns winding direction of the polygon.
20
- * @returns Winding direction of the polygon. 1 is for clockwise, -1 for counterclockwise winding direction.
21
- */
22
- getWindingDirection(): number;
23
-
24
- /**
25
- * Calls the visitor callback for each segment in the polygon.
26
- * @param visitor A callback to call for each segment.
27
- */
28
- forEachSegment(SegmentVisitorPoints): void;
29
-
30
- /**
31
- * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
32
- * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.
33
- * @return Returns true if the winding direction was changed.
34
- */
35
- modifyWindingDirection(direction: number): boolean;
36
- }
@@ -1,24 +0,0 @@
1
- type Polygon = {positions: Array<number>, holeIndices?: Array<number>, vertexTypes?: Array<Number>};
2
-
3
- export function cutPolylineByGrid(
4
- positions : Array<number>,
5
- options? : {
6
- size? : number,
7
- broken? : boolean,
8
- gridResolution? : number,
9
- gridOffset? : [number, number],
10
- startIndex? : number,
11
- endIndex? : number
12
- }
13
- ) : Array<number> | Array<Array<number>>;
14
-
15
- export function cutPolygonByGrid(
16
- positions : Array<number>,
17
- holeIndices : Array<number> | null,
18
- options? : {
19
- size? : number,
20
- gridResolution? : number,
21
- gridOffset? : [number, number],
22
- edgeTypes? : boolean
23
- }
24
- ) : Array<Polygon>;