import type { ICopy , IEmpty , Pair } from "@thi.ng/api" ; import type { IRegionQuery , ISpatialSet } from "@thi.ng/geom-api" ; import type { ReadonlyVec } from "@thi.ng/vectors" ; import { KdTreeMap } from "./kd-tree-map.js" ; export class KdTreeSet < K extends ReadonlyVec > implements ICopy < KdTreeSet < K > > , IEmpty < KdTreeSet < K > > , IRegionQuery < K , K , number > , ISpatialSet < K > { protected tree : KdTreeMap < K , K > ; constructor ( dim , keys ? ) { this . tree = new KdTreeMap ( dim ) ; keys && this . into ( keys ) ; } [ Symbol . iterator ] ( ) { return this . tree . keys ( ) ; } keys ( ) { return this . tree . keys ( ) ; } values ( ) { return this . tree . keys ( ) ; } get size ( ) { return this . tree . size ; } get height ( ) { return this . tree . height ; } get ratio ( ) { return this . tree . ratio ; } copy ( ) { return new KdTreeSet < K > ( this . tree . dim , this ) ; } clear ( ) { this . tree . clear ( ) ; } empty ( ) { return new KdTreeSet < K > ( this . tree . dim ) ; } add ( key , eps ? ) { return this . tree . set ( key , key , eps ) ; } into ( ks , eps ? ) { let ok = true ; for ( let k of ks ) { ok = this . tree . set ( k , k , eps ) && ok ; } return ok ; } remove ( key ) { return this . tree . remove ( key ) ; } has ( key , eps ? ) { return this . tree . has ( key , eps ) ; } get ( key , eps ? ) { return this . tree . get ( key , eps ) ; } query ( q , maxDist , limit ? , acc ? ) { return this . tree . query ( q , maxDist , limit , acc ) ; } queryKeys ( q , maxDist , limit ? , acc ? ) { return this . tree . queryKeys ( q , maxDist , limit , acc ) ; } queryValues ( q , maxDist , limit ? , acc ? ) { return this . tree . queryKeys ( q , maxDist , limit , acc ) ; } }