/// <summary> /// Removes redundant points. Two points are redundant if they occupy the same hash grid cell. /// </summary> /// <param name="points">List of points to prune.</param> /// <param name="cellSize">Size of cells to determine redundancy.</param> public static void RemoveRedundantPoints(ref QuickList<Vector3> points, double cellSize) { var set = new QuickSet<Int3>(BufferPools<Int3>.Locking, BufferPools<int>.Locking, BufferPool.GetPoolIndex(points.Count)); for (int i = points.Count - 1; i >= 0; --i) { var element = points.Elements[i]; var cell = new Int3 { X = (int)Math.Floor(element.X / cellSize), Y = (int)Math.Floor(element.Y / cellSize), Z = (int)Math.Floor(element.Z / cellSize) }; if (set.Contains(cell)) { points.FastRemoveAt(i); } else { set.Add(cell); //TODO: Consider adding adjacent cells to guarantee that a point on the border between two cells will still detect the presence //of a point on the opposite side of that border. } } set.Dispose(); }
/// <summary> /// Removes redundant points. Two points are redundant if they occupy the same hash grid cell. /// </summary> /// <param name="points">List of points to prune.</param> /// <param name="cellSize">Size of cells to determine redundancy.</param> public static void RemoveRedundantPoints(ref QuickList <Vector3> points, double cellSize) { var set = new QuickSet <Int3>(BufferPools <Int3> .Locking, BufferPools <int> .Locking, BufferPool.GetPoolIndex(points.Count)); for (int i = points.Count - 1; i >= 0; --i) { var element = points.Elements[i]; var cell = new Int3 { X = (int)Math.Floor(element.X / cellSize), Y = (int)Math.Floor(element.Y / cellSize), Z = (int)Math.Floor(element.Z / cellSize) }; if (set.Contains(cell)) { points.FastRemoveAt(i); } else { set.Add(cell); //TODO: Consider adding adjacent cells to guarantee that a point on the border between two cells will still detect the presence //of a point on the opposite side of that border. } } set.Dispose(); }
public static void TestSetResizing(IUnmanagedMemoryPool pool) { Random random = new Random(5); var set = new QuickSet <int, PrimitiveComparer <int> >(4, pool); HashSet <int> controlSet = new HashSet <int>(); for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex) { if (random.NextDouble() < 0.7) { set.Add(iterationIndex, pool); controlSet.Add(iterationIndex); } if (random.NextDouble() < 0.2) { var indexToRemove = random.Next(set.Count); var toRemove = set[indexToRemove]; set.FastRemove(toRemove); controlSet.Remove(toRemove); } if (iterationIndex % 1000 == 0) { set.EnsureCapacity(set.Count * 3, pool); } else if (iterationIndex % 7777 == 0) { set.Compact(pool); } } Debug.Assert(set.Count == controlSet.Count); for (int i = 0; i < set.Count; ++i) { Debug.Assert(controlSet.Contains(set[i])); } foreach (var element in controlSet) { Debug.Assert(set.Contains(element)); } set.Dispose(pool); }
public static void TestSetResizing() { Random random = new Random(5); UnsafeBufferPool <int> pool = new UnsafeBufferPool <int>(); QuickSet <int> set = new QuickSet <int>(pool, pool); HashSet <int> controlSet = new HashSet <int>(); for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex) { if (random.NextDouble() < 0.7) { set.Add(iterationIndex); controlSet.Add(iterationIndex); } if (random.NextDouble() < 0.2) { var indexToRemove = random.Next(set.Count); var toRemove = set[indexToRemove]; set.FastRemove(toRemove); controlSet.Remove(toRemove); } if (iterationIndex % 1000 == 0) { set.EnsureCapacity(set.Count * 3); } else if (iterationIndex % 7777 == 0) { set.Compact(); } } Assert.IsTrue(set.Count == controlSet.Count); for (int i = 0; i < set.Count; ++i) { Assert.IsTrue(controlSet.Contains(set[i])); } foreach (var element in controlSet) { Assert.IsTrue(set.Contains(element)); } }
public static void TestSetResizing() { Random random = new Random(5); UnsafeBufferPool<int> pool = new UnsafeBufferPool<int>(); QuickSet<int> set = new QuickSet<int>(pool, pool); HashSet<int> controlSet = new HashSet<int>(); for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex) { if (random.NextDouble() < 0.7) { set.Add(iterationIndex); controlSet.Add(iterationIndex); } if (random.NextDouble() < 0.2) { var indexToRemove = random.Next(set.Count); var toRemove = set[indexToRemove]; set.FastRemove(toRemove); controlSet.Remove(toRemove); } if (iterationIndex % 1000 == 0) { set.EnsureCapacity(set.Count * 3); } else if (iterationIndex % 7777 == 0) { set.Compact(); } } Assert.IsTrue(set.Count == controlSet.Count); for (int i = 0; i < set.Count; ++i) { Assert.IsTrue(controlSet.Contains(set[i])); } foreach (var element in controlSet) { Assert.IsTrue(set.Contains(element)); } }