diff --git a/types/flatbush/flatbush-tests.ts b/types/flatbush/flatbush-tests.ts new file mode 100644 index 0000000000..79a3864cf1 --- /dev/null +++ b/types/flatbush/flatbush-tests.ts @@ -0,0 +1,10 @@ +import Flatbush from 'flatbush'; + +const from: Flatbush = Flatbush.from(new ArrayBuffer(0)); + +const index = new Flatbush(1); +index.add(0, 0, 1, 1); +index.finish(); + +const results = index.search(0.5, 0.5, 0.5, 0.5); +const neighbors = index.neighbors(0.5, 0.5); diff --git a/types/flatbush/index.d.ts b/types/flatbush/index.d.ts new file mode 100644 index 0000000000..75117f8c1f --- /dev/null +++ b/types/flatbush/index.d.ts @@ -0,0 +1,100 @@ +// Type definitions for flatbush 3.1 +// Project: https://github.com/mourner/flatbush +// Definitions by: Matt Fedderly +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +type TypedArrayConstructor = + | Int8ArrayConstructor + | Uint8ArrayConstructor + | Uint8ClampedArrayConstructor + | Int16ArrayConstructor + | Uint16ArrayConstructor + | Int32ArrayConstructor + | Uint32ArrayConstructor + | Float32ArrayConstructor + | Float64ArrayConstructor; + +declare class FlatbushClass { + /** + * @param numItems total number of items to be indexed + * @param nodeSize size of the tree node, experiment with different values for best performance. Default 16. + * @param arrayType The array type used for coordinates storage. Other types may be faster in certain cases. Default Float64Array. + */ + constructor(numItems: number, nodeSize?: number, arrayType?: TypedArrayConstructor); + + /** + * Adds a given rectangle to the index. + */ + add(minX: number, minY: number, maxX: number, maxY: number): void; + + /** + * Performs indexing of the added rectangles. Their number must match the one provided when creating a Flatbush object. + */ + finish(): void; + + /** + * Returns an array of indices of items in a given bounding box. + */ + search(minX: number, minY: number, maxX: number, maxY: number, filter?: (idx: number) => boolean): number[]; + + /** + * Returns an array of item indices in order of distance from the given x, y (known as K nearest neighbors, or KNN). + */ + neighbors( + x: number, + y: number, + maxResults?: number, + maxDistance?: number, + filter?: (idx: number) => boolean + ): number[]; + + /** + * Recreates a Flatbush index from raw ArrayBuffer data (that's exposed as index.data on a previously indexed Flatbush instance). + * Very useful for transferring indices between threads or storing them in a file. + */ + static from(data: ArrayBuffer): Flatbush; + + /** + * array buffer that holds the index + */ + readonly data: ArrayBuffer; + + /** + * bounding box of the data. + */ + readonly minX: number; + /** + * bounding box of the data. + */ + readonly minY: number; + /** + * bounding box of the data. + */ + readonly maxX: number; + /** + * bounding box of the data. + */ + readonly maxY: number; + + /** + * number of stored items. + */ + readonly numItems: number; + /** + * number of items in a node tree. + */ + readonly nodeSize: number; + /** + * array type used for internal coordinates storage. + */ + readonly ArrayType: TypedArrayConstructor; + /** + * array type used for internal item indices storage. + */ + readonly IndexArrayType: TypedArrayConstructor; +} + +export type Flatbush = FlatbushClass; +// tslint:disable-next-line:npm-naming https://github.com/mourner/flatbush/blob/master/index.js#L11 +export default FlatbushClass; diff --git a/types/flatbush/tsconfig.json b/types/flatbush/tsconfig.json new file mode 100644 index 0000000000..1f9065c2ba --- /dev/null +++ b/types/flatbush/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "flatbush-tests.ts" + ] +} diff --git a/types/flatbush/tslint.json b/types/flatbush/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/flatbush/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/geoflatbush/geoflatbush-tests.ts b/types/geoflatbush/geoflatbush-tests.ts new file mode 100644 index 0000000000..68bbd5a7b5 --- /dev/null +++ b/types/geoflatbush/geoflatbush-tests.ts @@ -0,0 +1,5 @@ +import Flatbush from 'flatbush'; +import { around } from 'geoflatbush'; + +const index = new Flatbush(1); +const results = around(index, 0, 0); diff --git a/types/geoflatbush/index.d.ts b/types/geoflatbush/index.d.ts new file mode 100644 index 0000000000..767a1bd0df --- /dev/null +++ b/types/geoflatbush/index.d.ts @@ -0,0 +1,22 @@ +// Type definitions for geoflatbush 1.0 +// Project: https://github.com/mourner/geoflatbush +// Definitions by: Matt Fedderly +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +import { Flatbush } from 'flatbush'; + +/** + * Performs nearest neighbors queries for geographic bounding boxes, taking Earth curvature and date line wrapping into account. + * + * @param maxResults the maximum number of results, default Infinity + * @param maxDistance distance in kilometers, default Infinity + */ +export function around( + index: Flatbush, + longitude: number, + latitude: number, + maxResults?: number, + maxDistance?: number, + filter?: (index: number) => boolean +): number[]; diff --git a/types/geoflatbush/tsconfig.json b/types/geoflatbush/tsconfig.json new file mode 100644 index 0000000000..d6b4e88e80 --- /dev/null +++ b/types/geoflatbush/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "geoflatbush-tests.ts" + ] +} diff --git a/types/geoflatbush/tslint.json b/types/geoflatbush/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/geoflatbush/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }