456
457
getState(): mixed;
458
}
459
+
460
+// Ported from definitely-typed
461
+declare module 'rbush' {
462
+ declare interface BBox {
463
+ minX: number;
464
+ minY: number;
465
+ maxX: number;
466
+ maxY: number;
467
+ }
468
+
469
+ declare export default class RBush<T> {
470
+ /**
471
+ * Constructs an `RBush`, a high-performance 2D spatial index for points and
472
+ * rectangles. Based on an optimized __R-tree__ data structure with
473
+ * __bulk-insertion__ support.
474
+ *
475
+ * @param maxEntries An optional argument to RBush defines the maximum
476
+ * number of entries in a tree node. `9` (used by default)
477
+ * is a reasonable choice for most applications. Higher
478
+ * value means faster insertion and slower search, and
479
+ * vice versa.
480
+ */
481
+ constructor(maxEntries?: number): void;
482
+
483
+ /**
484
+ * Inserts an item. To insert many items at once, use `load()`.
485
+ *
486
+ * @param item The item to insert.
487
+ */
488
+ insert(item: T): RBush<T>;
489
+
490
+ /**
491
+ * Bulk-inserts the given items into the tree.
492
+ *
493
+ * Bulk insertion is usually ~2-3 times faster than inserting items one by
494
+ * one. After bulk loading (bulk insertion into an empty tree), subsequent
495
+ * query performance is also ~20-30% better.
496
+ *
497
+ * Note that when you do bulk insertion into an existing tree, it bulk-loads
498
+ * the given data into a separate tree and inserts the smaller tree into the
499
+ * larger tree. This means that bulk insertion works very well for clustered
500
+ * data (where items in one update are close to each other), but makes query
501
+ * performance worse if the data is scattered.
502
+ *
503
+ * @param items The items to load.
504
+ */
505
+ load(items: $ReadOnlyArray<T>): RBush<T>;
506
+
507
+ /**
508
+ * Removes a previously inserted item, comparing by reference.
509
+ *
510
+ * To remove all items, use `clear()`.
511
+ *
512
+ * @param item The item to remove.
513
+ * @param equals A custom function that allows comparing by value instead.
514
+ * Useful when you have only a copy of the object you need
515
+ * removed (e.g. loaded from server).
516
+ */
517
+ remove(item: T, equals?: (a: T, b: T) => boolean): RBush<T>;
518
+
519
+ /**
520
+ * Removes all items.
521
+ */
522
+ clear(): RBush<T>;
523
+
524
+ /**
525
+ * Returns an array of data items (points or rectangles) that the given
526
+ * bounding box intersects.
527
+ *
528
+ * Note that the search method accepts a bounding box in `{minX, minY, maxX,
529
+ * maxY}` format regardless of the data format.
530
+ *
531
+ * @param box The bounding box in which to search.
532
+ */
533
+ search(box: BBox): T[];
534
+
535
+ /**
536
+ * Returns all items contained in the tree.
537
+ */
538
+ all(): T[];
539
+
540
+ /**
541
+ * Returns `true` if there are any items intersecting the given bounding
542
+ * box, otherwise `false`.
543
+ *
544
+ * @param box The bounding box in which to search.
545
+ */
546
+ collides(box: BBox): boolean;
547
+
548
+ /**
549
+ * Returns the bounding box for the provided item.
550
+ *
551
+ * By default, `RBush` assumes the format of data points to be an object
552
+ * with `minX`, `minY`, `maxX`, and `maxY`. However, you can specify a
553
+ * custom item format by overriding `toBBox()`, `compareMinX()`, and
554
+ * `compareMinY()`.
555
+ *
556
+ * @example
557
+ * class MyRBush<T> extends RBush<T> {
558
+ * toBBox([x, y]) { return { minX: x, minY: y, maxX: x, maxY: y }; }
559
+ * compareMinX(a, b) { return a.x - b.x; }
560
+ * compareMinY(a, b) { return a.y - b.y; }
561
+ * }
562
+ * const tree = new MyRBush<[number, number]>();
563
+ * tree.insert([20, 50]); // accepts [x, y] points
564
+ *
565
+ * @param item The item whose bounding box should be returned.
566
+ */
567
+ toBBox(item: T): BBox;
568
+
569
+ /**
570
+ * Compares the minimum x coordinate of two items. Returns -1 if `a`'s
571
+ * x-coordinate is smaller, 1 if `b`'s x coordinate is smaller, or 0 if
572
+ * they're equal.
573
+ *
574
+ * By default, `RBush` assumes the format of data points to be an object
575
+ * with `minX`, `minY`, `maxX`, and `maxY`. However, you can specify a
576
+ * custom item format by overriding `toBBox()`, `compareMinX()`, and
577
+ * `compareMinY()`.
578
+ *
579
+ * @example
580
+ * class MyRBush<T> extends RBush<T> {
581
+ * toBBox([x, y]) { return { minX: x, minY: y, maxX: x, maxY: y }; }
582
+ * compareMinX(a, b) { return a.x - b.x; }
583
+ * compareMinY(a, b) { return a.y - b.y; }
584
+ * }
585
+ * const tree = new MyRBush<[number, number]>();
586
+ * tree.insert([20, 50]); // accepts [x, y] points
587
+ *
588
+ * @param a The first item to compare.
589
+ * @param b The second item to compare.
590
+ */
591
+ compareMinX(a: T, b: T): number;
592
+
593
+ /**
594
+ * Compares the minimum y coordinate of two items. Returns -1 if `a`'s
595
+ * x-coordinate is smaller, 1 if `b`'s x coordinate is smaller, or 0 if
596
+ * they're equal.
597
+ *
598
+ * By default, `RBush` assumes the format of data points to be an object
599
+ * with `minX`, `minY`, `maxX`, and `maxY`. However, you can specify a
600
+ * custom item format by overriding `toBBox()`, `compareMinX()`, and
601
+ * `compareMinY()`.
602
+ *
603
+ * @example
604
+ * class MyRBush<T> extends RBush<T> {
605
+ * toBBox([x, y]) { return { minX: x, minY: y, maxX: x, maxY: y }; }
606
+ * compareMinX(a, b) { return a.x - b.x; }
607
+ * compareMinY(a, b) { return a.y - b.y; }
608
+ * }
609
+ * const tree = new MyRBush<[number, number]>();
610
+ * tree.insert([20, 50]); // accepts [x, y] points
611
+ *
612
+ * @param a The first item to compare.
613
+ * @param b The second item to compare.
614
+ */
615
+ compareMinY(a: T, b: T): number;
616
+
617
+ /**
618
+ * Exports the tree's contents as a JSON object.
619
+ *
620
+ * Importing and exporting as JSON allows you to use RBush on both the
621
+ * server (using Node.js) and the browser combined, e.g. first indexing the
622
+ * data on the server and and then importing the resulting tree data on the
623
+ * client for searching.
624
+ *
625
+ * Note that the `maxEntries` option from the constructor must be the same
626
+ * in both trees for export/import to work properly.
627
+ */
628
+ toJSON(): any;
629
+
630
+ /**
631
+ * Imports previously exported data into the tree (i.e., data that was
632
+ * emitted by `toJSON()`).
633
+ *
634
+ * Importing and exporting as JSON allows you to use RBush on both the
635
+ * server (using Node.js) and the browser combined, e.g. first indexing the
636
+ * data on the server and and then importing the resulting tree data on the
637
+ * client for searching.
638
+ *
639
+ * Note that the `maxEntries` option from the constructor must be the same
640
+ * in both trees for export/import to work properly.
641
+ *
642
+ * @param data The previously exported JSON data.
643
+ */
644
+ fromJSON(data: any): RBush<T>;
645
+ }
646
+}