@osmix/core 0.1.8 → 0.2.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 (71) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +21 -0
  3. package/README.md +86 -69
  4. package/dist/contracts.d.ts +26 -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 +1 -1
  9. package/dist/entities.d.ts.map +1 -1
  10. package/dist/entities.js +2 -7
  11. package/dist/entities.js.map +1 -1
  12. package/dist/ids.d.ts +2 -0
  13. package/dist/ids.d.ts.map +1 -1
  14. package/dist/ids.js +23 -15
  15. package/dist/ids.js.map +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +0 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/mocks.d.ts.map +1 -1
  21. package/dist/mocks.js.map +1 -1
  22. package/dist/nodes.d.ts +9 -3
  23. package/dist/nodes.d.ts.map +1 -1
  24. package/dist/nodes.js +6 -13
  25. package/dist/nodes.js.map +1 -1
  26. package/dist/osm.d.ts +1 -1
  27. package/dist/osm.d.ts.map +1 -1
  28. package/dist/osm.js +1 -4
  29. package/dist/osm.js.map +1 -1
  30. package/dist/relations.d.ts +3 -2
  31. package/dist/relations.d.ts.map +1 -1
  32. package/dist/relations.js +15 -9
  33. package/dist/relations.js.map +1 -1
  34. package/dist/stringtable.d.ts.map +1 -1
  35. package/dist/stringtable.js +4 -13
  36. package/dist/stringtable.js.map +1 -1
  37. package/dist/tags.d.ts +1 -1
  38. package/dist/tags.d.ts.map +1 -1
  39. package/dist/tags.js.map +1 -1
  40. package/dist/typed-arrays.d.ts +1 -1
  41. package/dist/typed-arrays.d.ts.map +1 -1
  42. package/dist/typed-arrays.js.map +1 -1
  43. package/dist/ways.d.ts +2 -1
  44. package/dist/ways.d.ts.map +1 -1
  45. package/dist/ways.js +18 -18
  46. package/dist/ways.js.map +1 -1
  47. package/package.json +46 -31
  48. package/src/contracts.ts +28 -0
  49. package/src/entities.ts +179 -194
  50. package/src/ids.ts +228 -235
  51. package/src/index.ts +12 -9
  52. package/src/mocks.ts +114 -113
  53. package/src/nodes.ts +364 -397
  54. package/src/osm.ts +196 -207
  55. package/src/relations.ts +530 -558
  56. package/src/stringtable.ts +174 -183
  57. package/src/tags.ts +263 -271
  58. package/src/typed-arrays.ts +184 -194
  59. package/src/types/geoflatbush.d.ts +28 -33
  60. package/src/types/geokdbush.d.ts +28 -33
  61. package/src/types/kdbush.d.ts +34 -34
  62. package/src/ways.ts +381 -405
  63. package/test/ids.bench.ts +29 -0
  64. package/test/ids.test.ts +84 -0
  65. package/test/memory.test.ts +29 -30
  66. package/test/relations.bench.ts +27 -0
  67. package/test/relations.test.ts +101 -0
  68. package/test/tags-search.test.ts +76 -56
  69. package/test/typed-arrays.test.ts +100 -99
  70. package/tsconfig.build.json +6 -3
  71. package/tsconfig.json +7 -7
@@ -12,36 +12,34 @@
12
12
  * SharedArrayBuffer enables zero-copy transfer between workers.
13
13
  */
14
14
  export const BufferConstructor =
15
- typeof SharedArrayBuffer !== "undefined"
16
- ? (SharedArrayBuffer as SharedArrayBufferConstructor)
17
- : (ArrayBuffer as ArrayBufferConstructor)
15
+ typeof SharedArrayBuffer !== "undefined"
16
+ ? (SharedArrayBuffer as SharedArrayBufferConstructor)
17
+ : (ArrayBuffer as ArrayBufferConstructor);
18
18
 
19
19
  /** The buffer type used by this runtime (SharedArrayBuffer or ArrayBuffer). */
20
- export type BufferType = InstanceType<typeof BufferConstructor>
20
+ export type BufferType = InstanceType<typeof BufferConstructor>;
21
21
 
22
22
  /**
23
23
  * Union of all standard typed array types.
24
24
  * Generic over buffer type to preserve SharedArrayBuffer compatibility.
25
25
  */
