@osmix/core 0.1.10 → 0.3.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 (97) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/LICENSE +21 -0
  3. package/README.md +136 -72
  4. package/dist/contracts.d.ts +27 -0
  5. package/dist/contracts.d.ts.map +1 -0
  6. package/dist/contracts.js +1 -0
  7. package/dist/contracts.js.map +1 -0
  8. package/dist/entities.d.ts +22 -2
  9. package/dist/entities.d.ts.map +1 -1
  10. package/dist/entities.js +54 -10
  11. package/dist/entities.js.map +1 -1
  12. package/dist/ids.d.ts +20 -5
  13. package/dist/ids.d.ts.map +1 -1
  14. package/dist/ids.js +87 -29
  15. package/dist/ids.js.map +1 -1
  16. package/dist/index.d.ts +7 -4
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +6 -4
  19. package/dist/index.js.map +1 -1
  20. package/dist/indirect-kd-index.d.ts +28 -0
  21. package/dist/indirect-kd-index.d.ts.map +1 -0
  22. package/dist/indirect-kd-index.js +163 -0
  23. package/dist/indirect-kd-index.js.map +1 -0
  24. package/dist/limits.d.ts +30 -0
  25. package/dist/limits.d.ts.map +1 -0
  26. package/dist/limits.js +51 -0
  27. package/dist/limits.js.map +1 -0
  28. package/dist/mocks.d.ts.map +1 -1
  29. package/dist/mocks.js.map +1 -1
  30. package/dist/nodes.d.ts +36 -15
  31. package/dist/nodes.d.ts.map +1 -1
  32. package/dist/nodes.js +185 -62
  33. package/dist/nodes.js.map +1 -1
  34. package/dist/osm.d.ts +60 -4
  35. package/dist/osm.d.ts.map +1 -1
  36. package/dist/osm.js +32 -6
  37. package/dist/osm.js.map +1 -1
  38. package/dist/relations.d.ts +11 -4
  39. package/dist/relations.d.ts.map +1 -1
  40. package/dist/relations.js +73 -29
  41. package/dist/relations.js.map +1 -1
  42. package/dist/renumber.d.ts +23 -0
  43. package/dist/renumber.d.ts.map +1 -0
  44. package/dist/renumber.js +64 -0
  45. package/dist/renumber.js.map +1 -0
  46. package/dist/stringtable.d.ts +2 -1
  47. package/dist/stringtable.d.ts.map +1 -1
  48. package/dist/stringtable.js +9 -14
  49. package/dist/stringtable.js.map +1 -1
  50. package/dist/tags.d.ts +45 -12
  51. package/dist/tags.d.ts.map +1 -1
  52. package/dist/tags.js +153 -27
  53. package/dist/tags.js.map +1 -1
  54. package/dist/typed-arrays.d.ts +63 -48
  55. package/dist/typed-arrays.d.ts.map +1 -1
  56. package/dist/typed-arrays.js +184 -107
  57. package/dist/typed-arrays.js.map +1 -1
  58. package/dist/ways.d.ts +52 -3
  59. package/dist/ways.d.ts.map +1 -1
  60. package/dist/ways.js +223 -46
  61. package/dist/ways.js.map +1 -1
  62. package/package.json +45 -31
  63. package/src/contracts.ts +29 -0
  64. package/src/entities.ts +242 -194
  65. package/src/ids.ts +278 -235
  66. package/src/index.ts +22 -13
  67. package/src/indirect-kd-index.ts +212 -0
  68. package/src/limits.ts +73 -0
  69. package/src/mocks.ts +114 -113
  70. package/src/nodes.ts +538 -397
  71. package/src/osm.ts +282 -207
  72. package/src/relations.ts +580 -558
  73. package/src/renumber.ts +80 -0
  74. package/src/stringtable.ts +189 -184
  75. package/src/tags.ts +406 -272
  76. package/src/typed-arrays.ts +307 -205
  77. package/src/types/geoflatbush.d.ts +28 -33
  78. package/src/ways.ts +577 -406
  79. package/test/entity-index-errors.test.ts +41 -0
  80. package/test/ids.bench.ts +33 -0
  81. package/test/ids.test.ts +122 -0
  82. package/test/limits.test.ts +83 -0
  83. package/test/memory.test.ts +29 -30
  84. package/test/no-shared-array-buffer.test.ts +41 -0
  85. package/test/nodes-spatial-index.test.ts +261 -0
  86. package/test/osm-bbox.test.ts +30 -0
  87. package/test/relations.bench.ts +32 -0
  88. package/test/relations.test.ts +124 -0
  89. package/test/renumber.test.ts +54 -0
  90. package/test/spatial-index-rebuild.test.ts +33 -0
  91. package/test/storage-compaction.test.ts +269 -0
  92. package/test/tags-search.test.ts +89 -56
  93. package/test/typed-arrays.test.ts +252 -132
  94. package/tsconfig.build.json +6 -6
  95. package/tsconfig.json +7 -7
  96. package/src/types/geokdbush.d.ts +0 -37
  97. package/src/types/kdbush.d.ts +0 -47
