Beispiel #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 YBoundedIntervalTree(boundingRectangle.XProjection);

            foreach (var initialRectangle in initialRectangles)
            {
                Assert.True(tree.Insert(initialRectangle));
                if (initialRectangle.XProjection.Encloses(targetRectangle.XProjection) &&
                    (targetRectangle.YProjection.Contains(initialRectangle.YProjection.Beginning) ||
                     targetRectangle.YProjection.Contains(initialRectangle.YProjection.End)))
                {
                    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 void InsertRange(IReadOnlyList <Rectangle> rectangles)
 {
     _rectangleRangeTree.InsertRange(rectangles);
     _xIntervalTree.InsertRange(rectangles);
     _yIntervalTree.InsertRange(rectangles);
 }