mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Publish kdbush definition (#16107)
* Publish kdbush definition * Definition changes based on comments @andy-ms * Add semi-colon
This commit is contained in:
parent
8712d50b29
commit
e4e4d4223f
26
types/kdbush/index.d.ts
vendored
Normal file
26
types/kdbush/index.d.ts
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
// Type definitions for kdbush 1.0
|
||||
// Project: https://github.com/mourner/kdbush
|
||||
// Definitions by: DenisCarriere <https://github.com/DenisCarriere>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
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[];
|
||||
}
|
||||
|
||||
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;
|
||||
35
types/kdbush/kdbush-tests.ts
Normal file
35
types/kdbush/kdbush-tests.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import * as kdbush from 'kdbush';
|
||||
|
||||
// API
|
||||
const points = [[110, 60], [130, 40]];
|
||||
const index = kdbush(points);
|
||||
|
||||
// properties
|
||||
index.nodeSize;
|
||||
index.points;
|
||||
index.ids;
|
||||
index.coords;
|
||||
|
||||
// range
|
||||
index.range(10, 10, 20, 20);
|
||||
index.range(10, 10, 20, 20).map(id => points[id]);
|
||||
|
||||
// within
|
||||
index.within(10, 10, 5);
|
||||
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);
|
||||
index2.points[0].x;
|
||||
index2.points[0].y;
|
||||
index2.points.map(p => [p.x, p.y]);
|
||||
|
||||
// custom points (latlng)
|
||||
const latlng = [[60, 110], [40, 130]];
|
||||
kdbush(latlng, p => p[1], p => p[0]);
|
||||
kdbush(latlng, p => p[1], p => p[0], 64, Int32Array);
|
||||
|
||||
// z coordinate (does not require Get callbacks)
|
||||
const pointsZ = [[110, 60, 4000], [130, 40, 3000]];
|
||||
kdbush(pointsZ);
|
||||
22
types/kdbush/tsconfig.json
Normal file
22
types/kdbush/tsconfig.json
Normal 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",
|
||||
"kdbush-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/kdbush/tslint.json
Normal file
1
types/kdbush/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user