26
26
  export type TypedArray<B extends BufferType = BufferType> =
27
- | Int8Array<B>
28
- | Uint8Array<B>
29
- | Uint8ClampedArray<B>
30
- | Int16Array<B>
31
- | Uint16Array<B>
32
- | Int32Array<B>
33
- | Uint32Array<B>
34
- | Float32Array<B>
35
- | Float64Array<B>
27
+ | Int8Array<B>
28
+ | Uint8Array<B>
29
+ | Uint8ClampedArray<B>
30
+ | Int16Array<B>
31
+ | Uint16Array<B>
32
+ | Int32Array<B>
33
+ | Uint32Array<B>
34
+ | Float32Array<B>
35
+ | Float64Array<B>;
36
36
 
37
37
  /**
38
38
  * Constructor interface for typed arrays.
39
39
  */
40
- export interface TypedArrayConstructor<
41
- T extends TypedArray<BufferType> = TypedArray<BufferType>,
42
- > {
43
- new (buffer: BufferType): T
44
- readonly BYTES_PER_ELEMENT: number
40
+ export interface TypedArrayConstructor<T extends TypedArray<BufferType> = TypedArray<BufferType>> {
41
+ new (buffer: BufferType): T;
42
+ readonly BYTES_PER_ELEMENT: number;
45
43
  }
46
44
 
47
45
  /**
@@ -51,7 +49,7 @@ export interface TypedArrayConstructor<
51
49
  * can exactly represent integers up to 2^53, which covers all current OSM IDs.
52
50
  * Float64Array allows typed array operations while maintaining precision.
53
51
  */
54
- export const IdArrayType = Float64Array
52
+ export const IdArrayType = Float64Array;
55
53
 
56
54
  /**
57
55
  * Uint32Array for storing array indices.
@@ -59,13 +57,13 @@ export const IdArrayType = Float64Array
59
57
  * Internal indices into typed arrays never exceed 2^32 elements,
60
58
  * so Uint32Array provides the best balance of range and memory efficiency.
61
59
  */
62
- export const IndexArrayType = Uint32Array
60
+ export const IndexArrayType = Uint32Array;
63
61
 
64
62
  /**
65
63
  * Initial buffer size for ResizeableTypedArray.
66
64
  * 1 MiB provides reasonable initial capacity while avoiding excessive memory allocation.
67
65
  */
68
- export const DEFAULT_BUFFER_SIZE = 2 ** 20 // 1 MiB
66
+ export const DEFAULT_BUFFER_SIZE = 2 ** 20; // 1 MiB
69
67
 
70
68
  /**
71
69
  * Auto-expanding typed array wrapper.
@@ -75,177 +73,169 @@ export const DEFAULT_BUFFER_SIZE = 2 ** 20 // 1 MiB
75
73
  * - Supports growable SharedArrayBuffer and resizable ArrayBuffer.
76
74
  */
77
75
  export class ResizeableTypedArray<TA extends TypedArray> {
78
- /** The typed array constructor for this instance */
79
- ArrayType: TypedArrayConstructor<TA>
80
- /** The current typed array view into the buffer */
81
- array: TA
82
- /** Number of items actually stored (may be less than array.length) */
83
- items = 0
84
-
85
- /** The underlying ArrayBuffer or SharedArrayBuffer */
86
- buffer: BufferType
87
- /** Current buffer size in bytes */
88
- bufferSize: number
89
- /** Maximum byte length for growable buffers */
90
- maxByteLength: number
91
-
92
- /** Buffer constructor (SharedArrayBuffer or ArrayBuffer) */
93
- BC: SharedArrayBufferConstructor | ArrayBufferConstructor
94
-
95
- /**
96
- * Reconstruct a ResizeableTypedArray from an existing buffer.
97
- *
98
- * Used after transferring buffers between workers. The resulting array
99
- * is considered "compacted" with items = array.length.
100
- *
101
- * @param ArrayType - The typed array constructor.
102
- * @param buffer - The existing buffer to wrap.
103
- * @returns A new ResizeableTypedArray wrapping the buffer.
104
- */
105
- static from<TA extends TypedArray>(
106
- ArrayType: TypedArrayConstructor<TA>,
107
- buffer: BufferType,
108
- ) {
109
- const rta = new ResizeableTypedArray<TA>(
110
- ArrayType,
111
- buffer instanceof SharedArrayBuffer ? SharedArrayBuffer : ArrayBuffer,
112
- )
113
- rta.buffer = buffer
114
- rta.array = new ArrayType(buffer)
115
- rta.items = rta.array.length
116
- return rta
117
- }
118
-
119
- /**
120
- * Create a new ResizeableTypedArray with an empty buffer.
121
- *
122
- * @param ArrayType - The typed array constructor (e.g., Float64Array).
123
- * @param BC - Buffer constructor to use (defaults to SharedArrayBuffer if available).
124
- */
125
- constructor(
126
- ArrayType: TypedArrayConstructor<TA>,
127
- BC:
128
- | SharedArrayBufferConstructor
129
- | ArrayBufferConstructor = BufferConstructor,
130
- ) {
131
- this.ArrayType = ArrayType
132
- this.bufferSize = DEFAULT_BUFFER_SIZE
133
- this.maxByteLength = DEFAULT_BUFFER_SIZE * 2
134
- this.BC = BC
135
- this.buffer = new BC(this.bufferSize, {
136
- maxByteLength: this.maxByteLength,
137
- })
138
- this.array = new this.ArrayType(this.buffer)
139
- }
140
-
141
- /**
142
- * Iterate over the array values.
143
- */
144
- [Symbol.iterator](): ArrayIterator<number> {
145
- return this.array[Symbol.iterator]()
146
- }
147
-
148
- /**
149
- * Double the buffer capacity.
150
- * Uses in-place grow/resize if supported, otherwise allocates new buffer and copies.
151
- */
152
- expandArray() {
153
- this.bufferSize *= 2
154
- if (this.bufferSize > this.buffer.maxByteLength) {
155
- // Need a completely new buffer with larger maxByteLength
156
- this.maxByteLength *= 2
157
- const newBuffer = new this.BC(this.bufferSize, {
158
- maxByteLength: this.maxByteLength,
159
- })
160
- const newArray = new this.ArrayType(newBuffer)
161
- newArray.set(this.array)
162
- this.buffer = newBuffer
163
- this.array = newArray
164
- } else {
165
- // Can grow/resize the existing buffer in place
166
- if (this.buffer instanceof SharedArrayBuffer && this.buffer.growable) {
167
- this.buffer.grow(this.bufferSize)
168
- } else if (this.buffer instanceof ArrayBuffer && this.buffer.resizable) {
169
- this.buffer.resize(this.bufferSize)
170
- } else {
171
- throw Error("Buffer is not growable or resizable")
172
- }
173
- }
174
- }
175
-
176
- /**
177
- * Get the value at an index. Handles negative indices.
178
- */
179
- at(index: number): number {
180
- if (index < -this.length || index >= this.length)
181
- throw Error(`Index out of bounds: ${index}. Length: ${this.length}`)
182
- if (index < 0) return this.at(this.length + index)
183
- const result = this.array[index]
184
- if (result === undefined) throw Error(`No value at index: ${index}`)
185
- return result
186
- }
187
-
188
- /**
189
- * Get a slice of the array.
190
- */
191
- slice(start: number, end: number) {
192
- return this.array.slice(start, end)
193
- }
194
-
195
- get length() {
196
- return this.items
197
- }
198
-
199
- /**
200
- * Push a value to the end of the array.
201
- */
202
- push(value: number): number {
203
- if (this.length >= this.array.length) {
204
- this.expandArray()
205
- }
206
- this.array[this.items++] = value
207
- return this.length - 1
208
- }
209
-
210
- /**
211
- * Set a value at a specific index. Expands array if needed.
212
- */
213
- set(index: number, value: number) {
214
- if (index < 0) throw Error("Index out of bounds")
215
- if (index >= this.length) {
216
- while (index >= this.array.length) this.expandArray()
217
- this.items = index + 1
218
- }
219
- this.array[index] = value
220
- }
221
-
222
- /**
223
- * Push multiple values to the end of the array.
224
- */
225
- pushMany(values: number[] | TypedArray) {
226
- while (this.length + values.length > this.array.length) this.expandArray()
227
- this.array.set(values, this.length)
228
- this.items += values.length
229
- }
230
-
231
- /**
232
- * Shrink the buffer to exactly fit stored items.
233
- * Buffer becomes fixed-length after compacting.
234
- */
235
- compact() {
236
- if (this.buffer instanceof SharedArrayBuffer) {
237
- // SharedArrayBuffer uses slice() to create a new fixed-size buffer
238
- this.buffer = this.buffer.slice(
239
- 0,
240
- this.length * this.ArrayType.BYTES_PER_ELEMENT,
241
- )
242
- } else {
243
- // ArrayBuffer uses transferToFixedLength() to detach and resize
244
- this.buffer = this.buffer.transferToFixedLength(
245
- this.length * this.ArrayType.BYTES_PER_ELEMENT,
246
- )
247
- }
248
- this.array = new this.ArrayType(this.buffer)
249
- return this.array
250
- }
76
+ /** The typed array constructor for this instance */
77
+ ArrayType: TypedArrayConstructor<TA>;
78
+ /** The current typed array view into the buffer */
79
+ array: TA;
80
+ /** Number of items actually stored (may be less than array.length) */
81
+ items = 0;
82
+
83
+ /** The underlying ArrayBuffer or SharedArrayBuffer */
84
+ buffer: BufferType;
85
+ /** Current buffer size in bytes */
86
+ bufferSize: number;
87
+ /** Maximum byte length for growable buffers */
88
+ maxByteLength: number;
89
+
90
+ /** Buffer constructor (SharedArrayBuffer or ArrayBuffer) */
91
+ BC: SharedArrayBufferConstructor | ArrayBufferConstructor;
92
+
93
+ /**
94
+ * Reconstruct a ResizeableTypedArray from an existing buffer.
95
+ *
96
+ * Used after transferring buffers between workers. The resulting array
97
+ * is considered "compacted" with items = array.length.
98
+ *
99
+ * @param ArrayType - The typed array constructor.
100
+ * @param buffer - The existing buffer to wrap.
101
+ * @returns A new ResizeableTypedArray wrapping the buffer.
102
+ */
103
+ static from<TA extends TypedArray>(ArrayType: TypedArrayConstructor<TA>, buffer: BufferType) {
104
+ const rta = new ResizeableTypedArray<TA>(
105
+ ArrayType,
106
+ buffer instanceof SharedArrayBuffer ? SharedArrayBuffer : ArrayBuffer,
107
+ );
108
+ rta.buffer = buffer;
109
+ rta.array = new ArrayType(buffer);
110
+ rta.items = rta.array.length;
111
+ return rta;
112
+ }
113
+
114
+ /**
115
+ * Create a new ResizeableTypedArray with an empty buffer.
116
+ *
117
+ * @param ArrayType - The typed array constructor (e.g., Float64Array).
118
+ * @param BC - Buffer constructor to use (defaults to SharedArrayBuffer if available).
119
+ */
120
+ constructor(
121
+ ArrayType: TypedArrayConstructor<TA>,
122
+ BC: SharedArrayBufferConstructor | ArrayBufferConstructor = BufferConstructor,
123
+ ) {
124
+ this.ArrayType = ArrayType;
125
+ this.bufferSize = DEFAULT_BUFFER_SIZE;
126
+ this.maxByteLength = DEFAULT_BUFFER_SIZE * 2;
127
+ this.BC = BC;
128
+ this.buffer = new BC(this.bufferSize, {
129
+ maxByteLength: this.maxByteLength,
130
+ });
131
+ this.array = new this.ArrayType(this.buffer);
132
+ }
133
+
134
+ /**
135
+ * Iterate over the array values.
136
+ */
137
+ [Symbol.iterator](): ArrayIterator<number> {
138
+ return this.array[Symbol.iterator]();
139
+ }
140
+
141
+ /**
142
+ * Double the buffer capacity.
143
+ * Uses in-place grow/resize if supported, otherwise allocates new buffer and copies.
144
+ */
145
+ expandArray() {
146
+ this.bufferSize *= 2;
147
+ if (this.bufferSize > this.buffer.maxByteLength) {
148
+ // Need a completely new buffer with larger maxByteLength
149
+ this.maxByteLength *= 2;
150
+ const newBuffer = new this.BC(this.bufferSize, {
151
+ maxByteLength: this.maxByteLength,
152
+ });
153
+ const newArray = new this.ArrayType(newBuffer);
154
+ newArray.set(this.array);
155
+ this.buffer = newBuffer;
156
+ this.array = newArray;
157
+ } else {
158
+ // Can grow/resize the existing buffer in place
159
+ if (this.buffer instanceof SharedArrayBuffer && this.buffer.growable) {
160
+ this.buffer.grow(this.bufferSize);
161
+ } else if (this.buffer instanceof ArrayBuffer && this.buffer.resizable) {
162
+ this.buffer.resize(this.bufferSize);
163
+ } else {
164
+ throw Error("Buffer is not growable or resizable");
165
+ }
166
+ }
167
+ }
168
+
169
+ /**
170
+ * Get the value at an index. Handles negative indices.
171
+ */
172
+ at(index: number): number {
173
+ if (index < -this.length || index >= this.length)
174
+ throw Error(`Index out of bounds: ${index}. Length: ${this.length}`);
175
+ if (index < 0) return this.at(this.length + index);
176
+ const result = this.array[index];
177
+ if (result === undefined) throw Error(`No value at index: ${index}`);
178
+ return result;
179
+ }
180
+
181
+ /**
182
+ * Get a slice of the array.
183
+ */
184
+ slice(start: number, end: number) {
185
+ return this.array.slice(start, end);
186
+ }
187
+
188
+ get length() {
189
+ return this.items;
190
+ }
191
+
192
+ /**
193
+ * Push a value to the end of the array.
194
+ */
195
+ push(value: number): number {
196
+ if (this.length >= this.array.length) {
197
+ this.expandArray();
198
+ }
199
+ this.array[this.items++] = value;
200
+ return this.length - 1;
201
+ }
202
+
203
+ /**
204
+ * Set a value at a specific index. Expands array if needed.
205
+ */
206
+ set(index: number, value: number) {
207
+ if (index < 0) throw Error("Index out of bounds");
208
+ if (index >= this.length) {
209
+ while (index >= this.array.length) this.expandArray();
210
+ this.items = index + 1;
211
+ }
212
+ this.array[index] = value;
213
+ }
214
+
215
+ /**
216
+ * Push multiple values to the end of the array.
217
+ */
218
+ pushMany(values: number[] | TypedArray) {
219
+ while (this.length + values.length > this.array.length) this.expandArray();
220
+ this.array.set(values, this.length);
221
+ this.items += values.length;
222
+ }
223
+
224
+ /**
225
+ * Shrink the buffer to exactly fit stored items.
226
+ * Buffer becomes fixed-length after compacting.
227
+ */
228
+ compact() {
229
+ if (this.buffer instanceof SharedArrayBuffer) {
230
+ // SharedArrayBuffer uses slice() to create a new fixed-size buffer
231
+ this.buffer = this.buffer.slice(0, this.length * this.ArrayType.BYTES_PER_ELEMENT);
232
+ } else {
233
+ // ArrayBuffer uses transferToFixedLength() to detach and resize
234
+ this.buffer = this.buffer.transferToFixedLength(
235
+ this.length * this.ArrayType.BYTES_PER_ELEMENT,
236
+ );
237
+ }
238
+ this.array = new this.ArrayType(this.buffer);
239
+ return this.array;
240
+ }
251
241
  }
@@ -1,37 +1,32 @@
1
1
  declare module "geoflatbush" {
2
- import type Flatbush from "flatbush"
2
+ import type Flatbush from "flatbush";
3
3
 
4
- /**
5
- * Returns an array of the closest items from a given location in order of increasing distance.
6
- * @param index - A Flatbush index with geographic bounding boxes in degrees (minLng, minLat, maxLng, maxLat).
7
- * @param lng - Query point longitude in degrees.
8
- * @param lat - Query point latitude in degrees.
9
- * @param maxResults - Maximum number of items to return (default: Infinity).
10
- * @param maxDistance - Maximum distance in kilometers (default: Infinity).
11
- * @param filterFn - Optional filter function called with index of each item.
12
- * @returns Array of item indices from the index, sorted by distance.
13
- */
14
- export function around(
15
- index: Flatbush,
16
- lng: number,
17
- lat: number,
18
- maxResults?: number,
19
- maxDistance?: number,
20
- filterFn?: (index: number) => boolean,
21
- ): number[]
4
+ /**
5
+ * Returns an array of the closest items from a given location in order of increasing distance.
6
+ * @param index - A Flatbush index with geographic bounding boxes in degrees (minLng, minLat, maxLng, maxLat).
7
+ * @param lng - Query point longitude in degrees.
8
+ * @param lat - Query point latitude in degrees.
9
+ * @param maxResults - Maximum number of items to return (default: Infinity).
10
+ * @param maxDistance - Maximum distance in kilometers (default: Infinity).
11
+ * @param filterFn - Optional filter function called with index of each item.
12
+ * @returns Array of item indices from the index, sorted by distance.
13
+ */
14
+ export function around(
15
+ index: Flatbush,
16
+ lng: number,
17
+ lat: number,
18
+ maxResults?: number,
19
+ maxDistance?: number,
20
+ filterFn?: (index: number) => boolean,
21
+ ): number[];
22
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
- lng: number,
33
- lat: number,
34
- lng2: number,
35
- lat2: number,
36
- ): number
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(lng: number, lat: number, lng2: number, lat2: number): number;
37
32
  }
