Skip to content

Commit

Permalink
refactor(geom-accel): move iterator into KdNode
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Oct 18, 2018
1 parent aa01a2d commit 0c76c02
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/geom-accel/src/kdtree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ export class KdNode<T extends KdIndexable<T>> {
this.l = this.r = null;
}

*[Symbol.iterator](): IterableIterator<T> {
let queue: KdNode<T>[] = [this];
while (queue.length) {
const n = queue.pop();
if (n) {
yield n.p;
queue.push(n.r, n.l);
}
}
}

height() {
return 1 + Math.max(
this.l ? this.l.height() : 0,
Expand Down Expand Up @@ -51,15 +62,8 @@ export class KdTree<T extends KdIndexable<T>> {
null;
}

*[Symbol.iterator](): IterableIterator<T> {
let queue: KdNode<T>[] = [this.root];
while (queue.length) {
const n = queue.pop();
if (n) {
yield n.p;
queue.push(n.r, n.l);
}
}
[Symbol.iterator](): IterableIterator<T> {
return (this.root || [])[Symbol.iterator]();
}

get length() {
Expand Down

0 comments on commit 0c76c02

Please sign in to comment.