public void DegenerateTrianglesToConstructor_NoError()
        {
            var tri = new Triangle(new Vector(), new Vector(), new Vector(), 0);
            var obj = new SpatialSubdivision(new Triangle[] { tri }, new AxisAlignedBox(new Vector(0, 0, 0), new Vector(1, 1, 1)));

            Assert.IsNotNull(obj);
        }
        private void TestTree_OutsideIn(SpatialSubdivision tree, ICollection <Triangle> triList, int numRays = 100000)
        {
            var triSet = new GeometryCollection();

            foreach (var tri in triList)
            {
                triSet.Add(tri);
            }

            for (var i = 1; i <= numRays; i++)
            {
                var start    = MakeRandomVector(triangleSpaceSize * 10);
                var end      = MakeRandomVector(triangleSpaceSize);
                var dir      = end - start;
                var info     = tree.IntersectRay(start, dir, context);
                var infoBase = triSet.IntersectRay(start, dir, context);
                Assert.AreEqual(infoBase == null, info == null, "Ray " + i + ": SpatialSubdivision and GeometryCollection differ in intersection status");
                if (info != null)
                {
                    Assert.AreEqual(infoBase.triIndex, info.triIndex, "triIndex diff on ray " + i);
                    Assert.AreEqual(infoBase.rayFrac, info.rayFrac, 1e-10, "rayFrac diff on ray " + i);
                    Assert.AreEqual(infoBase.pos, info.pos, "pos diff on ray " + i);
                    Assert.AreEqual(infoBase.normal, info.normal, "normal diff on ray " + i);
                    Assert.AreEqual(infoBase.color, info.color, "color diff on ray " + i);
                }
            }
        }
        private ICollection <Triangle> BuildRandomTree(int numTriangles, int maxTreeDepth, int maxGeometryPerNode, int randomSeed, out SpatialSubdivision tree)
        {
            random = new Random(randomSeed);
            var triangles   = MakeRandomTriangles(numTriangles);
            var boundingBox = GetBoundingBoxOfRandomTriangles();

            tree = new SpatialSubdivision(triangles, boundingBox, maxTreeDepth, maxGeometryPerNode);
            Assert.IsNotNull(tree);
            return(triangles);
        }
        public void ConstructBalancedTree()
        {
            const int maxTreeDepth       = 3;
            const int maxGeometryPerNode = 1;

            random = new Random(12345);
            var triangles   = MakeRandomTriangles(8);
            var boundingBox = GetBoundingBoxOfRandomTriangles();
            var tree        = new SpatialSubdivision(triangles, boundingBox, maxTreeDepth, maxGeometryPerNode);

            Assert.IsNotNull(tree);
            Assert.AreEqual(3, tree.TreeDepth);
            Assert.AreEqual(5, tree.NumNodes);
            Assert.AreEqual(3, tree.NumLeafNodes);
            Assert.AreEqual(2, tree.NumInternalNodes);
        }
        public void CollectionsOfNullToConstructor_Error()
        {
            var obj = new SpatialSubdivision(new Triangle[] { null, null, null }, new AxisAlignedBox(new Vector(0, 0, 0), new Vector(1, 1, 1)));

            Assert.IsNotNull(obj);
        }
        public void EmptyInputToConstructor_NoError()
        {
            var obj = new SpatialSubdivision(new List <Triangle>(), new AxisAlignedBox(new Vector(), new Vector()));

            Assert.IsNotNull(obj);
        }
        public void NullBoundingBoxToConstructor_NoError()
        {
            var obj = new SpatialSubdivision(new List <Triangle>(), null);

            Assert.IsNotNull(obj);
        }