@maplibre/geojson-vt 6.3.3 → 7.0.0

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 (44) hide show
  1. package/dist/clip.d.ts.map +1 -1
  2. package/dist/cluster-tile-index.d.ts +8 -0
  3. package/dist/cluster-tile-index.d.ts.map +1 -1
  4. package/dist/convert.d.ts.map +1 -1
  5. package/dist/deconvert.d.ts +0 -1
  6. package/dist/deconvert.d.ts.map +1 -1
  7. package/dist/definitions.d.ts +66 -25
  8. package/dist/definitions.d.ts.map +1 -1
  9. package/dist/feature.d.ts +16 -12
  10. package/dist/feature.d.ts.map +1 -1
  11. package/dist/geojson-vt-dev.js +606 -461
  12. package/dist/geojson-vt.js +1 -1
  13. package/dist/geojson-vt.mjs +603 -458
  14. package/dist/geojson-vt.mjs.map +1 -1
  15. package/dist/index.d.ts +2 -3
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/simplify.d.ts +1 -1
  18. package/dist/simplify.d.ts.map +1 -1
  19. package/dist/tile-index.d.ts.map +1 -1
  20. package/dist/tile.d.ts +5 -2
  21. package/dist/tile.d.ts.map +1 -1
  22. package/dist/transform.d.ts +5 -6
  23. package/dist/transform.d.ts.map +1 -1
  24. package/dist/wrap.d.ts.map +1 -1
  25. package/package.json +1 -1
  26. package/src/clip.test.ts +52 -32
  27. package/src/clip.ts +225 -143
  28. package/src/cluster-tile-index.ts +29 -21
  29. package/src/convert.ts +77 -72
  30. package/src/deconvert.test.ts +29 -28
  31. package/src/deconvert.ts +51 -23
  32. package/src/definitions.ts +69 -17
  33. package/src/difference.test.ts +38 -75
  34. package/src/feature.ts +53 -51
  35. package/src/geojson-to-tile.ts +1 -1
  36. package/src/geojsonvt.test.ts +75 -0
  37. package/src/index.ts +1 -17
  38. package/src/simplify.ts +2 -2
  39. package/src/tile-index.test.ts +3 -9
  40. package/src/tile-index.ts +11 -10
  41. package/src/tile.ts +212 -92
  42. package/src/transform.test.ts +2 -3
  43. package/src/transform.ts +24 -99
  44. package/src/wrap.ts +12 -73
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import type { GeoJSONVTFeatureDiff, GeoJSONVTSourceDiff } from './difference';
2
- import type { GeoJSONVTInternalFeature, GeoJSONVTInternalLineStringFeature, GeoJSONVTInternalMultiLineStringFeature, GeoJSONVTInternalMultiPointFeature, GeoJSONVTInternalMultiPolygonFeature, GeoJSONVTInternalPointFeature, GeoJSONVTInternalPolygonFeature, GeoJSONVTOptions, GeoJSONToTileOptions, PartialGeoJSONVTFeature, SliceArray, SliceFixedArray, ClusterProperties, ClusterFeature, ClusterOrPointFeature, GeoJSONVTTile, GeoJSONVTFeature, GeoJSONVTFeaturePoint, GeoJSONVTFeatureNonPoint, GeoJSONVTInternalTileFeaturePoint, GeoJSONVTInternalTileFeatureNonPoint, GeoJSONVTInternalTile, GeoJSONVTInternalTileFeature, GeoJSONVTTileIndex, SuperclusterOptions, GeoJSONVTCoordinatesType } from './definitions';
3
- import type { KDBushWithData } from './cluster-tile-index';
2
+ import type { GeoJSONVTOptions, GeoJSONToTileOptions, ClusterProperties, ClusterFeature, ClusterOrPointFeature, GeoJSONVTTile, GeoJSONVTFeature, GeoJSONVTFeaturePoint, GeoJSONVTFeatureNonPoint, GeoJSONVTTileIndex, SuperclusterOptions, GeoJSONVTCoordinatesType } from './definitions';
4
3
  import { GeoJSONVT } from './geojsonvt';
5
4
  import { ClusterTileIndex } from './cluster-tile-index';
6
5
  import { geoJSONToTile } from './geojson-to-tile';
7
6
  import { GEOJSONVT_CLIP_START, GEOJSONVT_CLIP_END } from './tile';
8
7
  export { GeoJSONVT, ClusterTileIndex as Supercluster, geoJSONToTile, GEOJSONVT_CLIP_START, GEOJSONVT_CLIP_END };
