From 45c293734ee3aee2c4f3e410b229a9a5e83271ef Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 21 Jun 2017 14:27:56 -0400 Subject: [PATCH] Add geokdbush type definition --- types/geokdbush/geokdbush-tests.ts | 10 ++++++++++ types/geokdbush/index.d.ts | 20 ++++++++++++++++++++ types/geokdbush/tsconfig.json | 22 ++++++++++++++++++++++ types/geokdbush/tslint.json | 1 + types/kdbush/index.d.ts | 26 +++++++++++--------------- types/kdbush/kdbush-tests.ts | 3 ++- 6 files changed, 66 insertions(+), 16 deletions(-) create mode 100644 types/geokdbush/geokdbush-tests.ts create mode 100644 types/geokdbush/index.d.ts create mode 100644 types/geokdbush/tsconfig.json create mode 100644 types/geokdbush/tslint.json diff --git a/types/geokdbush/geokdbush-tests.ts b/types/geokdbush/geokdbush-tests.ts new file mode 100644 index 0000000000..f2fa9d54c3 --- /dev/null +++ b/types/geokdbush/geokdbush-tests.ts @@ -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); diff --git a/types/geokdbush/index.d.ts b/types/geokdbush/index.d.ts new file mode 100644 index 0000000000..4ece8ff98d --- /dev/null +++ b/types/geokdbush/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for geokdbush 1.1 +// Project: https://github.com/mourner/geokdbush +// Definitions by: Denis Carriere +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import {KDBush} from 'kdbush'; + +export function around( + index: KDBush, + longitude: number, + latitude: number, + maxResults?: number, + maxDistance?: number, + filterFn?: any): T[]; + +export function distance( + longitude1: number, + latitude1: number, + longitude2: number, + latitude2: number): number; diff --git a/types/geokdbush/tsconfig.json b/types/geokdbush/tsconfig.json new file mode 100644 index 0000000000..9f00c027da --- /dev/null +++ b/types/geokdbush/tsconfig.json @@ -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" + ] +} diff --git a/types/geokdbush/tslint.json b/types/geokdbush/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/geokdbush/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/kdbush/index.d.ts b/types/kdbush/index.d.ts index fa1581d09c..3ef758b85e 100644 --- a/types/kdbush/index.d.ts +++ b/types/kdbush/index.d.ts @@ -7,20 +7,16 @@ type Points = number[][]; type Get = (point: T) => number; type ArrayType = typeof Int32Array | typeof Array; -declare class KDBush { - 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; +declare function kdbush(points: T[], getX: Get, getY: Get, nodeSize?: number, ArrayType?: ArrayType): kdbush.KDBush; +declare namespace kdbush { + class KDBush { + 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[], getX: Get, getY: Get, nodeSize?: number, ArrayType?: ArrayType): KDBush; -} - -declare const kdbush: KDBushStatic; -declare namespace kdbush {} export = kdbush; diff --git a/types/kdbush/kdbush-tests.ts b/types/kdbush/kdbush-tests.ts index c9fd8ae11f..fb7e268290 100644 --- a/types/kdbush/kdbush-tests.ts +++ b/types/kdbush/kdbush-tests.ts @@ -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]);