@@ -1,134 +1,254 @@
1
- import { describe, expect, it } from "bun:test"
2
- import { BufferConstructor, ResizeableTypedArray } from "../src/typed-arrays"
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import {
4
+ BufferConstructor,
5
+ ResizeableTypedArray,
6
+ TypedBufferAllocationError,
7
+ } from "../src/typed-arrays";
8
+
9
+ const INITIAL_BYTES = 64 * 1024;
10
+
11
+ class FailingCreateArrayBuffer extends ArrayBuffer {
12
+ constructor() {
13
+ super(0);
14
+ throw new RangeError("create failed");
15
+ }
16
+ }
17
+
18
+ /** Allocates the first buffer, but can neither resize it nor allocate a larger one. */
19
+ class FailingGrowArrayBuffer extends ArrayBuffer {
20
+ constructor(byteLength: number, options?: { maxByteLength?: number }) {
21
+ if (byteLength > INITIAL_BYTES) throw new RangeError("grow failed");
22
+ super(byteLength, options);
23
+ }
24
+
25
+ override resize(): void {
26
+ throw new RangeError("resize failed");
27
+ }
28
+ }
29
+
30
+ class FailingCompactArrayBuffer extends ArrayBuffer {
31
+ override transferToFixedLength(): ArrayBuffer {
32
+ throw new RangeError("compact failed");
33
+ }
34
+ }
35
+
36
+ /** Refuses any `maxByteLength` reservation, like a runtime out of address space. */
37
+ class NoReserveArrayBuffer extends ArrayBuffer {
38
+ constructor(byteLength: number, options?: { maxByteLength?: number }) {
39
+ if (options?.maxByteLength !== undefined) throw new RangeError("no reservation");
40
+ super(byteLength);
41
+ }
42
+ }
3
43
 
