@math.gl/polygon 3.5.7 → 3.6.0-alpha.3

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 (79) hide show
  1. package/dist/cut-by-grid.d.ts +21 -0
  2. package/dist/cut-by-grid.d.ts.map +1 -0
  3. package/dist/cut-by-grid.js +214 -0
  4. package/dist/cut-by-mercator-bounds.d.ts +17 -0
  5. package/dist/cut-by-mercator-bounds.d.ts.map +1 -0
  6. package/dist/cut-by-mercator-bounds.js +144 -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 +29 -25
  11. package/dist/es5/cut-by-grid.js.map +1 -1
  12. package/dist/es5/cut-by-mercator-bounds.js +24 -19
  13. package/dist/es5/cut-by-mercator-bounds.js.map +1 -1
  14. package/dist/es5/earcut.js +11 -10
  15. package/dist/es5/earcut.js.map +1 -1
  16. package/dist/es5/index.js.map +1 -1
  17. package/dist/es5/lineclip.js +20 -16
  18. package/dist/es5/lineclip.js.map +1 -1
  19. package/dist/es5/polygon-utils.js +6 -4
  20. package/dist/es5/polygon-utils.js.map +1 -1
  21. package/dist/es5/polygon.js +5 -0
  22. package/dist/es5/polygon.js.map +1 -1
  23. package/dist/es5/utils.js.map +1 -1
  24. package/dist/esm/cut-by-grid.js +5 -5
  25. package/dist/esm/cut-by-grid.js.map +1 -1
  26. package/dist/esm/cut-by-mercator-bounds.js +5 -5
  27. package/dist/esm/cut-by-mercator-bounds.js.map +1 -1
  28. package/dist/esm/earcut.js +9 -10
  29. package/dist/esm/earcut.js.map +1 -1
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/lineclip.js +5 -5
  32. package/dist/esm/lineclip.js.map +1 -1
  33. package/dist/esm/polygon-utils.js +7 -4
  34. package/dist/esm/polygon-utils.js.map +1 -1
  35. package/dist/esm/polygon.js +7 -0
  36. package/dist/esm/polygon.js.map +1 -1
  37. package/dist/esm/utils.js.map +1 -1
  38. package/dist/index.d.ts +8 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +8 -0
  41. package/dist/lineclip.d.ts +30 -0
  42. package/dist/lineclip.d.ts.map +1 -0
  43. package/dist/lineclip.js +178 -0
  44. package/dist/{es5/polygon-utils.d.ts → polygon-utils.d.ts} +28 -64
  45. package/dist/polygon-utils.d.ts.map +1 -0
  46. package/dist/polygon-utils.js +140 -0
  47. package/dist/polygon.d.ts +41 -0
  48. package/dist/polygon.d.ts.map +1 -0
  49. package/dist/polygon.js +67 -0
  50. package/dist/utils.d.ts +5 -0
  51. package/dist/utils.d.ts.map +1 -0
  52. package/dist/utils.js +34 -0
  53. package/package.json +4 -3
  54. package/src/{cut-by-grid.js → cut-by-grid.ts} +79 -33
  55. package/src/{cut-by-mercator-bounds.js → cut-by-mercator-bounds.ts} +51 -22
  56. package/src/{earcut.js → earcut.ts} +26 -14
  57. package/src/{index.js → index.ts} +0 -0
  58. package/src/{lineclip.js → lineclip.ts} +61 -33
  59. package/src/polygon-utils.ts +228 -0
  60. package/src/polygon.ts +98 -0
  61. package/src/{utils.js → utils.ts} +11 -3
  62. package/dist/es5/cut-by-grid.d.ts +0 -24
  63. package/dist/es5/cut-by-mercator-bounds.d.ts +0 -23
  64. package/dist/es5/earcut.d.ts +0 -9
  65. package/dist/es5/lineclip.d.ts +0 -25
  66. package/dist/es5/polygon.d.ts +0 -36
  67. package/dist/esm/cut-by-grid.d.ts +0 -24
  68. package/dist/esm/cut-by-mercator-bounds.d.ts +0 -23
  69. package/dist/esm/lineclip.d.ts +0 -25
  70. package/dist/esm/polygon-utils.d.ts +0 -117
  71. package/dist/esm/polygon.d.ts +0 -36
  72. package/src/cut-by-grid.d.ts +0 -24
  73. package/src/cut-by-mercator-bounds.d.ts +0 -23
  74. package/src/earcut.d.ts +0 -9
  75. package/src/lineclip.d.ts +0 -25
  76. package/src/polygon-utils.d.ts +0 -117
  77. package/src/polygon-utils.js +0 -127
  78. package/src/polygon.d.ts +0 -36
  79. package/src/polygon.js +0 -66
