From 23a68fa4d7712f9f97a1a5e24d7b27334959854f Mon Sep 17 00:00:00 2001 From: Christian Scott Date: Mon, 5 Nov 2018 11:06:04 +1300 Subject: [PATCH] update kdbush types --- types/kdbush/index.d.ts | 17 +++++++++++++++-- types/kdbush/kdbush-tests.ts | 17 +++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/types/kdbush/index.d.ts b/types/kdbush/index.d.ts index 3ef758b85e..bea0366da0 100644 --- a/types/kdbush/index.d.ts +++ b/types/kdbush/index.d.ts @@ -1,14 +1,27 @@ // Type definitions for kdbush 1.0 // Project: https://github.com/mourner/kdbush // Definitions by: DenisCarriere +// Christian Scott // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped type Points = number[][]; type Get = (point: T) => number; -type ArrayType = typeof Int32Array | typeof Array; +type ArrayType = + typeof Int8Array + | typeof Int16Array + | typeof Int32Array + | typeof Float32Array + | typeof Float64Array + | typeof Array; declare function kdbush(points: Points): kdbush.KDBush; -declare function kdbush(points: T[], getX: Get, getY: Get, nodeSize?: number, ArrayType?: ArrayType): kdbush.KDBush; +declare function kdbush( + points: T[], + getX: Get, + getY: Get, + nodeSize?: number, + ArrayType?: ArrayType +): kdbush.KDBush; declare namespace kdbush { class KDBush { ids: number[]; diff --git a/types/kdbush/kdbush-tests.ts b/types/kdbush/kdbush-tests.ts index e552af4c19..5ee6165fcb 100644 --- a/types/kdbush/kdbush-tests.ts +++ b/types/kdbush/kdbush-tests.ts @@ -1,10 +1,19 @@ -import * as kdbush from 'kdbush'; -import { KDBush } from 'kdbush'; +import * as kdbush from "kdbush"; +import { KDBush } from "kdbush"; // API const points = [[110, 60], [130, 40]]; const index = kdbush(points); +// Specify array constructor +const pick = (index: number) => (point: number[]) => point[index]; +kdbush(points, pick(0), pick(1), 64, Int8Array); +kdbush(points, pick(0), pick(1), 64, Int16Array); +kdbush(points, pick(0), pick(1), 64, Int32Array); +kdbush(points, pick(0), pick(1), 64, Float32Array); +kdbush(points, pick(0), pick(1), 64, Float64Array); +kdbush(points, pick(0), pick(1), 64, Array); + // properties index.nodeSize; index.points; @@ -20,8 +29,8 @@ 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<{x: number, y: number}> = kdbush(xy, p => p.x, p => p.y); +const xy = [{ x: 110, y: 60 }, { x: 130, y: 40 }]; +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]);