9
- export type { GeoJSONVTInternalFeature, GeoJSONVTOptions, GeoJSONToTileOptions, GeoJSONVTInternalTile, GeoJSONVTInternalTileFeature, PartialGeoJSONVTFeature, SliceArray, SliceFixedArray, GeoJSONVTTile, GeoJSONVTFeature, GeoJSONVTSourceDiff, GeoJSONVTFeatureDiff, GeoJSONVTFeaturePoint, GeoJSONVTFeatureNonPoint, GeoJSONVTInternalTileFeaturePoint, GeoJSONVTInternalTileFeatureNonPoint, GeoJSONVTInternalPointFeature, GeoJSONVTInternalMultiPointFeature, GeoJSONVTInternalLineStringFeature, GeoJSONVTInternalMultiLineStringFeature, GeoJSONVTInternalPolygonFeature, GeoJSONVTInternalMultiPolygonFeature, SuperclusterOptions, GeoJSONVTCoordinatesType, ClusterProperties, ClusterFeature, ClusterOrPointFeature, KDBushWithData, GeoJSONVTTileIndex };
8
+ export type { GeoJSONVTOptions, GeoJSONToTileOptions, GeoJSONVTTile, GeoJSONVTFeature, GeoJSONVTSourceDiff, GeoJSONVTFeatureDiff, GeoJSONVTFeaturePoint, GeoJSONVTFeatureNonPoint, SuperclusterOptions, GeoJSONVTCoordinatesType, ClusterProperties, ClusterFeature, ClusterOrPointFeature, GeoJSONVTTileIndex };
10
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,oBAAoB,EAAE,mBAAmB,EAAC,MAAM,cAAc,CAAC;AAC5E,OAAO,KAAK,EAAC,wBAAwB,EAAE,kCAAkC,EAAE,uCAAuC,EAAE,kCAAkC,EAAE,oCAAoC,EAAE,6BAA6B,EAAE,+BAA+B,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,UAAU,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,qBAAqB,EAAE,aAAa,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,iCAAiC,EAAE,oCAAoC,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,wBAAwB,EAAC,MAAM,eAAe,CAAC;AAC9rB,OAAO,KAAK,EAAC,cAA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AO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAC,oBAAoB,EAAE,kBAAkB,EAAC,MAAM,QAAQ,CAAC;AAEhE,OAAO,EACH,SAAS,EACT,gBAAgB,IAAI,YAAY,EAChC,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EACrB,CAAA;AAED,YAAY,EACR,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EACrB,CAAC"}
@@ -5,5 +5,5 @@
5
5
  * @param last - index of the last coordinate in the segment
6
6
  * @param sqTolerance - square tolerance value
7
7
  */
8
- export declare function simplify(coords: number[], first: number, last: number, sqTolerance: number): void;
8
+ export declare function simplify(coords: number[] | Float64Array, first: number, last: number, sqTolerance: number): void;
9
9
  //# sourceMappingURL=simplify.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"simplify.d.ts","sourceRoot":"","sources":["../src/simplify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAQ1F"}
