private static void Test( IReadOnlyList <Rectangle> initialRectangles, Rectangle boundingRectangle, Rectangle targetRectangle) { var expectedRectangles = new List <Rectangle>(); var otherRectangles = new List <Rectangle>(); var tree = new IntervalTree(boundingRectangle.YProjection); foreach (var initialRectangle in initialRectangles) { Assert.True(tree.Insert(initialRectangle)); if (initialRectangle.YProjection.Encloses(targetRectangle.YProjection) && targetRectangle.XProjection.Overlaps(initialRectangle.XProjection)) { expectedRectangles.Add(initialRectangle); } else { otherRectangles.Add(initialRectangle); } } TestAssert.Equal(expectedRectangles, tree.GetEnclosing(targetRectangle), $"Target: {targetRectangle}"); foreach (var rectangle in otherRectangles) { Assert.True(tree.Remove(rectangle)); } TestAssert.Equal(expectedRectangles, tree.GetEnclosing(targetRectangle), $"Target: {targetRectangle}"); foreach (var rectangle in expectedRectangles) { Assert.True(tree.Remove(rectangle)); } Assert.Empty(tree.GetEnclosing(targetRectangle)); tree.InsertRange(expectedRectangles); tree.InsertRange(otherRectangles); TestAssert.Equal(expectedRectangles, tree.GetEnclosing(targetRectangle), $"Target: {targetRectangle}"); }
public RectangleIntervalTree(Rectangle boundingRectangle) { _rectangleRangeTree = new RectangleRangeTree(); _xIntervalTree = new YBoundedIntervalTree(boundingRectangle.XProjection); _yIntervalTree = new IntervalTree(boundingRectangle.YProjection); }