import type { ICopy , IEmpty , Pair } from "@thi.ng/api" ; import type { IRegionQuery , ISpatialSet } from "@thi.ng/geom-api" ; import { EPS } from "@thi.ng/math/api" ; import type { ReadonlyVec } from "@thi.ng/vectors" ; import { addmN } from "@thi.ng/vectors/addmn" ; import { submN } from "@thi.ng/vectors/submn" ; import { NdQuadtreeMap } from "./nd-quadtree-map.js" ; export class NdQuadtreeSet < K extends ReadonlyVec > implements ICopy < NdQuadtreeSet < K > > , IEmpty < NdQuadtreeSet < K > > , IRegionQuery < K , K , number > , ISpatialSet < K > { remarks static fromMinMax < K extends ReadonlyVec > ( min , max ) { return new NdQuadtreeSet < K > ( addmN ( [ ] , min , max , 0.5 ) , submN ( [ ] , max , min , 0.5 ) ) ; } protected tree : NdQuadtreeMap < K , K > ; protected _size : number ; constructor ( pos , ext , keys ? ) { this . tree = new NdQuadtreeMap < K , K > ( pos , ext ) ; this . _size = 0 ; keys && this . into ( keys ) ; } [ Symbol . iterator ] ( ) { return this . tree . keys ( ) ; } keys ( ) { return this . tree . keys ( ) ; } values ( ) { return this . tree . values ( ) ; } get size ( ) { return this . _size ; } copy ( ) { return new NdQuadtreeSet < K > ( this . tree . root . pos , this . tree . root . ext , this ) ; } clear ( ) { this . tree . clear ( ) ; } empty ( ) { return new NdQuadtreeSet < K > ( this . tree . root . pos , this . tree . root . ext ) ; } add ( key , eps = EPS ) { return this . tree . set ( key , key , eps ) ; } into ( keys , eps = EPS ) { let ok = true ; const tree = this . tree ; for ( let k of keys ) { ok = tree . set ( k , k , eps ) && ok ; } return ok ; } remove ( key ) { return this . tree . remove ( key ) ; } has ( key , eps = 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 ) ; } }