mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #17367 from DenisCarriere/geokdbush
Implement Geokdbush definition
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import * as kdbush from 'kdbush';
|
||||
import * as geokdbush from 'geokdbush';
|
||||
|
||||
const points = [
|
||||
{lon: 0, lat: 0},
|
||||
{lon: 20, lat: 10},
|
||||
{lon: -10, lat: 30},
|
||||
];
|
||||
const index = kdbush(points, p => p.lon, p => p.lat);
|
||||
const nearest = geokdbush.around(index, -119.7051, 34.4363, 1000);
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// Type definitions for geokdbush 1.1
|
||||
// Project: https://github.com/mourner/geokdbush
|
||||
// Definitions by: Denis Carriere <https://github.com/DenisCarriere>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import {KDBush} from 'kdbush';
|
||||
|
||||
export function around<T>(
|
||||
index: KDBush<T>,
|
||||
longitude: number,
|
||||
latitude: number,
|
||||
maxResults?: number,
|
||||
maxDistance?: number,
|
||||
filterFn?: any): T[];
|
||||
|
||||
export function distance(
|
||||
longitude1: number,
|
||||
latitude1: number,
|
||||
longitude2: number,
|
||||
latitude2: number): number;
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"geokdbush-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Vendored
+11
-15
@@ -7,20 +7,16 @@ type Points = number[][];
|
||||
type Get<T> = (point: T) => number;
|
||||
type ArrayType = typeof Int32Array | typeof Array;
|
||||
|
||||
declare class KDBush<T> {
|
||||
ids: number[];
|
||||
coords: number[];
|
||||
nodeSize: number;
|
||||
points: T[];
|
||||
range(minX: number, minY: number, maxX: number, maxY: number): number[];
|
||||
within(x: number, y: number, r: number): number[];
|
||||
declare function kdbush(points: Points): kdbush.KDBush<Points>;
|
||||
declare function kdbush<T>(points: T[], getX: Get<T>, getY: Get<T>, nodeSize?: number, ArrayType?: ArrayType): kdbush.KDBush<T>;
|
||||
declare namespace kdbush {
|
||||
class KDBush<T> {
|
||||
ids: number[];
|
||||
coords: number[];
|
||||
nodeSize: number;
|
||||
points: T[];
|
||||
range(minX: number, minY: number, maxX: number, maxY: number): number[];
|
||||
within(x: number, y: number, r: number): number[];
|
||||
}
|
||||
}
|
||||
|
||||
interface KDBushStatic {
|
||||
(points: Points): KDBush<Points>;
|
||||
<T>(points: T[], getX: Get<T>, getY: Get<T>, nodeSize?: number, ArrayType?: ArrayType): KDBush<T>;
|
||||
}
|
||||
|
||||
declare const kdbush: KDBushStatic;
|
||||
declare namespace kdbush {}
|
||||
export = kdbush;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as kdbush from 'kdbush';
|
||||
import {KDBush} from 'kdbush';
|
||||
|
||||
// API
|
||||
const points = [[110, 60], [130, 40]];
|
||||
@@ -20,7 +21,7 @@ index.within(10, 10, 5).map(id => points[id]);
|
||||
|
||||
// custom points (object)
|
||||
const xy = [{x: 110, y: 60}, {x: 130, y: 40}];
|
||||
const index2 = kdbush(xy, p => p.x, p => p.y);
|
||||
const index2: KDBush<{x: number, y: number}> = kdbush(xy, p => p.x, p => p.y);
|
||||
index2.points[0].x;
|
||||
index2.points[0].y;
|
||||
index2.points.map(p => [p.x, p.y]);
|
||||
|
||||
Reference in New Issue
Block a user