index.d.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. export default class KDBush {
  2. /**
  3. * Creates an index from raw `ArrayBuffer` data.
  4. * @param {ArrayBuffer} data
  5. */
  6. static from(data: ArrayBuffer): KDBush;
  7. /**
  8. * Creates an index that will hold a given number of items.
  9. * @param {number} numItems
  10. * @param {number} [nodeSize=64] Size of the KD-tree node (64 by default).
  11. * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
  12. * @param {ArrayBuffer} [data] (For internal use only)
  13. */
  14. constructor(numItems: number, nodeSize?: number | undefined, ArrayType?: TypedArrayConstructor | undefined, data?: ArrayBuffer | undefined);
  15. numItems: number;
  16. nodeSize: number;
  17. ArrayType: TypedArrayConstructor;
  18. IndexArrayType: Uint16ArrayConstructor | Uint32ArrayConstructor;
  19. data: ArrayBuffer;
  20. ids: Uint16Array | Uint32Array;
  21. coords: Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
  22. _pos: number;
  23. _finished: boolean;
  24. /**
  25. * Add a point to the index.
  26. * @param {number} x
  27. * @param {number} y
  28. * @returns {number} An incremental index associated with the added item (starting from `0`).
  29. */
  30. add(x: number, y: number): number;
  31. /**
  32. * Perform indexing of the added points.
  33. */
  34. finish(): KDBush;
  35. /**
  36. * Search the index for items within a given bounding box.
  37. * @param {number} minX
  38. * @param {number} minY
  39. * @param {number} maxX
  40. * @param {number} maxY
  41. * @returns {number[]} An array of indices correponding to the found items.
  42. */
  43. range(minX: number, minY: number, maxX: number, maxY: number): number[];
  44. /**
  45. * Search the index for items within a given radius.
  46. * @param {number} qx
  47. * @param {number} qy
  48. * @param {number} r Query radius.
  49. * @returns {number[]} An array of indices correponding to the found items.
  50. */
  51. within(qx: number, qy: number, r: number): number[];
  52. }
  53. export type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;