@maplibre/mlt 1.1.2 → 1.1.5
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/decoding/decodingTestUtils.d.ts +75 -0
- package/dist/decoding/decodingTestUtils.js +285 -0
- package/dist/decoding/decodingTestUtils.js.map +1 -0
- package/dist/decoding/decodingUtils.d.ts +5 -8
- package/dist/decoding/decodingUtils.js +22 -49
- package/dist/decoding/decodingUtils.js.map +1 -1
- package/dist/decoding/decodingUtils.spec.js +85 -69
- package/dist/decoding/decodingUtils.spec.js.map +1 -1
- package/dist/decoding/fsstDecoder.spec.js +52 -35
- package/dist/decoding/fsstDecoder.spec.js.map +1 -1
- package/dist/decoding/geometryDecoder.js +41 -30
- package/dist/decoding/geometryDecoder.js.map +1 -1
- package/dist/decoding/integerDecodingUtils.d.ts +18 -31
- package/dist/decoding/integerDecodingUtils.js +134 -299
- package/dist/decoding/integerDecodingUtils.js.map +1 -1
- package/dist/decoding/integerDecodingUtils.spec.js +254 -148
- package/dist/decoding/integerDecodingUtils.spec.js.map +1 -1
- package/dist/decoding/integerStreamDecoder.d.ts +4 -6
- package/dist/decoding/integerStreamDecoder.js +104 -122
- package/dist/decoding/integerStreamDecoder.js.map +1 -1
- package/dist/decoding/integerStreamDecoder.spec.js +370 -131
- package/dist/decoding/integerStreamDecoder.spec.js.map +1 -1
- package/dist/decoding/propertyDecoder.js +14 -24
- package/dist/decoding/propertyDecoder.js.map +1 -1
- package/dist/decoding/propertyDecoder.spec.js +409 -606
- package/dist/decoding/propertyDecoder.spec.js.map +1 -1
- package/dist/decoding/stringDecoder.js +10 -10
- package/dist/decoding/stringDecoder.js.map +1 -1
- package/dist/decoding/stringDecoder.spec.js +352 -320
- package/dist/decoding/stringDecoder.spec.js.map +1 -1
- package/dist/decoding/unpackNullableUtils.d.ts +25 -0
- package/dist/decoding/unpackNullableUtils.js +51 -0
- package/dist/decoding/unpackNullableUtils.js.map +1 -0
- package/dist/decoding/unpackNullableUtils.spec.js +71 -0
- package/dist/decoding/unpackNullableUtils.spec.js.map +1 -0
- package/dist/encoding/embeddedTilesetMetadataEncoder.d.ts +16 -0
- package/dist/encoding/embeddedTilesetMetadataEncoder.js +40 -0
- package/dist/encoding/embeddedTilesetMetadataEncoder.js.map +1 -0
- package/dist/encoding/encodingUtils.d.ts +7 -0
- package/dist/encoding/encodingUtils.js +107 -0
- package/dist/encoding/encodingUtils.js.map +1 -0
- package/dist/encoding/fsstEncoder.d.ts +21 -0
- package/dist/encoding/fsstEncoder.js +78 -0
- package/dist/encoding/fsstEncoder.js.map +1 -0
- package/dist/encoding/integerEncodingUtils.d.ts +68 -0
- package/dist/encoding/integerEncodingUtils.js +655 -0
- package/dist/encoding/integerEncodingUtils.js.map +1 -0
- package/dist/encoding/integerStreamEncoder.d.ts +27 -0
- package/dist/encoding/integerStreamEncoder.js +139 -0
- package/dist/encoding/integerStreamEncoder.js.map +1 -0
- package/dist/encoding/packNullableUtils.d.ts +4 -0
- package/dist/encoding/packNullableUtils.js +55 -0
- package/dist/encoding/packNullableUtils.js.map +1 -0
- package/dist/encoding/propertyEncoder.d.ts +78 -0
- package/dist/encoding/propertyEncoder.js +335 -0
- package/dist/encoding/propertyEncoder.js.map +1 -0
- package/dist/encoding/stringEncoder.d.ts +12 -0
- package/dist/encoding/stringEncoder.js +182 -0
- package/dist/encoding/stringEncoder.js.map +1 -0
- package/dist/encoding/zOrderCurveEncoder.d.ts +1 -0
- package/dist/encoding/zOrderCurveEncoder.js +10 -0
- package/dist/encoding/zOrderCurveEncoder.js.map +1 -0
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.d.ts +5 -1
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.js +29 -41
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.js.map +1 -1
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.spec.d.ts +1 -0
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.spec.js +142 -0
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.spec.js.map +1 -0
- package/dist/mltDecoder.js +2 -3
- package/dist/mltDecoder.js.map +1 -1
- package/dist/vector/dictionary/stringDictionaryVector.d.ts +1 -1
- package/dist/vector/dictionary/stringDictionaryVector.js.map +1 -1
- package/dist/vector/flat/stringFlatVector.d.ts +1 -1
- package/dist/vector/flat/stringFlatVector.js.map +1 -1
- package/dist/vector/fsst-dictionary/stringFsstDictionaryVector.d.ts +1 -1
- package/dist/vector/fsst-dictionary/stringFsstDictionaryVector.js.map +1 -1
- package/dist/vector/fsst-dictionary/stringFsstDictionaryVector.spec.js +2 -2
- package/dist/vector/fsst-dictionary/stringFsstDictionaryVector.spec.js.map +1 -1
- package/dist/vector/geometry/constGpuVector.d.ts +2 -2
- package/dist/vector/geometry/constGpuVector.js.map +1 -1
- package/dist/vector/geometry/flatGpuVector.d.ts +2 -2
- package/dist/vector/geometry/flatGpuVector.js.map +1 -1
- package/dist/vector/geometry/gpuVector.d.ts +2 -2
- package/dist/vector/geometry/gpuVector.js.map +1 -1
- package/dist/vector/geometry/topologyVector.d.ts +4 -4
- package/dist/vector/geometry/topologyVector.js +0 -1
- package/dist/vector/geometry/topologyVector.js.map +1 -1
- package/dist/vector/geometry/zOrderCurve.spec.js +17 -11
- package/dist/vector/geometry/zOrderCurve.spec.js.map +1 -1
- package/dist/vector/variableSizeVector.d.ts +2 -2
- package/dist/vector/variableSizeVector.js +0 -1
- package/dist/vector/variableSizeVector.js.map +1 -1
- package/package.json +6 -8
- package/dist/decoding/geometryDecoder.spec.js +0 -5
- package/dist/decoding/geometryDecoder.spec.js.map +0 -1
- /package/dist/decoding/{geometryDecoder.spec.d.ts → unpackNullableUtils.spec.d.ts} +0 -0
|
@@ -1,124 +1,140 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { decodeFloatsLE, decodeDoublesLE, decodeBooleanRle, decodeString, decodeByteRle
|
|
2
|
+
import { decodeFloatsLE, decodeDoublesLE, decodeBooleanRle, decodeString, decodeByteRle } from "./decodingUtils";
|
|
3
3
|
import IntWrapper from "./intWrapper";
|
|
4
4
|
import BitVector from "../vector/flat/bitVector";
|
|
5
|
+
import { encodeFloatsLE, encodeDoubleLE, encodeBooleanRle, encodeByteRle, encodeStrings, } from "../encoding/encodingUtils";
|
|
5
6
|
describe("decodingUtils", () => {
|
|
6
7
|
describe("decodeFloatsLE", () => {
|
|
7
8
|
it("should decode float values from little-endian bytes", () => {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
view[0] = 1.5;
|
|
11
|
-
view[1] = 2.5;
|
|
12
|
-
const data = new Uint8Array(buffer);
|
|
9
|
+
const data = new Float32Array([1.5, 2.5]);
|
|
10
|
+
const encoded = encodeFloatsLE(data);
|
|
13
11
|
const offset = new IntWrapper(0);
|
|
14
|
-
const result = decodeFloatsLE(
|
|
15
|
-
expect(result
|
|
16
|
-
expect(result[1]).toBeCloseTo(2.5);
|
|
12
|
+
const result = decodeFloatsLE(encoded, offset, 2);
|
|
13
|
+
expect(result).toEqual(data);
|
|
17
14
|
expect(offset.get()).toBe(8);
|
|
18
15
|
});
|
|
19
16
|
});
|
|
20
17
|
describe("decodeDoublesLE", () => {
|
|
21
18
|
it("should decode double values from little-endian bytes", () => {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
view[0] = 3.14159;
|
|
25
|
-
view[1] = 2.71828;
|
|
26
|
-
const data = new Uint8Array(buffer);
|
|
19
|
+
const data = new Float32Array([3.14159, 2.71828]);
|
|
20
|
+
const encoded = encodeDoubleLE(data);
|
|
27
21
|
const offset = new IntWrapper(0);
|
|
28
|
-
const result = decodeDoublesLE(
|
|
22
|
+
const result = decodeDoublesLE(encoded, offset, 2);
|
|
29
23
|
expect(result[0]).toBeCloseTo(3.14159);
|
|
30
24
|
expect(result[1]).toBeCloseTo(2.71828);
|
|
31
25
|
expect(offset.get()).toBe(16);
|
|
32
26
|
});
|
|
33
27
|
});
|
|
34
|
-
describe("
|
|
28
|
+
describe("decodeFloatsLE with nullability", () => {
|
|
35
29
|
it("should decode nullable float values with nullability buffer", () => {
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
view[0] = 1.5;
|
|
39
|
-
view[1] = 2.5;
|
|
40
|
-
const data = new Uint8Array(buffer);
|
|
30
|
+
const data = new Float32Array([1.5, 2.5]);
|
|
31
|
+
const encoded = encodeFloatsLE(data);
|
|
41
32
|
const offset = new IntWrapper(0);
|
|
42
|
-
const bitVectorData = new Uint8Array([0b00000101]);
|
|
33
|
+
const bitVectorData = new Uint8Array([0b00000101]);
|
|
43
34
|
const nullabilityBuffer = new BitVector(bitVectorData, 3);
|
|
44
|
-
const result =
|
|
35
|
+
const result = decodeFloatsLE(encoded, offset, 2, nullabilityBuffer);
|
|
45
36
|
expect(result.length).toBe(3);
|
|
46
|
-
expect(result[0]).toBeCloseTo(1.5);
|
|
47
|
-
expect(result[1]).toBe(0);
|
|
48
|
-
expect(result[2]).toBeCloseTo(2.5);
|
|
37
|
+
expect(result[0]).toBeCloseTo(1.5);
|
|
38
|
+
expect(result[1]).toBe(0);
|
|
39
|
+
expect(result[2]).toBeCloseTo(2.5);
|
|
49
40
|
});
|
|
50
41
|
});
|
|
51
|
-
describe("
|
|
42
|
+
describe("decodeDoublesLE with nullability", () => {
|
|
52
43
|
it("should decode nullable double values with nullability buffer", () => {
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
view[0] = 3.14159;
|
|
56
|
-
view[1] = 2.71828;
|
|
57
|
-
const data = new Uint8Array(buffer);
|
|
44
|
+
const data = new Float32Array([3.14159, 2.71828]);
|
|
45
|
+
const encoded = encodeDoubleLE(data);
|
|
58
46
|
const offset = new IntWrapper(0);
|
|
59
|
-
const bitVectorData = new Uint8Array([0b00000011]);
|
|
47
|
+
const bitVectorData = new Uint8Array([0b00000011]);
|
|
60
48
|
const nullabilityBuffer = new BitVector(bitVectorData, 2);
|
|
61
|
-
const result =
|
|
49
|
+
const result = decodeDoublesLE(encoded, offset, 2, nullabilityBuffer);
|
|
62
50
|
expect(result.length).toBe(2);
|
|
63
|
-
expect(result[0]).toBeCloseTo(3.14159);
|
|
64
|
-
expect(result[1]).toBeCloseTo(2.71828);
|
|
51
|
+
expect(result[0]).toBeCloseTo(3.14159);
|
|
52
|
+
expect(result[1]).toBeCloseTo(2.71828);
|
|
65
53
|
});
|
|
66
54
|
});
|
|
67
55
|
describe("decodeBooleanRle", () => {
|
|
68
56
|
it("should decode boolean RLE", () => {
|
|
69
|
-
|
|
57
|
+
// Create 8 true boolean values
|
|
58
|
+
const data = [true, true, true, true, true, true, true, true];
|
|
59
|
+
const encoded = encodeBooleanRle(data);
|
|
70
60
|
const offset = new IntWrapper(0);
|
|
71
|
-
const result = decodeBooleanRle(
|
|
61
|
+
const result = decodeBooleanRle(encoded, 8, encoded.length, offset);
|
|
62
|
+
// All 8 bits should be set in the first byte
|
|
72
63
|
expect(result[0]).toBe(0xff);
|
|
73
64
|
});
|
|
74
65
|
});
|
|
75
66
|
describe("decodeByteRle", () => {
|
|
76
67
|
it("should decode byte RLE with runs", () => {
|
|
77
|
-
//
|
|
78
|
-
const data = new Uint8Array([
|
|
68
|
+
// Encode 5 identical bytes
|
|
69
|
+
const data = new Uint8Array([42, 42, 42, 42, 42]);
|
|
70
|
+
const encoded = encodeByteRle(data);
|
|
71
|
+
const offset = new IntWrapper(0);
|
|
72
|
+
const result = decodeByteRle(encoded, 5, encoded.length, offset);
|
|
73
|
+
expect(result).toEqual(data);
|
|
74
|
+
});
|
|
75
|
+
it("should decode byte RLE with literals", () => {
|
|
76
|
+
// Encode 3 different bytes (will be encoded as literals)
|
|
77
|
+
const data = new Uint8Array([1, 2, 3]);
|
|
78
|
+
const encoded = encodeByteRle(data);
|
|
79
79
|
const offset = new IntWrapper(0);
|
|
80
|
-
const result = decodeByteRle(
|
|
81
|
-
expect(result
|
|
80
|
+
const result = decodeByteRle(encoded, 3, encoded.length, offset);
|
|
81
|
+
expect(result).toEqual(data);
|
|
82
|
+
expect(offset.get()).toBe(encoded.length);
|
|
83
|
+
});
|
|
84
|
+
it("should handle truncated stream when byteLength runs out before numBytes", () => {
|
|
85
|
+
// Request 10 bytes but byteLength only allows 2 bytes (header + value)
|
|
86
|
+
// header=0 means numRuns=3, but stream ends after value byte
|
|
87
|
+
const data = new Uint8Array([0, 42]);
|
|
88
|
+
const offset = new IntWrapper(0);
|
|
89
|
+
const result = decodeByteRle(data, 10, 2, offset);
|
|
90
|
+
// Should only fill 3 bytes (what the run specified) then stop at stream boundary
|
|
91
|
+
expect(result.length).toBe(10);
|
|
82
92
|
expect(result[0]).toBe(42);
|
|
83
93
|
expect(result[1]).toBe(42);
|
|
84
94
|
expect(result[2]).toBe(42);
|
|
85
|
-
|
|
86
|
-
expect(result[
|
|
95
|
+
// Remaining bytes should be 0
|
|
96
|
+
expect(result[3]).toBe(0);
|
|
97
|
+
expect(result[9]).toBe(0);
|
|
98
|
+
expect(offset.get()).toBe(2); // Should stop at byteLength boundary
|
|
87
99
|
});
|
|
88
|
-
it("should decode
|
|
89
|
-
|
|
90
|
-
const
|
|
100
|
+
it("should decode mixed literals and runs", () => {
|
|
101
|
+
const data = new Uint8Array([1, 2, 5, 5, 5, 5, 5, 7, 8]);
|
|
102
|
+
const encoded = encodeByteRle(data);
|
|
91
103
|
const offset = new IntWrapper(0);
|
|
92
|
-
const result = decodeByteRle(
|
|
93
|
-
expect(result
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
const result = decodeByteRle(encoded, 9, encoded.length, offset);
|
|
105
|
+
expect(result).toEqual(data);
|
|
106
|
+
});
|
|
107
|
+
it("should handle 128 literal max", () => {
|
|
108
|
+
const data = new Uint8Array(130);
|
|
109
|
+
for (let i = 0; i < 130; i++) {
|
|
110
|
+
data[i] = i % 256;
|
|
111
|
+
}
|
|
112
|
+
const encoded = encodeByteRle(data);
|
|
113
|
+
const offset = new IntWrapper(0);
|
|
114
|
+
const result = decodeByteRle(encoded, 130, encoded.length, offset);
|
|
115
|
+
expect(result).toEqual(data);
|
|
97
116
|
});
|
|
98
117
|
});
|
|
99
118
|
describe("decodeString", () => {
|
|
100
119
|
it("should decode short string", () => {
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
const result = decodeString(
|
|
104
|
-
expect(result).toBe(
|
|
120
|
+
const data = "Hello";
|
|
121
|
+
const encoded = encodeStrings([data]);
|
|
122
|
+
const result = decodeString(encoded, 0, encoded.length);
|
|
123
|
+
expect(result).toBe(data);
|
|
105
124
|
});
|
|
106
125
|
it("should decode long string", () => {
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
const result = decodeString(
|
|
110
|
-
expect(result).toBe(
|
|
126
|
+
const data = "This is a longer string for testing TextDecoder path";
|
|
127
|
+
const encoded = encodeStrings([data]);
|
|
128
|
+
const result = decodeString(encoded, 0, encoded.length);
|
|
129
|
+
expect(result).toBe(data);
|
|
111
130
|
});
|
|
112
131
|
it("should handle string with offset", () => {
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// decodeString takes (buffer, start, end) where end is the position after the last byte
|
|
120
|
-
const result = decodeString(combined, prefix.length, prefix.length + textBytes.length);
|
|
121
|
-
expect(result).toBe(text);
|
|
132
|
+
const prefix = "Hello";
|
|
133
|
+
const expectedText = "World";
|
|
134
|
+
const encoded = encodeStrings([prefix, expectedText]);
|
|
135
|
+
const prefixLength = new TextEncoder().encode(prefix).length;
|
|
136
|
+
const result = decodeString(encoded, prefixLength, encoded.length);
|
|
137
|
+
expect(result).toBe(expectedText);
|
|
122
138
|
});
|
|
123
139
|
});
|
|
124
140
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decodingUtils.spec.js","sourceRoot":"","sources":["../../src/decoding/decodingUtils.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,M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CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport {\n decodeFloatsLE,\n decodeDoublesLE,\n decodeBooleanRle,\n decodeString,\n decodeByteRle,\n decodeNullableFloatsLE,\n decodeNullableDoublesLE,\n} from \"./decodingUtils\";\nimport IntWrapper from \"./intWrapper\";\nimport BitVector from \"../vector/flat/bitVector\";\n\ndescribe(\"decodingUtils\", () => {\n describe(\"decodeFloatsLE\", () => {\n it(\"should decode float values from little-endian bytes\", () => {\n const buffer = new ArrayBuffer(8);\n const view = new Float32Array(buffer);\n view[0] = 1.5;\n view[1] = 2.5;\n\n const data = new Uint8Array(buffer);\n const offset = new IntWrapper(0);\n const result = decodeFloatsLE(data, offset, 2);\n\n expect(result[0]).toBeCloseTo(1.5);\n expect(result[1]).toBeCloseTo(2.5);\n expect(offset.get()).toBe(8);\n });\n });\n\n describe(\"decodeDoublesLE\", () => {\n it(\"should decode double values from little-endian bytes\", () => {\n const buffer = new ArrayBuffer(16);\n const view = new Float64Array(buffer);\n view[0] = 3.14159;\n view[1] = 2.71828;\n\n const data = new Uint8Array(buffer);\n const offset = new IntWrapper(0);\n const result = decodeDoublesLE(data, offset, 2);\n\n expect(result[0]).toBeCloseTo(3.14159);\n expect(result[1]).toBeCloseTo(2.71828);\n expect(offset.get()).toBe(16);\n });\n });\n\n describe(\"decodeNullableFloatsLE\", () => {\n it(\"should decode nullable float values with nullability buffer\", () => {\n const buffer = new ArrayBuffer(8);\n const view = new Float32Array(buffer);\n view[0] = 1.5;\n view[1] = 2.5;\n\n const data = new Uint8Array(buffer);\n const offset = new IntWrapper(0);\n const bitVectorData = new Uint8Array([0b00000101]); // bits 0 and 2 are set\n const nullabilityBuffer = new BitVector(bitVectorData, 3);\n\n const result = decodeNullableFloatsLE(data, offset, nullabilityBuffer, 2);\n\n expect(result.length).toBe(3);\n expect(result[0]).toBeCloseTo(1.5); // bit 0 is set\n expect(result[1]).toBe(0); // bit 1 is not set (null)\n expect(result[2]).toBeCloseTo(2.5); // bit 2 is set\n });\n });\n\n describe(\"decodeNullableDoublesLE\", () => {\n it(\"should decode nullable double values with nullability buffer\", () => {\n const buffer = new ArrayBuffer(16);\n const view = new Float64Array(buffer);\n view[0] = 3.14159;\n view[1] = 2.71828;\n\n const data = new Uint8Array(buffer);\n const offset = new IntWrapper(0);\n const bitVectorData = new Uint8Array([0b00000011]); // bits 0 and 1 are set\n const nullabilityBuffer = new BitVector(bitVectorData, 2);\n\n const result = decodeNullableDoublesLE(data, offset, nullabilityBuffer, 2);\n\n expect(result.length).toBe(2);\n expect(result[0]).toBeCloseTo(3.14159); // bit 0 is set\n expect(result[1]).toBeCloseTo(2.71828); // bit 1 is set\n });\n });\n\n describe(\"decodeBooleanRle\", () => {\n it(\"should decode boolean RLE\", () => {\n const buffer = new Uint8Array([254, 0xff]);\n const offset = new IntWrapper(0);\n const result = decodeBooleanRle(buffer, 8, offset);\n\n expect(result[0]).toBe(0xff);\n });\n });\n\n describe(\"decodeByteRle\", () => {\n it(\"should decode byte RLE with runs\", () => {\n // header=2 means numRuns=2+3=5, followed by value byte\n const data = new Uint8Array([2, 42]);\n const offset = new IntWrapper(0);\n const result = decodeByteRle(data, 5, offset);\n\n expect(result.length).toBe(5);\n expect(result[0]).toBe(42);\n expect(result[1]).toBe(42);\n expect(result[2]).toBe(42);\n expect(result[3]).toBe(42);\n expect(result[4]).toBe(42);\n });\n\n it(\"should decode byte RLE with literals\", () => {\n // header=253 means numLiterals=256-253=3, followed by 3 literal bytes\n const data = new Uint8Array([253, 1, 2, 3]);\n const offset = new IntWrapper(0);\n const result = decodeByteRle(data, 3, offset);\n\n expect(result.length).toBe(3);\n expect(result[0]).toBe(1);\n expect(result[1]).toBe(2);\n expect(result[2]).toBe(3);\n });\n });\n\n describe(\"decodeString\", () => {\n it(\"should decode short string\", () => {\n const text = \"Hello\";\n const buffer = new TextEncoder().encode(text);\n const result = decodeString(buffer, 0, buffer.length);\n\n expect(result).toBe(text);\n });\n\n it(\"should decode long string\", () => {\n const text = \"This is a longer string for testing TextDecoder path\";\n const buffer = new TextEncoder().encode(text);\n const result = decodeString(buffer, 0, buffer.length);\n\n expect(result).toBe(text);\n });\n\n it(\"should handle string with offset\", () => {\n const text = \"World\";\n const prefix = new TextEncoder().encode(\"Hello\");\n const textBytes = new TextEncoder().encode(text);\n const combined = new Uint8Array(prefix.length + textBytes.length);\n combined.set(prefix, 0);\n combined.set(textBytes, prefix.length);\n\n // decodeString takes (buffer, start, end) where end is the position after the last byte\n const result = decodeString(combined, prefix.length, prefix.length + textBytes.length);\n\n expect(result).toBe(text);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"decodingUtils.spec.js","sourceRoot":"","sources":["../../src/decoding/decodingUtils.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAA8B,MAAM,iBAAiB,CAAC;AAC7I,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,SAAS,MAAM,0BAA0B,CAAC;AACjD,OAAO,EACH,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,GAChB,MAAM,2BAA2B,CAAC;AAEnC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC3B,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC5B,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;YAC3D,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;YAC1C,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;YACrC,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,CAAC,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AC;YACtD,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;YAE7D,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YAEnE,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport { decodeFloatsLE, decodeDoublesLE, decodeBooleanRle, decodeString, decodeByteRle, getVectorTypeBooleanStream } from \"./decodingUtils\";\nimport IntWrapper from \"./intWrapper\";\nimport BitVector from \"../vector/flat/bitVector\";\nimport {\n encodeFloatsLE,\n encodeDoubleLE,\n encodeBooleanRle,\n encodeByteRle,\n encodeStrings,\n} from \"../encoding/encodingUtils\";\n\ndescribe(\"decodingUtils\", () => {\n describe(\"decodeFloatsLE\", () => {\n it(\"should decode float values from little-endian bytes\", () => {\n const data = new Float32Array([1.5, 2.5]);\n const encoded = encodeFloatsLE(data);\n const offset = new IntWrapper(0);\n const result = decodeFloatsLE(encoded, offset, 2);\n\n expect(result).toEqual(data);\n expect(offset.get()).toBe(8);\n });\n });\n\n describe(\"decodeDoublesLE\", () => {\n it(\"should decode double values from little-endian bytes\", () => {\n const data = new Float32Array([3.14159, 2.71828]);\n const encoded = encodeDoubleLE(data);\n const offset = new IntWrapper(0);\n const result = decodeDoublesLE(encoded, offset, 2);\n\n expect(result[0]).toBeCloseTo(3.14159);\n expect(result[1]).toBeCloseTo(2.71828);\n expect(offset.get()).toBe(16);\n });\n });\n\n describe(\"decodeFloatsLE with nullability\", () => {\n it(\"should decode nullable float values with nullability buffer\", () => {\n const data = new Float32Array([1.5, 2.5]);\n const encoded = encodeFloatsLE(data);\n const offset = new IntWrapper(0);\n const bitVectorData = new Uint8Array([0b00000101]);\n const nullabilityBuffer = new BitVector(bitVectorData, 3);\n\n const result = decodeFloatsLE(encoded, offset, 2, nullabilityBuffer);\n\n expect(result.length).toBe(3);\n expect(result[0]).toBeCloseTo(1.5);\n expect(result[1]).toBe(0);\n expect(result[2]).toBeCloseTo(2.5);\n });\n });\n\n describe(\"decodeDoublesLE with nullability\", () => {\n it(\"should decode nullable double values with nullability buffer\", () => {\n const data = new Float32Array([3.14159, 2.71828]);\n const encoded = encodeDoubleLE(data);\n const offset = new IntWrapper(0);\n const bitVectorData = new Uint8Array([0b00000011]);\n const nullabilityBuffer = new BitVector(bitVectorData, 2);\n\n const result = decodeDoublesLE(encoded, offset, 2, nullabilityBuffer);\n\n expect(result.length).toBe(2);\n expect(result[0]).toBeCloseTo(3.14159);\n expect(result[1]).toBeCloseTo(2.71828);\n });\n });\n\n describe(\"decodeBooleanRle\", () => {\n it(\"should decode boolean RLE\", () => {\n // Create 8 true boolean values\n const data = [true, true, true, true, true, true, true, true];\n const encoded = encodeBooleanRle(data);\n const offset = new IntWrapper(0);\n const result = decodeBooleanRle(encoded, 8, encoded.length, offset);\n\n // All 8 bits should be set in the first byte\n expect(result[0]).toBe(0xff);\n });\n });\n\n describe(\"decodeByteRle\", () => {\n it(\"should decode byte RLE with runs\", () => {\n // Encode 5 identical bytes\n const data = new Uint8Array([42, 42, 42, 42, 42]);\n const encoded = encodeByteRle(data);\n const offset = new IntWrapper(0);\n const result = decodeByteRle(encoded, 5, encoded.length, offset);\n\n expect(result).toEqual(data);\n });\n\n it(\"should decode byte RLE with literals\", () => {\n // Encode 3 different bytes (will be encoded as literals)\n const data = new Uint8Array([1, 2, 3]);\n const encoded = encodeByteRle(data);\n const offset = new IntWrapper(0);\n const result = decodeByteRle(encoded, 3, encoded.length, offset);\n\n expect(result).toEqual(data);\n expect(offset.get()).toBe(encoded.length);\n });\n\n it(\"should handle truncated stream when byteLength runs out before numBytes\", () => {\n // Request 10 bytes but byteLength only allows 2 bytes (header + value)\n // header=0 means numRuns=3, but stream ends after value byte\n const data = new Uint8Array([0, 42]);\n const offset = new IntWrapper(0);\n const result = decodeByteRle(data, 10, 2, offset);\n\n // Should only fill 3 bytes (what the run specified) then stop at stream boundary\n expect(result.length).toBe(10);\n expect(result[0]).toBe(42);\n expect(result[1]).toBe(42);\n expect(result[2]).toBe(42);\n // Remaining bytes should be 0\n expect(result[3]).toBe(0);\n expect(result[9]).toBe(0);\n expect(offset.get()).toBe(2); // Should stop at byteLength boundary\n });\n\n it(\"should decode mixed literals and runs\", () => {\n const data = new Uint8Array([1, 2, 5, 5, 5, 5, 5, 7, 8]);\n const encoded = encodeByteRle(data);\n const offset = new IntWrapper(0);\n const result = decodeByteRle(encoded, 9, encoded.length, offset);\n\n expect(result).toEqual(data);\n });\n\n it(\"should handle 128 literal max\", () => {\n const data = new Uint8Array(130);\n for (let i = 0; i < 130; i++) {\n data[i] = i % 256;\n }\n const encoded = encodeByteRle(data);\n const offset = new IntWrapper(0);\n const result = decodeByteRle(encoded, 130, encoded.length, offset);\n\n expect(result).toEqual(data);\n });\n });\n\n describe(\"decodeString\", () => {\n it(\"should decode short string\", () => {\n const data = \"Hello\";\n const encoded = encodeStrings([data]);\n const result = decodeString(encoded, 0, encoded.length);\n\n expect(result).toBe(data);\n });\n\n it(\"should decode long string\", () => {\n const data = \"This is a longer string for testing TextDecoder path\";\n const encoded = encodeStrings([data]);\n const result = decodeString(encoded, 0, encoded.length);\n\n expect(result).toBe(data);\n });\n\n it(\"should handle string with offset\", () => {\n const prefix = \"Hello\";\n const expectedText = \"World\";\n const encoded = encodeStrings([prefix, expectedText]);\n const prefixLength = new TextEncoder().encode(prefix).length;\n\n const result = decodeString(encoded, prefixLength, encoded.length);\n\n expect(result).toBe(expectedText);\n });\n });\n});\n"]}
|
|
@@ -1,40 +1,57 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import { decodeFsst } from "./fsstDecoder";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
3
|
+
import { encodeFsst, createSymbolTable } from "../encoding/fsstEncoder";
|
|
4
|
+
const textEncoder = new TextEncoder();
|
|
5
|
+
describe("decodeFsst", () => {
|
|
6
|
+
describe("basic functionality", () => {
|
|
7
|
+
it("should decode FSST compressed string data", () => {
|
|
8
|
+
const inputString = "HelloWorld !";
|
|
9
|
+
const originalBytes = textEncoder.encode(inputString);
|
|
10
|
+
const { symbols, symbolLengths } = createSymbolTable(["Hello", "World", "!"]);
|
|
11
|
+
const encoded = encodeFsst(symbols, symbolLengths, originalBytes);
|
|
12
|
+
const decoded = decodeFsst(symbols, symbolLengths, encoded);
|
|
13
|
+
expect(decoded).toEqual(originalBytes);
|
|
14
|
+
expect(new TextDecoder().decode(decoded)).toBe(inputString);
|
|
15
|
+
});
|
|
16
|
+
it("should handle empty string", () => {
|
|
17
|
+
const inputString = "";
|
|
18
|
+
const originalBytes = textEncoder.encode(inputString);
|
|
19
|
+
const { symbols, symbolLengths } = createSymbolTable(["A"]);
|
|
20
|
+
const encoded = encodeFsst(symbols, symbolLengths, originalBytes);
|
|
21
|
+
const decoded = decodeFsst(symbols, symbolLengths, encoded);
|
|
22
|
+
expect(decoded).toEqual(originalBytes);
|
|
23
|
+
expect(decoded.length).toBe(0);
|
|
24
|
+
});
|
|
25
|
+
it("should handle string with no matching symbols", () => {
|
|
26
|
+
const inputString = "12345";
|
|
27
|
+
const originalBytes = textEncoder.encode(inputString);
|
|
28
|
+
const { symbols, symbolLengths } = createSymbolTable(["abc", "def", "xyz"]);
|
|
29
|
+
const encoded = encodeFsst(symbols, symbolLengths, originalBytes);
|
|
30
|
+
const decoded = decodeFsst(symbols, symbolLengths, encoded);
|
|
31
|
+
expect(decoded).toEqual(originalBytes);
|
|
32
|
+
expect(new TextDecoder().decode(decoded)).toBe(inputString);
|
|
33
|
+
});
|
|
34
|
+
it("should handle string with all matching symbols", () => {
|
|
35
|
+
const inputString = "AAAA";
|
|
36
|
+
const originalBytes = textEncoder.encode(inputString);
|
|
37
|
+
const { symbols, symbolLengths } = createSymbolTable(["A"]);
|
|
38
|
+
const encoded = encodeFsst(symbols, symbolLengths, originalBytes);
|
|
39
|
+
const decoded = decodeFsst(symbols, symbolLengths, encoded);
|
|
40
|
+
expect(decoded).toEqual(originalBytes);
|
|
41
|
+
expect(new TextDecoder().decode(decoded)).toBe(inputString);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe("compression verification", () => {
|
|
45
|
+
it("should handle repeated strings efficiently", () => {
|
|
46
|
+
const inputString = "HelloWorldHelloWorld";
|
|
47
|
+
const originalBytes = textEncoder.encode(inputString);
|
|
48
|
+
const { symbols, symbolLengths } = createSymbolTable(["Hello", "World"]);
|
|
49
|
+
const encoded = encodeFsst(symbols, symbolLengths, originalBytes);
|
|
50
|
+
const decoded = decodeFsst(symbols, symbolLengths, encoded);
|
|
51
|
+
expect(decoded).toEqual(originalBytes);
|
|
52
|
+
expect(new TextDecoder().decode(decoded)).toBe(inputString);
|
|
53
|
+
expect(encoded.length).toBeLessThan(originalBytes.length);
|
|
54
|
+
});
|
|
38
55
|
});
|
|
39
56
|
});
|
|
40
57
|
//# sourceMappingURL=fsstDecoder.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fsstDecoder.spec.js","sourceRoot":"","sources":["../../src/decoding/fsstDecoder.spec.ts"],"names":[],"mappings":"AAA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,CAAC","sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport { decodeFsst } from \"./fsstDecoder\";\nimport { encodeFsst, createSymbolTable } from \"../encoding/fsstEncoder\";\n\nconst textEncoder = new TextEncoder();\n\ndescribe(\"decodeFsst\", () => {\n describe(\"basic functionality\", () => {\n it(\"should decode FSST compressed string data\", () => {\n const inputString = \"HelloWorld !\";\n const originalBytes = textEncoder.encode(inputString);\n\n const { symbols, symbolLengths } = createSymbolTable([\"Hello\", \"World\", \"!\"]);\n const encoded = encodeFsst(symbols, symbolLengths, originalBytes);\n const decoded = decodeFsst(symbols, symbolLengths, encoded);\n\n expect(decoded).toEqual(originalBytes);\n expect(new TextDecoder().decode(decoded)).toBe(inputString);\n });\n\n it(\"should handle empty string\", () => {\n const inputString = \"\";\n const originalBytes = textEncoder.encode(inputString);\n\n const { symbols, symbolLengths } = createSymbolTable([\"A\"]);\n const encoded = encodeFsst(symbols, symbolLengths, originalBytes);\n const decoded = decodeFsst(symbols, symbolLengths, encoded);\n\n expect(decoded).toEqual(originalBytes);\n expect(decoded.length).toBe(0);\n });\n\n it(\"should handle string with no matching symbols\", () => {\n const inputString = \"12345\";\n const originalBytes = textEncoder.encode(inputString);\n\n const { symbols, symbolLengths } = createSymbolTable([\"abc\", \"def\", \"xyz\"]);\n const encoded = encodeFsst(symbols, symbolLengths, originalBytes);\n const decoded = decodeFsst(symbols, symbolLengths, encoded);\n\n expect(decoded).toEqual(originalBytes);\n expect(new TextDecoder().decode(decoded)).toBe(inputString);\n });\n\n it(\"should handle string with all matching symbols\", () => {\n const inputString = \"AAAA\";\n const originalBytes = textEncoder.encode(inputString);\n\n const { symbols, symbolLengths } = createSymbolTable([\"A\"]);\n const encoded = encodeFsst(symbols, symbolLengths, originalBytes);\n const decoded = decodeFsst(symbols, symbolLengths, encoded);\n\n expect(decoded).toEqual(originalBytes);\n expect(new TextDecoder().decode(decoded)).toBe(inputString);\n });\n });\n\n describe(\"compression verification\", () => {\n it(\"should handle repeated strings efficiently\", () => {\n const inputString = \"HelloWorldHelloWorld\";\n const originalBytes = textEncoder.encode(inputString);\n\n const { symbols, symbolLengths } = createSymbolTable([\"Hello\", \"World\"]);\n const encoded = encodeFsst(symbols, symbolLengths, originalBytes);\n const decoded = decodeFsst(symbols, symbolLengths, encoded);\n\n expect(decoded).toEqual(originalBytes);\n expect(new TextDecoder().decode(decoded)).toBe(inputString);\n expect(encoded.length).toBeLessThan(originalBytes.length);\n });\n });\n});\n"]}
|
|
@@ -14,19 +14,20 @@ import { createFlatGpuVector } from "../vector/geometry/flatGpuVector";
|
|
|
14
14
|
export function decodeGeometryColumn(tile, numStreams, offset, numFeatures, scalingData) {
|
|
15
15
|
const geometryTypeMetadata = decodeStreamMetadata(tile, offset);
|
|
16
16
|
const geometryTypesVectorType = getVectorType(geometryTypeMetadata, numFeatures, tile, offset);
|
|
17
|
-
let geometryOffsets = null;
|
|
18
|
-
let partOffsets = null;
|
|
19
|
-
let ringOffsets = null;
|
|
20
17
|
let vertexOffsets = null;
|
|
21
18
|
let vertexBuffer = null;
|
|
22
19
|
let mortonSettings = null;
|
|
23
|
-
//TODO: use geometryOffsets for that? -> but then tessellated polygons can't be used with normal polygons
|
|
24
|
-
// in one FeatureTable?
|
|
25
|
-
let triangleOffsets = null;
|
|
26
20
|
let indexBuffer = null;
|
|
27
21
|
if (geometryTypesVectorType === VectorType.CONST) {
|
|
28
22
|
/* All geometries in the colum have the same geometry type */
|
|
29
23
|
const geometryType = decodeConstIntStream(tile, offset, geometryTypeMetadata, false);
|
|
24
|
+
// Variables for const geometry path (directly decoded as offsets)
|
|
25
|
+
let geometryOffsets = null;
|
|
26
|
+
let partOffsets = null;
|
|
27
|
+
let ringOffsets = null;
|
|
28
|
+
//TODO: use geometryOffsets for that? -> but then tessellated polygons can't be used with normal polygons
|
|
29
|
+
// in one FeatureTable?
|
|
30
|
+
let triangleOffsets = null;
|
|
30
31
|
for (let i = 0; i < numStreams - 1; i++) {
|
|
31
32
|
const geometryStreamMetadata = decodeStreamMetadata(tile, offset);
|
|
32
33
|
switch (geometryStreamMetadata.physicalStreamType) {
|
|
@@ -88,19 +89,26 @@ export function decodeGeometryColumn(tile, numStreams, offset, numFeatures, scal
|
|
|
88
89
|
}
|
|
89
90
|
/* Different geometry types are mixed in the geometry column */
|
|
90
91
|
const geometryTypeVector = decodeIntStream(tile, offset, geometryTypeMetadata, false);
|
|
92
|
+
// Variables for flat geometry path (decoded as lengths, then converted to offsets)
|
|
93
|
+
let geometryLengths = null;
|
|
94
|
+
let partLengths = null;
|
|
95
|
+
let ringLengths = null;
|
|
96
|
+
//TODO: use geometryOffsets for that? -> but then tessellated polygons can't be used with normal polygons
|
|
97
|
+
// in one FeatureTable?
|
|
98
|
+
let triangleOffsets = null;
|
|
91
99
|
for (let i = 0; i < numStreams - 1; i++) {
|
|
92
100
|
const geometryStreamMetadata = decodeStreamMetadata(tile, offset);
|
|
93
101
|
switch (geometryStreamMetadata.physicalStreamType) {
|
|
94
102
|
case PhysicalStreamType.LENGTH:
|
|
95
103
|
switch (geometryStreamMetadata.logicalStreamType.lengthType) {
|
|
96
104
|
case LengthType.GEOMETRIES:
|
|
97
|
-
|
|
105
|
+
geometryLengths = decodeIntStream(tile, offset, geometryStreamMetadata, false);
|
|
98
106
|
break;
|
|
99
107
|
case LengthType.PARTS:
|
|
100
|
-
|
|
108
|
+
partLengths = decodeIntStream(tile, offset, geometryStreamMetadata, false);
|
|
101
109
|
break;
|
|
102
110
|
case LengthType.RINGS:
|
|
103
|
-
|
|
111
|
+
ringLengths = decodeIntStream(tile, offset, geometryStreamMetadata, false);
|
|
104
112
|
break;
|
|
105
113
|
case LengthType.TRIANGLES:
|
|
106
114
|
triangleOffsets = decodeLengthStreamToOffsetBuffer(tile, offset, geometryStreamMetadata);
|
|
@@ -131,29 +139,32 @@ export function decodeGeometryColumn(tile, numStreams, offset, numFeatures, scal
|
|
|
131
139
|
break;
|
|
132
140
|
}
|
|
133
141
|
}
|
|
134
|
-
if (indexBuffer !== null && partOffsets === null) {
|
|
135
|
-
/* Case when the indices of a Polygon outline are not encoded in the data so no
|
|
136
|
-
* topology data are present in the tile */
|
|
137
|
-
return createFlatGpuVector(geometryTypeVector, triangleOffsets, indexBuffer, vertexBuffer);
|
|
138
|
-
}
|
|
139
142
|
// TODO: refactor the following instructions -> decode in one pass for performance reasons
|
|
140
143
|
/* Calculate the offsets from the length buffer for util access */
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
let geometryOffsets = null;
|
|
145
|
+
let partOffsets = null;
|
|
146
|
+
let ringOffsets = null;
|
|
147
|
+
if (geometryLengths !== null) {
|
|
148
|
+
geometryOffsets = decodeRootLengthStream(geometryTypeVector, geometryLengths, 2);
|
|
149
|
+
if (partLengths !== null && ringLengths !== null) {
|
|
150
|
+
partOffsets = decodeLevel1LengthStream(geometryTypeVector, geometryOffsets, partLengths, false);
|
|
151
|
+
ringOffsets = decodeLevel2LengthStream(geometryTypeVector, geometryOffsets, partOffsets, ringLengths);
|
|
146
152
|
}
|
|
147
|
-
else if (
|
|
148
|
-
partOffsets = decodeLevel1WithoutRingBufferLengthStream(geometryTypeVector, geometryOffsets,
|
|
153
|
+
else if (partLengths !== null) {
|
|
154
|
+
partOffsets = decodeLevel1WithoutRingBufferLengthStream(geometryTypeVector, geometryOffsets, partLengths);
|
|
149
155
|
}
|
|
150
156
|
}
|
|
151
|
-
else if (
|
|
152
|
-
partOffsets = decodeRootLengthStream(geometryTypeVector,
|
|
153
|
-
ringOffsets = decodeLevel1LengthStream(geometryTypeVector, partOffsets,
|
|
157
|
+
else if (partLengths !== null && ringLengths !== null) {
|
|
158
|
+
partOffsets = decodeRootLengthStream(geometryTypeVector, partLengths, 1);
|
|
159
|
+
ringOffsets = decodeLevel1LengthStream(geometryTypeVector, partOffsets, ringLengths, true);
|
|
154
160
|
}
|
|
155
|
-
else if (
|
|
156
|
-
partOffsets = decodeRootLengthStream(geometryTypeVector,
|
|
161
|
+
else if (partLengths !== null) {
|
|
162
|
+
partOffsets = decodeRootLengthStream(geometryTypeVector, partLengths, 0);
|
|
163
|
+
}
|
|
164
|
+
if (indexBuffer !== null && partOffsets === null) {
|
|
165
|
+
/* Case when the indices of a Polygon outline are not encoded in the data so no
|
|
166
|
+
* topology data are present in the tile */
|
|
167
|
+
return createFlatGpuVector(geometryTypeVector, triangleOffsets, indexBuffer, vertexBuffer);
|
|
157
168
|
}
|
|
158
169
|
if (indexBuffer !== null) {
|
|
159
170
|
/* Case when the indices of a Polygon outline are encoded in the tile */
|
|
@@ -168,7 +179,7 @@ export function decodeGeometryColumn(tile, numStreams, offset, numFeatures, scal
|
|
|
168
179
|
* branching and improve the performance
|
|
169
180
|
*/
|
|
170
181
|
function decodeRootLengthStream(geometryTypes, rootLengthStream, bufferId) {
|
|
171
|
-
const rootBufferOffsets = new
|
|
182
|
+
const rootBufferOffsets = new Uint32Array(geometryTypes.length + 1);
|
|
172
183
|
let previousOffset = 0;
|
|
173
184
|
rootBufferOffsets[0] = previousOffset;
|
|
174
185
|
let rootLengthCounter = 0;
|
|
@@ -184,7 +195,7 @@ function decodeRootLengthStream(geometryTypes, rootLengthStream, bufferId) {
|
|
|
184
195
|
return rootBufferOffsets;
|
|
185
196
|
}
|
|
186
197
|
function decodeLevel1LengthStream(geometryTypes, rootOffsetBuffer, level1LengthBuffer, isLineStringPresent) {
|
|
187
|
-
const level1BufferOffsets = new
|
|
198
|
+
const level1BufferOffsets = new Uint32Array(rootOffsetBuffer[rootOffsetBuffer.length - 1] + 1);
|
|
188
199
|
let previousOffset = 0;
|
|
189
200
|
level1BufferOffsets[0] = previousOffset;
|
|
190
201
|
let level1BufferCounter = 1;
|
|
@@ -216,7 +227,7 @@ function decodeLevel1LengthStream(geometryTypes, rootOffsetBuffer, level1LengthB
|
|
|
216
227
|
* Case where no ring buffer exists so no MultiPolygon or Polygon geometry is part of the buffer
|
|
217
228
|
*/
|
|
218
229
|
function decodeLevel1WithoutRingBufferLengthStream(geometryTypes, rootOffsetBuffer, level1LengthBuffer) {
|
|
219
|
-
const level1BufferOffsets = new
|
|
230
|
+
const level1BufferOffsets = new Uint32Array(rootOffsetBuffer[rootOffsetBuffer.length - 1] + 1);
|
|
220
231
|
let previousOffset = 0;
|
|
221
232
|
level1BufferOffsets[0] = previousOffset;
|
|
222
233
|
let level1OffsetBufferCounter = 1;
|
|
@@ -241,7 +252,7 @@ function decodeLevel1WithoutRingBufferLengthStream(geometryTypes, rootOffsetBuff
|
|
|
241
252
|
return level1BufferOffsets;
|
|
242
253
|
}
|
|
243
254
|
function decodeLevel2LengthStream(geometryTypes, rootOffsetBuffer, level1OffsetBuffer, level2LengthBuffer) {
|
|
244
|
-
const level2BufferOffsets = new
|
|
255
|
+
const level2BufferOffsets = new Uint32Array(level1OffsetBuffer[level1OffsetBuffer.length - 1] + 1);
|
|
245
256
|
let previousOffset = 0;
|
|
246
257
|
level2BufferOffsets[0] = previousOffset;
|
|
247
258
|
let level1OffsetBufferCounter = 1;
|