Merge pull request #17367 from DenisCarriere/geokdbush

Implement Geokdbush definition
This commit is contained in:
Nathan Shively-Sanders
2017-06-21 14:44:38 -07:00
committed by GitHub
6 changed files with 66 additions and 16 deletions
+10
View File
@@ -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);
+20
View File
@@ -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;
+22
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+11 -15
View File
@@ -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;
+2 -1
View File
@@ -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]);