@tscircuit/capacity-autorouter 0.0.102 → 0.0.103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1842,8 +1842,10 @@ var FlatbushIndex = class {
1842
1842
  index;
1843
1843
  items = [];
1844
1844
  currentIndex = 0;
1845
+ capacity;
1845
1846
  constructor(numItems) {
1846
- this.index = new Flatbush(numItems);
1847
+ this.capacity = Math.max(1, numItems);
1848
+ this.index = new Flatbush(this.capacity);
1847
1849
  }
1848
1850
  insert(item, minX, minY, maxX, maxY) {
1849
1851
  if (this.currentIndex >= this.index.numItems) {
@@ -1862,7 +1864,8 @@ var FlatbushIndex = class {
1862
1864
  }
1863
1865
  clear() {
1864
1866
  this.items = [];
1865
- this.index = new Flatbush(0);
1867
+ this.currentIndex = 0;
1868
+ this.index = new Flatbush(this.capacity);
1866
1869
  }
1867
1870
  };
1868
1871
 
@@ -1872,7 +1875,12 @@ var ObstacleSpatialHashIndex = class {
1872
1875
  storage = [];
1873
1876
  constructor(implementation = "native", obstacles = []) {
1874
1877
  if (implementation === "flatbush") {
1875
- this.idx = new FlatbushIndex(obstacles.length);
1878
+ if (obstacles.length === 0) {
1879
+ this.idx = new RbushIndex();
1880
+ implementation = "rbush";
1881
+ } else {
1882
+ this.idx = new FlatbushIndex(obstacles.length);
1883
+ }
1876
1884
  } else if (implementation === "rbush") {
1877
1885
  this.idx = new RbushIndex();
1878
1886
  } else {
@@ -1892,7 +1900,8 @@ var ObstacleSpatialHashIndex = class {
1892
1900
  }();
1893
1901
  }
1894
1902
  obstacles.forEach((o) => this.insert(o));
1895
- if (implementation === "flatbush") this.idx.finish?.();
1903
+ if (implementation === "flatbush" && obstacles.length > 0)
1904
+ this.idx.finish?.();
1896
1905
  }
1897
1906
  insert(o) {
1898
1907
  this.storage.push(o);