Example #1
0
        private static void Test(
            IReadOnlyList <Rectangle> initialRectangles, Rectangle boundingRectangle, Rectangle targetRectangle)
        {
            var expectedRectangles = new List <Rectangle>();
            var otherRectangles    = new List <Rectangle>();
            var tree = new RectangleRangeTree();

            foreach (var initialRectangle in initialRectangles)
            {
                Assert.True(tree.Insert(initialRectangle));
                if (targetRectangle.Contains(initialRectangle.TopLeft) ||
                    targetRectangle.Contains(initialRectangle.BottomLeft) ||
                    targetRectangle.Contains(initialRectangle.TopRight) ||
                    targetRectangle.Contains(initialRectangle.BottomRight))
                {
                    expectedRectangles.Add(initialRectangle);
                }
                else
                {
                    otherRectangles.Add(initialRectangle);
                }
            }

            TestAssert.Equal(expectedRectangles, tree.GetOverlappingCorners(targetRectangle),
                             $"Target: {targetRectangle}");

            foreach (var rectangle in otherRectangles)
            {
                Assert.True(tree.Remove(rectangle));
            }

            TestAssert.Equal(expectedRectangles, tree.GetOverlappingCorners(targetRectangle),
                             $"Target: {targetRectangle}");

            foreach (var rectangle in expectedRectangles)
            {
                Assert.True(tree.Remove(rectangle));
            }

            Assert.Empty(tree.GetOverlappingCorners(targetRectangle));

            tree.InsertRange(expectedRectangles);
            tree.InsertRange(otherRectangles);

            TestAssert.Equal(expectedRectangles, tree.GetOverlappingCorners(targetRectangle),
                             $"Target: {targetRectangle}");
        }
 public bool Insert(Rectangle rectangle) => _rectangleRangeTree.Insert(rectangle) &&
 _xIntervalTree.Insert(rectangle) && _yIntervalTree.Insert(rectangle);