public void QuadrantsJoinWhenAtLowCapacity() { ConcurrentGeoQuadtree <object> quadtree = new ConcurrentGeoQuadtree <object>(1, 10, 25); List <ConcurrentGeoQuadtree <object> .IElement> elements = new List <ConcurrentGeoQuadtree <object> .IElement>(); for (int i = 0; i < 20; ++i) { elements.Add(quadtree.InsertElement(null, new GeoCoordinates(0, 0))); } Assert.Equal(0, quadtree.GetLargestSubdivisionLevel()); quadtree.EfficientlyReindex(); int prevSubdivLevel = quadtree.GetLargestSubdivisionLevel(); Assert.True(prevSubdivLevel >= 1); foreach (var element in elements) { quadtree.RemoveElement(element); } quadtree.EfficientlyReindex(); Assert.True(quadtree.GetLargestSubdivisionLevel() < prevSubdivLevel); }
public void QuadrantDoesntJoinIfWouldBeAboveCapacity() { ConcurrentGeoQuadtree <object> quadtree = new ConcurrentGeoQuadtree <object>(2, 10, 25); List <ConcurrentGeoQuadtree <object> .IElement> elements = new List <ConcurrentGeoQuadtree <object> .IElement>(); for (int i = 0; i < 10; ++i) { elements.Add(quadtree.InsertElement(null, new GeoCoordinates(1, 1))); } for (int i = 0; i < 10; ++i) { quadtree.InsertElement(null, new GeoCoordinates(-1, -1)); } quadtree.EfficientlyReindex(); Assert.True(quadtree.GetLargestSubdivisionLevel() >= 1); // Remove all but one element from the top-right quadrant but not the // bottom-left quadrant. foreach (var element in elements.Take(9)) { quadtree.RemoveElement(element); } quadtree.EfficientlyReindex(); Assert.True(quadtree.GetLargestSubdivisionLevel() >= 1); }
public void CannotMoveRemovedElement() { ConcurrentGeoQuadtree <object> quadtree = new ConcurrentGeoQuadtree <object>(); var element = quadtree.InsertElement(null, new GeoCoordinates(0, 0)); quadtree.RemoveElement(element); Assert.False(quadtree.MoveElement(element, new GeoCoordinates(1, 1))); }