From 8376457dad55ae9c183279d23c8b086b8140a8d0 Mon Sep 17 00:00:00 2001 From: Duane Johnson Date: Sat, 26 Feb 2022 09:59:49 -0700 Subject: [PATCH] Add PointOctree tests for leaves in small and large octrees --- test/points/PointOctree.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/points/PointOctree.js b/test/points/PointOctree.js index bebfe68..6baf12a 100644 --- a/test/points/PointOctree.js +++ b/test/points/PointOctree.js @@ -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"); +});