Skip to content

Commit

Permalink
Merge pull request #42 from canadaduane/add-leaves-test
Browse files Browse the repository at this point in the history
Add PointOctree tests for leaves in small and large octrees
  • Loading branch information
vanruesc authored Feb 26, 2022
2 parents 3cc0c0f + 8376457 commit 8840141
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/points/PointOctree.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,41 @@ test("can find points inside a radius", t => {
t.is(octree.findPoints(new Vector3(0, 0, 0), 0.15, true).length, 2, "should be able to skip itself");

});

test("retrieves leaves when octree is small", (t) => {
const octree = new PointOctree(box.min, box.max);

octree.set(new Vector3(0.0, 0, 0), data0);
octree.set(new Vector3(0.1, 0, 0), data1);
octree.set(new Vector3(0.2, 0, 0), data2);

const found = [];
for (let node of octree.leaves()) {
if (!node.data) continue;
const { points } = node.data;
if (points) {
for (let point of points) found.push(point);
}
}

t.is(found.length, 3, "should find points");
});

test("retrieves leaves when octree is large", (t) => {
const octree = new PointOctree(box.min, box.max);

for (let i = 0; i < 100; i++) {
octree.set(new Vector3(0 + i / 100, 0, 0), data0);
}

const found = [];
for (let node of octree.leaves()) {
if (!node.data) continue;
const { points } = node.data;
if (points) {
for (let point of points) found.push(point);
}
}

t.is(found.length, 100, "should find points");
});

0 comments on commit 8840141

Please # to comment.