@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.
- package/CHANGELOG.md +37 -0
- package/LICENSE +21 -0
- package/README.md +86 -69
- package/dist/contracts.d.ts +26 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +1 -0
- package/dist/contracts.js.map +1 -0
- package/dist/entities.d.ts +1 -1
- package/dist/entities.d.ts.map +1 -1
- package/dist/entities.js +2 -7
- package/dist/entities.js.map +1 -1
- package/dist/ids.d.ts +2 -0
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +23 -15
- package/dist/ids.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/mocks.d.ts.map +1 -1
- package/dist/mocks.js.map +1 -1
- package/dist/nodes.d.ts +9 -3
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +6 -13
- package/dist/nodes.js.map +1 -1
- package/dist/osm.d.ts +1 -1
- package/dist/osm.d.ts.map +1 -1
- package/dist/osm.js +1 -4
- package/dist/osm.js.map +1 -1
- package/dist/relations.d.ts +3 -2
- package/dist/relations.d.ts.map +1 -1
- package/dist/relations.js +15 -9
- package/dist/relations.js.map +1 -1
- package/dist/stringtable.d.ts.map +1 -1
- package/dist/stringtable.js +4 -13
- package/dist/stringtable.js.map +1 -1
- package/dist/tags.d.ts +1 -1
- package/dist/tags.d.ts.map +1 -1
- package/dist/tags.js.map +1 -1
- package/dist/typed-arrays.d.ts +1 -1
- package/dist/typed-arrays.d.ts.map +1 -1
- package/dist/typed-arrays.js.map +1 -1
- package/dist/ways.d.ts +2 -1
- package/dist/ways.d.ts.map +1 -1
- package/dist/ways.js +18 -18
- package/dist/ways.js.map +1 -1
- package/package.json +46 -31
- package/src/contracts.ts +28 -0
- package/src/entities.ts +179 -194
- package/src/ids.ts +228 -235
- package/src/index.ts +12 -9
- package/src/mocks.ts +114 -113
- package/src/nodes.ts +364 -397
- package/src/osm.ts +196 -207
- package/src/relations.ts +530 -558
- package/src/stringtable.ts +174 -183
- package/src/tags.ts +263 -271
- package/src/typed-arrays.ts +184 -194
- package/src/types/geoflatbush.d.ts +28 -33
- package/src/types/geokdbush.d.ts +28 -33
- package/src/types/kdbush.d.ts +34 -34
- package/src/ways.ts +381 -405
- package/test/ids.bench.ts +29 -0
- package/test/ids.test.ts +84 -0
- package/test/memory.test.ts +29 -30
- package/test/relations.bench.ts +27 -0
- package/test/relations.test.ts +101 -0
- package/test/tags-search.test.ts +76 -56
- package/test/typed-arrays.test.ts +100 -99
- package/tsconfig.build.json +6 -3
- package/tsconfig.json +7 -7
package/src/typed-arrays.ts
CHANGED
|
@@ -12,36 +12,34 @@
|
|
|
12
12
|
* SharedArrayBuffer enables zero-copy transfer between workers.
|
|
13
13
|
*/
|
|
14
14
|
export const BufferConstructor =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
2
|
+
import type Flatbush from "flatbush";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
}
|
package/src/types/geokdbush.d.ts
CHANGED
|
@@ -1,37 +1,32 @@
|
|
|
1
1
|
declare module "geokdbush" {
|
|
2
|
-
|
|
2
|
+
import type KDBush from "kdbush";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
}
|
package/src/types/kdbush.d.ts
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
declare module "kdbush" {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import type {
|
|
3
|
+
BufferConstructor,
|
|
4
|
+
BufferType,
|
|
5
|
+
TypedArray,
|
|
6
|
+
TypedArrayConstructor,
|
|
7
|
+
} from "../typed-arrays.ts";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
export default class KDBush {
|
|
10
|
+
constructor(
|
|
11
|
+
length: number,
|
|
12
|
+
nodeSize?: number,
|
|
13
|
+
ArrayType?: TypedArrayConstructor,
|
|
14
|
+
BufferConstructor?: BufferConstructor,
|
|
15
|
+
);
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/** Number of items in the index */
|
|
18
|
+
numItems: number;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/** Size of the KD-tree node */
|
|
21
|
+
nodeSize: number;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/** Serialized index data buffer */
|
|
24
|
+
data: BufferType;
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
/** Internal array of indices (used by geokdbush) */
|
|
27
|
+
ids: Uint16Array | Uint32Array;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
/** Internal array of coordinates [x0, y0, x1, y1, ...] (used by geokdbush) */
|
|
30
|
+
coords: TypedArray;
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
/** Add a point before calling finish */
|
|
33
|
+
add(x: number, y: number): number;
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
/** Finalize the index after adding all points */
|
|
36
|
+
finish(): this;
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
42
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
/** Reconstruct an index from a serialized buffer */
|
|
45
|
+
static from(data: BufferType): KDBush;
|
|
46
|
+
}
|
|
47
47
|
}
|