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)); }
[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]); } } } } }
[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]); } } } } }
public void Clear_AllCellsEmpty() { var bin = new Bin3D <object>(9, 9, 9, 1, 1, 1); var results = new HashSet <object>(); var fullBounds = GetBoundsInsideCells(-1, -1, -1, bin.Width, bin.Height, bin.Depth, bin.CellWidth, bin.CellHeight, bin.CellDepth); bin.Retrieve(fullBounds, results); Assert.AreEqual(0, results.Count); }
public void Retrieve_Empty_NoResults() { var bin = new Bin3D <object>(9, 9, 9, 1, 1, 1); var rect = GetBoundsInsideCells(-1, -1, -1, bin.Width, bin.Height, bin.Depth, bin.CellWidth, bin.CellHeight, bin.CellDepth); var results = new HashSet <object>(); bin.Retrieve(rect, results); Assert.IsEmpty(results); }
public void Constructor_CorrectSize() { var bin = new Bin3D <string>(9, 18, 7, 1, 2, 3); Assert.AreEqual(9, bin.Width); Assert.AreEqual(18, bin.Height); Assert.AreEqual(7, bin.Depth); Assert.AreEqual(1, bin.CellWidth, 0.001f); Assert.AreEqual(2, bin.CellHeight, 0.001f); Assert.AreEqual(3, bin.CellDepth, 0.001f); }
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)); }
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)); }
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]); } } } }