@@ -1,37 +1,32 @@
1
1
  declare module "geokdbush" {
2
- import type KDBush from "kdbush"
2
+ import type KDBush from "kdbush";
3
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[]
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
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
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(lng1: number, lat1: number, lng2: number, lat2: number): number;
37
32
  }
@@ -1,47 +1,47 @@
1
1
  declare module "kdbush" {
2
- import type {
3
- BufferConstructor,
4
- BufferType,
5
- TypedArray,
6
- TypedArrayConstructor,
7
- } from "../typed-arrays.ts"
2
+ import type {
3
+ BufferConstructor,
4
+ BufferType,
5
+ TypedArray,
6
+ TypedArrayConstructor,
7
+ } from "../typed-arrays.ts";
8
8
 
9
- export default class KDBush {
10
- constructor(
11
- length: number,
12
- nodeSize?: number,
13
- ArrayType?: TypedArrayConstructor,
14
- BufferConstructor?: BufferConstructor,
15
- )
9
+ export default class KDBush {
10
+ constructor(
11
+ length: number,
12
+ nodeSize?: number,
13
+ ArrayType?: TypedArrayConstructor,
14
+ BufferConstructor?: BufferConstructor,
15
+ );
16
16
 
17
- /** Number of items in the index */
18
- numItems: number
17
+ /** Number of items in the index */
18
+ numItems: number;
19
19
 
20
- /** Size of the KD-tree node */
21
- nodeSize: number
20
+ /** Size of the KD-tree node */
21
+ nodeSize: number;
22
22
 
23
- /** Serialized index data buffer */
24
- data: BufferType
23
+ /** Serialized index data buffer */
24
+ data: BufferType;
25
25
 
26
- /** Internal array of indices (used by geokdbush) */
27
- ids: Uint16Array | Uint32Array
26
+ /** Internal array of indices (used by geokdbush) */
27
+ ids: Uint16Array | Uint32Array;
28
28
 
29
- /** Internal array of coordinates [x0, y0, x1, y1, ...] (used by geokdbush) */
30
- coords: TypedArray
29
+ /** Internal array of coordinates [x0, y0, x1, y1, ...] (used by geokdbush) */
30
+ coords: TypedArray;
31
31
 
32
- /** Add a point before calling finish */
33
- add(x: number, y: number): number
32
+ /** Add a point before calling finish */
33
+ add(x: number, y: number): number;
34
34
 
35
- /** Finalize the index after adding all points */
36
- finish(): this
35
+ /** Finalize the index after adding all points */
36
+ finish(): this;
37
37
 
38
- /** Query points within a bounding box; returns internal point indexes */
39
- range(minX: number, minY: number, maxX: number, maxY: number): number[]
38
+ /** Query points within a bounding box; returns internal point indexes */
39
+ range(minX: number, minY: number, maxX: number, maxY: number): number[];
40
40
 
41
- /** Query points within a radius from (x, y); returns internal point indexes */
42
- within(x: number, y: number, radius: number): number[]
41
+ /** Query points within a radius from (x, y); returns internal point indexes */
42
+ within(x: number, y: number, radius: number): number[];
43
43
 
44
- /** Reconstruct an index from a serialized buffer */
45
- static from(data: BufferType): KDBush
46
- }
44
+ /** Reconstruct an index from a serialized buffer */
45
+ static from(data: BufferType): KDBush;
46
+ }
47
47
  }