4
44
  describe("typed array helpers", () => {
5
- it("selects the appropriate buffer constructor", () => {
6
- if (typeof SharedArrayBuffer !== "undefined") {
7
- expect(BufferConstructor).toBe(SharedArrayBuffer)
8
- } else {
9
- expect(BufferConstructor).toBe(ArrayBuffer)
10
- }
11
- })
12
-
13
- describe("ResizeableTypedArray", () => {
14
- it("push stores values and returns the index", () => {
15
- const arr = new ResizeableTypedArray(Float64Array)
16
-
17
- const first = arr.push(1.5)
18
- const second = arr.push(2.5)
19
-
20
- expect(first).toBe(0)
21
- expect(second).toBe(1)
22
- expect(arr.length).toBe(2)
23
- expect(arr.at(0)).toBe(1.5)
24
- expect(arr.at(1)).toBe(2.5)
25
- })
26
-
27
- it("should push many values", () => {
28
- const arr = new ResizeableTypedArray(Float64Array)
29
-
30
- arr.pushMany([1.5, 2.5])
31
-
32
- expect(arr.length).toBe(2)
33
- expect(arr.at(0)).toBe(1.5)
34
- expect(arr.at(1)).toBe(2.5)
35
- })
36
-
37
- it("at supports negative indices and guards bounds", () => {
38
- const arr = new ResizeableTypedArray(Int16Array)
39
-
40
- arr.pushMany([10, 20, 30])
41
-
42
- expect(arr.length).toBe(3)
43
- expect(Array.from(arr.slice(0, arr.length))).toEqual([10, 20, 30])
44
- expect(arr.at(-1)).toBe(30)
45
- expect(arr.at(-3)).toBe(10)
46
- expect(() => arr.at(-4)).toThrow(/Index out of bounds/)
47
- expect(() => arr.at(3)).toThrow(/Index out of bounds/)
48
- })
49
-
50
- it("pushMany appends arrays while preserving order", () => {
51
- const arr = new ResizeableTypedArray(Uint32Array)
52
-
53
- arr.pushMany([1, 2, 3])
54
- arr.pushMany(Uint32Array.from([4, 5]))
55
-
56
- expect(arr.length).toBe(5)
57
- expect(Array.from(arr.slice(0, arr.length))).toEqual([1, 2, 3, 4, 5])
58
- })
59
-
60
- it("slice returns a copy of the requested segment", () => {
61
- const arr = new ResizeableTypedArray(Uint8Array)
62
-
63
- arr.pushMany([1, 2, 3, 4])
64
-
65
- const segment = arr.slice(1, 3)
66
-
67
- expect(segment).toBeInstanceOf(Uint8Array)
68
- expect(Array.from(segment)).toEqual([2, 3])
69
-
70
- segment[0] = 99
71
- expect(arr.at(1)).toBe(2)
72
- })
73
-
74
- it("compact trims unused capacity", () => {
75
- const arr = new ResizeableTypedArray(Float64Array)
76
-
77
- arr.pushMany([5, 6, 7])
78
-
79
- const previousCapacity = arr.array.length
80
- const compacted = arr.compact()
81
- const expectedByteLength = arr.length * Float64Array.BYTES_PER_ELEMENT
82
-
83
- expect(compacted).toBe(arr.array)
84
- expect(compacted.length).toBe(arr.length)
85
- expect(compacted.length).toBeLessThan(previousCapacity)
86
- expect(arr.array.buffer.byteLength).toBe(expectedByteLength)
87
- })
88
-
89
- it("from reuses an existing buffer and grows when needed", () => {
90
- const backing = new ArrayBuffer(16)
91
- new Uint32Array(backing).set([1, 2, 3, 4])
92
-
93
- const arr = ResizeableTypedArray.from(Uint32Array, backing)
94
-
95
- arr.bufferSize = arr.buffer.byteLength
96
- arr.maxByteLength = Math.max(arr.maxByteLength, arr.bufferSize * 2)
97
- arr.items = arr.array.length
98
-
99
- expect(arr.length).toBe(4)
100
- expect(Array.from(arr.slice(0, arr.length))).toEqual([1, 2, 3, 4])
101
-
102
- arr.push(5)
103
-
104
- expect(arr.length).toBe(5)
105
- expect(arr.array.length).toBe(8)
106
- expect(Array.from(arr.slice(0, arr.length))).toEqual([1, 2, 3, 4, 5])
107
- })
108
-
109
- if (typeof SharedArrayBuffer !== "undefined") {
110
- it("grows shared buffers in place", () => {
111
- const backing = new SharedArrayBuffer(8, {
112
- maxByteLength: 32,
113
- })
114
- const seed = new Uint8Array(backing)
115
- seed.set([1, 2, 3, 4, 5, 6, 7, 8])
116
-
117
- const arr = ResizeableTypedArray.from(Uint8Array, backing)
118
-
119
- arr.bufferSize = arr.buffer.byteLength
120
- arr.maxByteLength = backing.maxByteLength
121
- arr.items = arr.array.length
122
-
123
- const originalBuffer = arr.buffer
124
-
125
- arr.push(9)
126
-
127
- expect(arr.buffer).toBe(originalBuffer)
128
- expect(arr.array.length).toBe(16)
129
- expect(arr.buffer.byteLength).toBe(16)
130
- expect(Array.from(arr.slice(0, 9))).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
131
- })
132
- }
133
- })
134
- })
45
+ it("selects the appropriate buffer constructor", () => {
46
+ if (typeof SharedArrayBuffer !== "undefined") {
47
+ expect(BufferConstructor).toBe(SharedArrayBuffer);
48
+ } else {
49
+ expect(BufferConstructor).toBe(ArrayBuffer);
50
+ }
51
+ });
52
+
53
+ describe("ResizeableTypedArray", () => {
54
+ it("reports structured create allocation failures", () => {
55
+ expect(
56
+ () =>
57
+ new ResizeableTypedArray(
58
+ Float64Array,
59
+ FailingCreateArrayBuffer as unknown as ArrayBufferConstructor,
60
+ ),
61
+ ).toThrowError(
62
+ expect.objectContaining({
63
+ name: "TypedBufferAllocationError",
64
+ code: "TYPED_BUFFER_ALLOCATION_FAILED",
65
+ operation: "create",
66
+ typedArray: "Float64Array",
67
+ bufferType: "array-buffer",
68
+ elementCount: INITIAL_BYTES / 8,
69
+ bytesPerElement: 8,
70
+ requiredBytes: INITIAL_BYTES,
71
+ }),
72
+ );
73
+ });
74
+
75
+ it("reports structured grow allocation failures", () => {
76
+ const arr = new ResizeableTypedArray(
77
+ Uint8Array,
78
+ FailingGrowArrayBuffer as unknown as ArrayBufferConstructor,
79
+ );
80
+ arr.pushMany(new Uint8Array(INITIAL_BYTES));
81
+
82
+ expect(() => arr.push(1)).toThrowError(
83
+ expect.objectContaining({
84
+ operation: "grow",
85
+ typedArray: "Uint8Array",
86
+ elementCount: INITIAL_BYTES * 2,
87
+ requiredBytes: INITIAL_BYTES * 2,
88
+ }),
89
+ );
90
+ expect(arr.length).toBe(INITIAL_BYTES);
91
+ });
92
+
93
+ it("reports structured compact allocation failures", () => {
94
+ const arr = new ResizeableTypedArray(
95
+ Float64Array,
96
+ FailingCompactArrayBuffer as unknown as ArrayBufferConstructor,
97
+ );
98
+ arr.pushMany([1, 2, 3]);
99
+
100
+ try {
101
+ arr.compact();
102
+ expect.unreachable("Expected compact to fail");
103
+ } catch (error) {
104
+ expect(error).toBeInstanceOf(TypedBufferAllocationError);
105
+ expect(error).toMatchObject({
106
+ operation: "compact",
107
+ typedArray: "Float64Array",
108
+ elementCount: 3,
109
+ bytesPerElement: 8,
110
+ requiredBytes: 24,
111
+ });
112
+ expect((error as Error).cause).toBeInstanceOf(RangeError);
113
+ }
114
+ });
115
+
116
+ it("push stores values and returns the index", () => {
117
+ const arr = new ResizeableTypedArray(Float64Array);
118
+
119
+ expect(arr.push(1.5)).toBe(0);
120
+ expect(arr.push(2.5)).toBe(1);
121
+ expect(arr.length).toBe(2);
122
+ expect(arr.at(0)).toBe(1.5);
123
+ expect(arr.at(1)).toBe(2.5);
124
+ });
125
+
126
+ it("at supports negative indices and guards bounds", () => {
127
+ const arr = new ResizeableTypedArray(Int16Array);
128
+ arr.pushMany([10, 20, 30]);
129
+
130
+ expect(arr.at(-1)).toBe(30);
131
+ expect(arr.at(-3)).toBe(10);
132
+ expect(() => arr.at(-4)).toThrow(/Index out of bounds/);
133
+ expect(() => arr.at(3)).toThrow(/Index out of bounds/);
134
+ });
135
+
136
+ it("pushMany appends arrays while preserving order, across growth", () => {
137
+ const arr = new ResizeableTypedArray(Uint32Array);
138
+ arr.pushMany([1, 2, 3]);
139
+ arr.pushMany(Uint32Array.from([4, 5]));
140
+ expect(Array.from(arr.array)).toEqual([1, 2, 3, 4, 5]);
141
+
142
+ // One call that needs several doublings grows once, to at least the needed size.
143
+ const many = Uint32Array.from({ length: 100_000 }, (_, i) => i);
144
+ arr.pushMany(many);
145
+ expect(arr.length).toBe(100_005);
146
+ expect(arr.at(-1)).toBe(99_999);
147
+ expect(arr.capacity).toBeGreaterThanOrEqual(100_005);
148
+ });
149
+
150
+ it("exposes only stored items through array, iteration and slice", () => {
151
+ const arr = new ResizeableTypedArray(Uint8Array);
152
+ arr.pushMany([1, 2, 3, 4]);
153
+
154
+ expect(arr.capacity).toBeGreaterThan(4);
155
+ expect(arr.array.length).toBe(4);
156
+ expect([...arr]).toEqual([1, 2, 3, 4]);
157
+
158
+ const segment = arr.slice(1, 3);
159
+ expect(segment).toBeInstanceOf(Uint8Array);
160
+ expect(Array.from(segment)).toEqual([2, 3]);
161
+ segment[0] = 99;
162
+ expect(arr.at(1)).toBe(2);
163
+ });
164
+
165
+ it("set grows and extends the length", () => {
166
+ const arr = new ResizeableTypedArray(Float32Array);
167
+ arr.set(100_000, 5);
168
+ expect(arr.length).toBe(100_001);
169
+ expect(arr.at(100_000)).toBe(5);
170
+ expect(arr.at(0)).toBe(0);
171
+ });
172
+
173
+ it("compact trims unused capacity", () => {
174
+ const arr = new ResizeableTypedArray(Float64Array);
175
+ arr.pushMany([5, 6, 7]);
176
+
177
+ const compacted = arr.compact();
178
+
179
+ expect(compacted).toBe(arr.array);
180
+ expect(compacted.length).toBe(3);
181
+ expect(arr.capacity).toBe(3);
182
+ expect(arr.buffer.byteLength).toBe(3 * Float64Array.BYTES_PER_ELEMENT);
183
+ });
184
+
185
+ it("grows again after compact", () => {
186
+ const arr = new ResizeableTypedArray(Uint16Array);
187
+ arr.pushMany([1, 2]);
188
+ arr.compact();
189
+ arr.push(3);
190
+ expect(Array.from(arr.array)).toEqual([1, 2, 3]);
191
+ });
192
+
193
+ it("from wraps a transferred buffer without allocating, and can grow past 2 MiB", () => {
194
+ // A finished column larger than 2 MiB, as received from another worker.
195
+ const backing = new ArrayBuffer(4 * 2 ** 20);
196
+ new Uint32Array(backing).set([1, 2, 3, 4]);
197
+
198
+ const arr = ResizeableTypedArray.from(Uint32Array, backing);
199
+ expect(arr.buffer).toBe(backing);
200
+ expect(arr.length).toBe(2 ** 20);
201
+ expect(arr.at(3)).toBe(4);
202
+
203
+ arr.push(5);
204
+ expect(arr.length).toBe(2 ** 20 + 1);
205
+ expect(arr.at(-1)).toBe(5);
206
+ expect(arr.at(3)).toBe(4);
207
+ });
208
+
209
+ it("falls back to reallocating when the runtime refuses a reservation", () => {
210
+ const arr = new ResizeableTypedArray(
211
+ Uint8Array,
212
+ NoReserveArrayBuffer as unknown as ArrayBufferConstructor,
213
+ );
214
+ const first = arr.buffer;
215
+ arr.pushMany(new Uint8Array(INITIAL_BYTES + 1).fill(7));
216
+ expect(arr.buffer).not.toBe(first);
217
+ expect(arr.length).toBe(INITIAL_BYTES + 1);
218
+ expect(arr.at(-1)).toBe(7);
219
+ });
220
+
221
+ it("projects the capacity a column reaches: doubling, then 1.5× above 256 MiB", () => {
222
+ const MiB = 2 ** 20;
223
+ expect(ResizeableTypedArray.capacityBytesFor(10, 8)).toBe(INITIAL_BYTES);
224
+ expect(ResizeableTypedArray.capacityBytesFor(3 * MiB, 8)).toBe(4 * MiB);
225
+ expect(ResizeableTypedArray.capacityBytesFor(300 * MiB, 8)).toBe(384 * MiB);
226
+ // Just over 2 GiB no longer asks for 4 GiB.
227
+ const capacity = ResizeableTypedArray.capacityBytesFor(2 * 1024 * MiB + 8, 8);
228
+ expect(capacity).toBeLessThan(3 * 1024 * MiB);
229
+ expect(capacity).toBeGreaterThanOrEqual(2 * 1024 * MiB + 8);
230
+ });
231
+
232
+ it("grows in place without copying", () => {
233
+ const arr = new ResizeableTypedArray(Float64Array);
234
+ const first = arr.buffer;
235
+ for (let i = 0; i < 100_000; i++) arr.push(i);
236
+ expect(arr.buffer).toBe(first);
237
+ expect(arr.at(99_999)).toBe(99_999);
238
+ });
239
+
240
+ if (typeof SharedArrayBuffer !== "undefined") {
241
+ it("grows a transferred growable shared buffer in place", () => {
242
+ const backing = new SharedArrayBuffer(8, { maxByteLength: 32 });
243
+ new Uint8Array(backing).set([1, 2, 3, 4, 5, 6, 7, 8]);
244
+
245
+ const arr = ResizeableTypedArray.from(Uint8Array, backing);
246
+ arr.push(9);
247
+
248
+ expect(arr.buffer).toBe(backing);
249
+ expect(arr.capacity).toBe(16);
250
+ expect(Array.from(arr.array)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]);
251
+ });
252
+ }
253
+ });
254
+ });
@@ -1,8 +1,8 @@
1
1
  {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "./tsconfig.json",
4
- "include": ["src"],
5
- "compilerOptions": {
6
- "rootDir": "./src"
7
- }
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig.json",
4
+ "include": ["src"],
5
+ "compilerOptions": {
6
+ "rootDir": "./src"
7
+ }
8
8
  }
