Ejemplo n.º 1
0
        public void Insert_InsideCell_CorrectCell(int expectedX, int expectedY, int expectedZ)
        {
            var bin = new Bin3D <object>(9, 9, 9, 1, 1, 1);
            var val = new object();

            bin.Insert(val, GetBoundsInsideCell(expectedX, expectedY, expectedZ, 1, 1, 1));

            for (var x = 0; x < bin.Width; x++)
            {
                for (var y = 0; y < bin.Height; y++)
                {
                    for (var z = 0; z < bin.Depth; z++)
                    {
                        if (x == expectedX && y == expectedY)
                        {
                            continue;
                        }

                        Assert.IsNull(bin[x, y, z]);
                    }
                }
            }

            Assert.IsNotNull(bin[expectedX, expectedY, expectedZ]);
            Assert.IsTrue(bin[expectedX, expectedY, expectedZ].Contains(val));
        }
Ejemplo n.º 2
0
        [TestCase(-1, -1, -1, -1, -1, -1)] // out of bounds
        public void Insert_Overlap_CorrectCells(int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
        {
            var bin = new Bin3D <object>(9, 9, 9, 1, 1, 1);
            var val = new object();

            var rect = GetBoundsInsideCells(minX, minY, minZ, maxX, maxY, maxZ, 1, 1, 1);

            bin.Insert(val, rect);

            for (var x = 0; x < bin.Width; x++)
            {
                for (var y = 0; y < bin.Height; y++)
                {
                    for (var z = 0; z < bin.Depth; z++)
                    {
                        if (x >= minX && y >= minY && z >= minZ &&
                            x <= maxX && y <= maxY && z <= maxZ)
                        {
                            Assert.IsNotNull(bin[x, y, z]);
                            Assert.IsTrue(bin[x, y, z].Contains(val));
                        }
                        else
                        {
                            Assert.IsNull(bin[x, y, z]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        [TestCase(-1, -1, -1, -1, -1, -1)] // out of bounds
        public void Insert_WithOffsetOrigin_CorrectCells(int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
        {
            var origin = new Vector3(-4.5f, -4.5f, -4.5f);

            var bin = new Bin3D <object>(9, 9, 9, 1, 1, 1, origin);
            var val = new object();

            var bounds = GetBoundsInsideCells(minX, minY, minZ, maxX, maxY, maxZ, 1, 1, 1);

            bounds.center += origin;

            bin.Insert(val, bounds);

            for (var x = 0; x < bin.Width; x++)
            {
                for (var y = 0; y < bin.Height; y++)
                {
                    for (var z = 0; z < bin.Depth; z++)
                    {
                        if (x >= minX && y >= minY && z >= minZ &&
                            x <= maxX && y <= maxY && z <= maxZ)
                        {
                            Assert.IsNotNull(bin[x, y, z]);
                            Assert.IsTrue(bin[x, y, z].Contains(val));
                        }
                        else
                        {
                            Assert.IsNull(bin[x, y, z]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void Retrieve_CorrectResults(int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
        {
            var bin     = new Bin3D <object>(9, 9, 9, 1, 1, 1);
            var results = new HashSet <object>();
            var val     = new object();
            var bounds  = GetBoundsInsideCells(minX, minY, minZ, maxX, maxY, maxZ, bin.CellWidth, bin.CellHeight, bin.CellDepth);

            bin.Insert(val, bounds);
            bin.Retrieve(bounds, results);

            Assert.True(results.Contains(val));
        }
Ejemplo n.º 5
0
        public void Remove_RemovedFromCells()
        {
            var bin     = new Bin3D <object>(9, 9, 9, 1, 1, 1);
            var results = new HashSet <object>();
            var val     = new object();
            var bounds  = GetBoundsInsideCells(3, 6, 4, 7, 8, 6, bin.CellWidth, bin.CellHeight, bin.CellDepth);

            bin.Insert(val, bounds);
            bin.Remove(val, bounds);
            bin.Retrieve(bounds, results);

            Assert.False(results.Contains(val));
        }
Ejemplo n.º 6
0
        public void Insert_OutOfBounds_NotAdded(int cellX, int cellY, int cellZ)
        {
            var bin = new Bin3D <object>(9, 9, 9, 1, 1, 1);
            var val = new object();

            bin.Insert(val, GetBoundsInsideCell(cellX, cellY, cellZ, 1, 1, 1));

            for (var x = 0; x < bin.Width; x++)
            {
                for (var y = 0; y < bin.Height; y++)
                {
                    for (var z = 0; z < bin.Depth; z++)
                    {
                        Assert.IsNull(bin[x, y, z]);
                    }
                }
            }
        }