1
+ {"version":3,"file":"simplify.d.ts","sourceRoot":"","sources":["../src/simplify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAQzG"}
@@ -1 +1 @@
1
- {"version":3,"file":"tile-index.d.ts","sourceRoot":"","sources":["../src/tile-index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,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H,OAAO,CAAC,WAAW;IAQnB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,SAAS;IA4FjB;;;;OAIG;IACH,OAAO,CAAC,eAAe;CAuE1B"}
package/dist/tile.d.ts CHANGED
@@ -1,14 +1,17 @@
1
1
  import type { GeoJSONVTInternalFeature, GeoJSONVTInternalTile, GeoJSONVTOptions } from "./definitions";
2
2
  export declare const GEOJSONVT_CLIP_START = "geojsonvt_clip_start";
3
3
  export declare const GEOJSONVT_CLIP_END = "geojsonvt_clip_end";
4
+ type TileCoordsConstructor = Int16ArrayConstructor | Int32ArrayConstructor | Float64ArrayConstructor;
4
5
  /**
5
- * Creates a tile object from the given features
6
+ * Creates a tile object from the given features, with their coordinates in the tile's extent
6
7
  * @param features - the features to include in the tile
7
8
  * @param z
8
9
  * @param tx
9
10
  * @param ty
10
11
  * @param options - the options object
12
+ * @param CoordArray - what holds the coordinates, which has to be a `Float64Array` when the features are not cut at the tile's buffer
11
13
  * @returns the created tile
12
14
  */
13
- export declare function createTile(features: GeoJSONVTInternalFeature[], z: number, tx: number, ty: number, options: GeoJSONVTOptions): GeoJSONVTInternalTile;
15
+ export declare function createTile(features: GeoJSONVTInternalFeature[], z: number, tx: number, ty: number, options: GeoJSONVTOptions, CoordArray?: TileCoordsConstructor): GeoJSONVTInternalTile;
16
+ export {};
14
17
  //# sourceMappingURL=tile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tile.d.ts","sourceRoot":"","sources":["../src/tile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAyN,qBAAqB,EAAgC,gBAAgB,EAAmB,MAAM,eAAe,CAAC;AAE7W,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAC3D,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAEvD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,wBAAwB,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,qBAAqB,CAwBpJ"}
1
+ {"version":3,"file":"tile.d.ts","sourceRoot":"","sources":["../src/tile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAyN,qBAAqB,EAAgC,gBAAgB,EAA8C,MAAM,eAAe,CAAC;AAGxY,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAC3D,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAEvD,KAAK,qBAAqB,GAAG,qBAAqB,GAAG,qBAAqB,GAAG,uBAAuB,CAAC;AAoBrG;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,wBAAwB,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,UAAU,wBAAoC,GAAG,qBAAqB,CA+BpM"}
@@ -1,10 +1,9 @@
1
1
  import type { GeoJSONVTInternalTile, GeoJSONVTTile } from "./definitions";
2
2
  /**
3
- * Transforms the coordinates of each feature in the given tile from
4
- * mercator-projected space into (extent x extent) tile space.
5
- * @param tile - the tile to transform, this gets modified in place
6
- * @param extent - the tile extent (usually 4096)
7
- * @returns the transformed tile
3
+ * Turns a stored tile, which keeps its coordinates in flat arrays, into the tile `getTile` returns,
4
+ * with every position as an `[x, y]` pair. The stored tile stays as it is.
5
+ * @param tile - the stored tile
6
+ * @returns a new tile with the coordinates as pairs
8
7
  */
9
- export declare function transformTile(tile: GeoJSONVTInternalTile, extent: number): GeoJSONVTTile;
8
+ export declare function transformTile(tile: GeoJSONVTInternalTile): GeoJSONVTTile;
10
9
  //# sourceMappingURL=transform.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmD,qBAAqB,EAA2E,aAAa,EAAE,MAAM,eAAe,CAAC;AAEpM;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAmBxF"}
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,qBAAqB,EAAgC,aAAa,EAAuB,MAAM,eAAe,CAAC;AAE/I;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,qBAAqB,GAAG,aAAa,CAOxE"}
@@ -1 +1 @@
1
- {"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../src/wrap.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB,EAA+B,MAAM,eAAe,CAAC;AAG7G,wBAAgB,IAAI,CAAC,QAAQ,EAAE,wBAAwB,EAAE,EAAE,OAAO,EAAE,gBAAgB,GAAG,wBAAwB,EAAE,CAiBhH"}
1
+ {"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../src/wrap.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGhF,wBAAgB,IAAI,CAAC,QAAQ,EAAE,wBAAwB,EAAE,EAAE,OAAO,EAAE,gBAAgB,GAAG,wBAAwB,EAAE,CAiBhH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maplibre/geojson-vt",
3
- "version": "6.3.3",
3
+ "version": "7.0.0",
4
4
  "description": "Slice GeoJSON data into vector tiles efficiently",
5
5
  "type": "module",
6
6
  "exports": {
package/src/clip.test.ts CHANGED
@@ -1,30 +1,51 @@
1
1
 
2
2
  import {test, expect} from 'vitest';
3
3
  import {clip} from './clip';
4
- import type { SliceArray } from './definitions';
4
+ import type { GeoJSONVTInternalFeature, GeoJSONVTInternalLineStringFeature, GeoJSONVTInternalMultiPointFeature } from './definitions';
5
5
 
6
6
  const geom1 = [0,0,0,50,0,0,50,10,0,20,10,0,20,20,0,30,20,0,30,30,0,50,30,0,50,40,0,25,40,0,25,50,0,0,50,0,0,60,0,25,60,0];
7
7
  const geom2 = [0,0,0,50,0,0,50,10,0,0,10,0];
8
8
 
9
+ /**
10
+ * The coordinates of a feature with one ring, which has its number of positions and its size before it.
11
+ */
12
+ function ring(points: number[], size = 0): Float64Array {
13
+ return new Float64Array([points.length / 3, size, ...points]);
14
+ }
15
+
16
+ /**
17
+ * The rings of a feature, each as its `x, y, z` values.
18
+ */
19
+ function rings(feature: GeoJSONVTInternalFeature): number[][] {
20
+ const geometry = (feature as GeoJSONVTInternalLineStringFeature).geometry;
21
+ const result: number[][] = [];
22
+ for (let i = 0; i < geometry.length; i += 2 + geometry[i] * 3) {
23
+ result.push(Array.from(geometry.subarray(i + 2, i + 2 + geometry[i] * 3)));
24
+ }
25
+ return result;
26
+ }
27
+
9
28
  test('clips polylines', () => {
10
29
 
11
30
  const clipped = clip([
12
- {geometry: {points: geom1}, type: 'LineString', tags: { "1": 1}, minX: 0, minY: 0, maxX: 50, maxY: 60},
13
- {geometry: {points: geom2}, type: 'LineString', tags: { "2": 2}, minX: 0, minY: 0, maxX: 50, maxY: 10}
31
+ {geometry: ring(geom1), type: 'LineString', tags: { "1": 1}, minX: 0, minY: 0, maxX: 50, maxY: 60, worldOffset: 0},
32
+ {geometry: ring(geom2), type: 'LineString', tags: { "2": 2}, minX: 0, minY: 0, maxX: 50, maxY: 10, worldOffset: 0}
14
33
  ], 1, 10, 40, 0, -Infinity, Infinity, {});
15
34
 
16
- const expected = [
17
- {id: null as string, type: 'MultiLineString', geometry: [
18
- {points: [10,0,1,40,0,1]},
19
- {points: [40,10,1,20,10,0,20,20,0,30,20,0,30,30,0,40,30,1]},
20
- {points: [40,40,1,25,40,0,25,50,0,10,50,1]},
21
- {points: [10,60,1,25,60,0]}], tags: {"1": 1}, minX: 10, minY: 0, maxX: 40, maxY: 60},
22
- {id: null as string, type: 'MultiLineString', geometry: [
23
- {points: [10,0,1,40,0,1]},
24
- {points: [40,10,1,10,10,1]}], tags: {"2": 2}, minX: 10, minY: 0, maxX: 40, maxY: 10}
25
- ];
26
-
27
- expect(JSON.stringify(clipped)).toEqual(JSON.stringify(expected));
35
+ expect(clipped).toMatchObject([
36
+ {id: null, type: 'MultiLineString', tags: {"1": 1}, minX: 10, minY: 0, maxX: 40, maxY: 60},
37
+ {id: null, type: 'MultiLineString', tags: {"2": 2}, minX: 10, minY: 0, maxX: 40, maxY: 10}
38
+ ]);
39
+ expect(rings(clipped[0])).toEqual([
40
+ [10,0,1,40,0,1],
41
+ [40,10,1,20,10,0,20,20,0,30,20,0,30,30,0,40,30,1],
42
+ [40,40,1,25,40,0,25,50,0,10,50,1],
43
+ [10,60,1,25,60,0]
44
+ ]);
45
+ expect(rings(clipped[1])).toEqual([
46
+ [10,0,1,40,0,1],
47
+ [40,10,1,10,10,1]
48
+ ]);
28
49
  });
29
50
 
30
51
  test('clips lines with line metrics on', () => {
@@ -36,43 +57,42 @@ test('clips lines with line metrics on', () => {
36
57
  const dy = points[i + 4] - points[i + 1];
37
58
  size += Math.sqrt(dx * dx + dy * dy);
38
59
  }
39
- const geom: SliceArray = {points, size, start: 0, end: size};
40
60
 
41
- const clipped = clip([{id: 1, geometry: geom, type: 'LineString', tags: {}, minX: 0, minY: 0, maxX: 50, maxY: 60}],
61
+ const clipped = clip([{id: 1, geometry: ring(points, size), type: 'LineString', tags: {}, minX: 0, minY: 0, maxX: 50, maxY: 60, worldOffset: 0, start: 0, end: size, size}],
42
62
  1, 10, 40, 0, -Infinity, Infinity, {lineMetrics: true});
43
63
 
44
64
  expect(
45
- clipped.map(f => [(f.geometry as SliceArray).start, (f.geometry as SliceArray).end])).toEqual(
65
+ clipped.map(f => [(f as GeoJSONVTInternalLineStringFeature).start, (f as GeoJSONVTInternalLineStringFeature).end])).toEqual(
46
66
  [[10, 40], [70, 130], [160, 200], [230, 245]]
47
67
  );
48
68
  });
49
69
 
50
- function closed(geometry: number[]): SliceArray[] {
51
- return [{points: geometry.concat(geometry.slice(0, 3))}];
70
+ function closed(geometry: number[]): Float64Array {
71
+ return ring(geometry.concat(geometry.slice(0, 3)));
52
72
  }
53
73
 
54
74
  test('clips polygons', () => {
55
75
 
56
76
  const clipped = clip([
57
- {geometry: closed(geom1), type: 'Polygon', tags: {"1": 1}, minX: 0, minY: 0, maxX: 50, maxY: 60},
58
- {geometry: closed(geom2), type: 'Polygon', tags: {"2": 2}, minX: 0, minY: 0, maxX: 50, maxY: 10}
77
+ {geometry: closed(geom1), type: 'Polygon', tags: {"1": 1}, minX: 0, minY: 0, maxX: 50, maxY: 60, worldOffset: 0},
78
+ {geometry: closed(geom2), type: 'Polygon', tags: {"2": 2}, minX: 0, minY: 0, maxX: 50, maxY: 10, worldOffset: 0}
59
79
  ], 1, 10, 40, 0, -Infinity, Infinity, {});
60
80
 
61
- const expected = [
62
- {id: null as string, type: 'Polygon', geometry: [{points: [10,0,1,40,0,1,40,10,1,20,10,0,20,20,0,30,20,0,30,30,0,40,30,1,40,40,1,25,40,0,25,50,0,10,50,1,10,60,1,25,60,0,10,24,1,10,0,1]}], tags: {"1": 1}, minX: 10, minY: 0, maxX: 40, maxY: 60},
63
- {id: null as string, type: 'Polygon', geometry: [{points: [10,0,1,40,0,1,40,10,1,10,10,1,10,0,1]}], tags: {"2": 2}, minX: 10, minY: 0, maxX: 40, maxY: 10}
64
- ];
65
-
66
- expect(JSON.stringify(clipped)).toEqual(JSON.stringify(expected));
81
+ expect(clipped).toMatchObject([
82
+ {id: null, type: 'Polygon', tags: {"1": 1}, minX: 10, minY: 0, maxX: 40, maxY: 60},
83
+ {id: null, type: 'Polygon', tags: {"2": 2}, minX: 10, minY: 0, maxX: 40, maxY: 10}
84
+ ]);
85
+ expect(rings(clipped[0])).toEqual([[10,0,1,40,0,1,40,10,1,20,10,0,20,20,0,30,20,0,30,30,0,40,30,1,40,40,1,25,40,0,25,50,0,10,50,1,10,60,1,25,60,0,10,24,1,10,0,1]]);
86
+ expect(rings(clipped[1])).toEqual([[10,0,1,40,0,1,40,10,1,10,10,1,10,0,1]]);
67
87
  });
68
88
 
69
89
  test('clips points', () => {
70
90
 
71
91
  const clipped = clip([
72
- {geometry: geom1, type: 'MultiPoint', tags: {"1": 1}, minX: 0, minY: 0, maxX: 50, maxY: 60},
73
- {geometry: geom2, type: 'MultiPoint', tags: {"2": 2}, minX: 0, minY: 0, maxX: 50, maxY: 10}
92
+ {geometry: new Float64Array(geom1), type: 'MultiPoint', tags: {"1": 1}, minX: 0, minY: 0, maxX: 50, maxY: 60, worldOffset: 0},
93
+ {geometry: new Float64Array(geom2), type: 'MultiPoint', tags: {"2": 2}, minX: 0, minY: 0, maxX: 50, maxY: 10, worldOffset: 0}
74
94
  ], 1, 10, 40, 0, -Infinity, Infinity, {});
75
95
 
76
- expect(clipped).toEqual([{id: null, type: 'MultiPoint',
77
- geometry: [20,10,0,20,20,0,30,20,0,30,30,0,25,40,0,25,50,0,25,60,0], tags: {"1": 1}, minX: 20, minY: 10, maxX: 30, maxY: 60}]);
96
+ expect(clipped).toMatchObject([{id: null, type: 'MultiPoint', tags: {"1": 1}, minX: 20, minY: 10, maxX: 30, maxY: 60}]);
97
+ expect(Array.from((clipped[0] as GeoJSONVTInternalMultiPointFeature).geometry)).toEqual([20,10,0,20,20,0,30,20,0,30,30,0,25,40,0,25,50,0,25,60,0]);
78
98
  });