package/tsconfig.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "@osmix/shared/tsconfig/base.json",
4
- "exclude": ["node_modules", "dist"],
5
- "include": ["src", "test"],
6
- "compilerOptions": {
7
- "outDir": "./dist"
8
- }
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "@osmix/shared/tsconfig/base.json",
4
+ "exclude": ["node_modules", "dist"],
5
+ "include": ["src", "test"],
6
+ "compilerOptions": {
7
+ "outDir": "./dist"
8
+ }
9
9
  }
@@ -1,37 +0,0 @@
1
- declare module "geokdbush" {
2
- import type KDBush from "kdbush"
3
-
4
- /**
5
- * Returns an array of the closest points from a given location in order of increasing distance.
6
- * @param index - A KDBush index with geographic coordinates (lng, lat) in degrees.
7
- * @param lng - Query point longitude in degrees.
8
- * @param lat - Query point latitude in degrees.
9
- * @param maxResults - Maximum number of points to return (default: Infinity).
10
- * @param maxDistance - Maximum distance in kilometers (default: Infinity).
11
- * @param predicate - Optional filter function called with index of each point.
12
- * @returns Array of point indices from the index, sorted by distance.
13
- */
14
- export function around(
15
- index: KDBush,
16
- lng: number,
17
- lat: number,
18
- maxResults?: number,
19
- maxDistance?: number,
20
- predicate?: (index: number) => boolean,
21
- ): number[]
22
-
23
- /**
24
- * Returns the great circle distance between two locations in kilometers.
25
- * @param lng1 - First point longitude in degrees.
26
- * @param lat1 - First point latitude in degrees.
27
- * @param lng2 - Second point longitude in degrees.
28
- * @param lat2 - Second point latitude in degrees.
29
- * @returns Distance in kilometers.
30
- */
31
- export function distance(
32
- lng1: number,
33
- lat1: number,
34
- lng2: number,
35
- lat2: number,
36
- ): number
37
- }
@@ -1,47 +0,0 @@
1
- declare module "kdbush" {
2
- import type {
3
- BufferConstructor,
4
- BufferType,
5
- TypedArray,
6
- TypedArrayConstructor,
7
- } from "../typed-arrays.ts"
8
-
9
- export default class KDBush {
10
- constructor(
11
- length: number,
12
- nodeSize?: number,
13
- ArrayType?: TypedArrayConstructor,
14
- BufferConstructor?: BufferConstructor,
15
- )
16
-
17
- /** Number of items in the index */
18
- numItems: number
19
-
20
- /** Size of the KD-tree node */
21
- nodeSize: number
22
-
23
- /** Serialized index data buffer */
24
- data: BufferType
25
-
26
- /** Internal array of indices (used by geokdbush) */
27
- ids: Uint16Array | Uint32Array
28
-
29
- /** Internal array of coordinates [x0, y0, x1, y1, ...] (used by geokdbush) */
30
- coords: TypedArray
31
-
32
- /** Add a point before calling finish */
33
- add(x: number, y: number): number
34
-
35
- /** Finalize the index after adding all points */
36
- finish(): this
37
-
38
- /** Query points within a bounding box; returns internal point indexes */
39
- range(minX: number, minY: number, maxX: number, maxY: number): number[]
40
-
41
- /** Query points within a radius from (x, y); returns internal point indexes */
42
- within(x: number, y: number, radius: number): number[]
43
-
44
- /** Reconstruct an index from a serialized buffer */
45
- static from(data: BufferType): KDBush
46
- }
47
- }