@@ -0,0 +1,228 @@
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(
136
+ points: NumericArray,
137
+ options: {start?: number; end?: number; size?: number}
138
+ ): void {
139
+ const {start = 0, end = points.length, size = 2} = options;
140
+
141
+ const numPoints = (end - start) / size;
142
+ const numSwaps = Math.floor(numPoints / 2);
143
+ for (let i = 0; i < numSwaps; ++i) {
144
+ const b1 = start + i * size;
145
+ const b2 = start + (numPoints - 1 - i) * size;
146
+ for (let j = 0; j < size; ++j) {
147
+ const tmp = points[b1 + j];
148
+ points[b1 + j] = points[b2 + j];
149
+ points[b2 + j] = tmp;
150
+ }
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
156
+ * Note: points are modified in-place.
157
+ * @param points Array of points that represent the polygon.
158
+ * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.
159
+ * @param options Parameters of the polygon.
160
+ * @return Returns true if the winding direction was changed.
161
+ */
162
+ export function modifyPolygonWindingDirectionPoints(
163
+ points: PointsArray,
164
+ direction: number,
165
+ options: PolygonParams = {}
166
+ ): boolean {
167
+ const currentDirection = getPolygonWindingDirectionPoints(points, options);
168
+ if (currentDirection !== direction) {
169
+ points.reverse();
170
+ return true;
171
+ }
172
+ return false;
173
+ }
174
+
175
+ /**
176
+ * Returns winding direction of the polygon.
177
+ * @param points Array of points that represent the polygon.
178
+ * @param options Parameters of the polygon.
179
+ * @returns Winding direction of the polygon.
180
+ */
181
+ export function getPolygonWindingDirectionPoints(
182
+ points: PointsArray,
183
+ options: PolygonParams = {}
184
+ ): number {
185
+ return Math.sign(getPolygonSignedAreaPoints(points, options));
186
+ }
187
+
188
+ /**
189
+ * Returns signed area of the polygon.
190
+ * @param points Array of points that represent the polygon.
191
+ * @param options Parameters of the polygon.
192
+ * @returns Signed area of the polygon.
193
+ */
194
+ export function getPolygonSignedAreaPoints(
195
+ points: PointsArray,
196
+ options: PolygonParams = {}
197
+ ): number {
198
+ // https://en.wikipedia.org/wiki/Shoelace_formula
199
+ const {start = 0, end = points.length} = options;
200
+ let area = 0;
201
+ for (let i = start, j = end - 1; i < end; ++i) {
202
+ area += (points[i][0] - points[j][0]) * (points[i][1] + points[j][1]);
203
+ j = i;
204
+ }
205
+ return area / 2;
206
+ }
207
+
208
+ /**
209
+ * Calls visitor callback for each segment in the polygon.
210
+ * @param points Array of points that represent the polygon.
211
+ * @param visitor A callback to call for each segment.
212
+ * @param options Parameters of the polygon.
213
+ */
214
+ export function forEachSegmentInPolygonPoints(
215
+ points: PointsArray,
216
+ visitor: SegmentVisitorPoints,
217
+ options: PolygonParams = {}
218
+ ): void {
219
+ const {start = 0, end = points.length, isClosed} = options;
220
+ for (let i = start; i < end - 1; ++i) {
221
+ visitor(points[i], points[i + 1], i, i + 1);
222
+ }
223
+
224
+ const isClosedEx = isClosed || equals(points[end - 1], points[0]);
225
+ if (!isClosedEx) {
226
+ visitor(points[end - 1], points[0], end - 1, 0);
227
+ }
228
+ }
package/src/polygon.ts ADDED
@@ -0,0 +1,98 @@
1
+ /* eslint-disable no-undef, no-console */
2
+ import {isArray} from '@math.gl/core';
3
+ import type {SegmentVisitorPoints} from './polygon-utils';
4
+ import type {NumericArray} from '@math.gl/core';
5
+
6
+ import {
7
+ getPolygonSignedArea,
8
+ forEachSegmentInPolygon,
9
+ modifyPolygonWindingDirection,
10
+ getPolygonSignedAreaPoints,
11
+ forEachSegmentInPolygonPoints,
12
+ modifyPolygonWindingDirectionPoints
13
+ } from './polygon-utils';
14
+
15
+ export type PolygonOptions = {
16
+ start?: number;
17
+ end?: number;
18
+ size?: number;
19
+ isClosed?: boolean;
20
+ };
21
+
22
+ export default class Polygon {
23
+ points: NumericArray | number[][];
24
+ isFlatArray: boolean;
25
+ options: PolygonOptions;
26
+
27
+ constructor(points: NumericArray | number[][], options: PolygonOptions = {}) {
28
+ this.points = points;
29
+ this.isFlatArray = !isArray(points[0]);
30
+
31
+ this.options = {
32
+ start: options.start || 0,
33
+ end: options.end || points.length,
34
+ size: options.size || 2,
35
+ isClosed: options.isClosed
36
+ };
37
+
38
+ Object.freeze(this);
39
+ }
40
+
41
+ /**
42
+ * Returns signed area of the polygon.
43
+ * @returns Signed area of the polygon.
44
+ */
45
+ getSignedArea(): number {
46
+ if (this.isFlatArray) return getPolygonSignedArea(this.points as NumericArray, this.options);
47
+
48
+ return getPolygonSignedAreaPoints(this.points as number[][], this.options);
49
+ }
50
+
51
+ /**
52
+ * Returns absolute area of the polygon.
53
+ * @returns Absolute area of the polygon.
54
+ */
55
+ getArea(): number {
56
+ return Math.abs(this.getSignedArea());
57
+ }
58
+
59
+ /**
60
+ * Returns winding direction of the polygon.
61
+ * @returns Winding direction of the polygon. 1 is for clockwise, -1 for counterclockwise winding direction.
62
+ */
63
+ getWindingDirection(): number {
64
+ return Math.sign(this.getSignedArea());
65
+ }
66
+
67
+ /**
68
+ * Calls the visitor callback for each segment in the polygon.
69
+ * @param visitor A callback to call for each segment.
70
+ */
71
+ forEachSegment(visitor: SegmentVisitorPoints): void {
72
+ if (this.isFlatArray) {
73
+ forEachSegmentInPolygon(
74
+ this.points as NumericArray,
75
+ // eslint-disable-next-line max-params
76
+ (x1, y1, x2, y2, i1, i2) => {
77
+ // TODO @igorDykhta original visitor uses arrays for each point, but with flat arrays performance degrades if we allocate points for each segment
78
+ visitor([x1, y1], [x2, y2], i1, i2);
79
+ },
80
+ this.options
81
+ );
82
+ } else {
83
+ forEachSegmentInPolygonPoints(this.points as number[][], visitor, this.options);
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
89
+ * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.
90
+ * @return Returns true if the winding direction was changed.
91
+ */
92
+ modifyWindingDirection(direction: number): boolean {
93
+ if (this.isFlatArray) {
94
+ return modifyPolygonWindingDirection(this.points as NumericArray, direction, this.options);
95
+ }
96
+ return modifyPolygonWindingDirectionPoints(this.points as number[][], direction, this.options);
97
+ }
98
+ }
@@ -1,4 +1,6 @@
1
- export function push(target, source) {
1
+ import type {NumericArray} from '@math.gl/core';
2
+
3
+ export function push(target: number[], source: number[]): boolean {
2
4
  const size = source.length;
3
5
  const startIndex = target.length;
4
6
 
@@ -22,14 +24,20 @@ export function push(target, source) {
22
24
  return true;
23
25
  }
24
26
 
25
- export function copy(target, source) {
27
+ export function copy(target: number[], source: Readonly<NumericArray>): void {
26
28
  const size = source.length;
27
29
  for (let i = 0; i < size; i++) {
28
30
  target[i] = source[i];
29
31
  }
30
32
  }
31
33
 
32
- export function getPointAtIndex(positions, index, size, offset, out = []) {
34
+ export function getPointAtIndex(
35
+ positions: NumericArray,
36
+ index: number,
37
+ size: number,
38
+ offset: number,
39
+ out: number[] = []
40
+ ): number[] {
33
41
  const startI = offset + index * size;
34
42
  for (let i = 0; i < size; i++) {
35
43
  out[i] = positions[startI + i];
@@ -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;