예제 #1
0
        public void RTree_Range_Search_Test()
        {
            var nodeCount      = 1000;
            var randomPolygons = new HashSet <Polygon>();

            for (int i = 0; i < nodeCount; i++)
            {
                randomPolygons.Add(getRandomPointOrPolygon());
            }
            var order = 5;
            var tree  = new RTree(order);

            foreach (var polygon in randomPolygons)
            {
                tree.Insert(polygon);
            }

            //IEnumerable test
            Assert.AreEqual(tree.Count, tree.Count());

            var searchRectangle = getRandomPointOrPolygon().GetContainingRectangle();

            var expectedIntersections = randomPolygons.Where(x => RectangleIntersection.FindIntersection(searchRectangle, x.GetContainingRectangle()) != null).ToList();
            var actualIntersections   = tree.RangeSearch(searchRectangle);

            Assert.AreEqual(expectedIntersections.Count, actualIntersections.Count);
        }
        public void RectIntersection_Smoke_Test()
        {
            var result = RectangleIntersection.FindIntersection(new Rectangle()
            {
                LeftTopCorner     = new Point(0, 10),
                RightBottomCorner = new Point(10, 0)
            },
                                                                new Rectangle()
            {
                LeftTopCorner     = new Point(5, 5),
                RightBottomCorner = new Point(15, 0)
            });

            Assert.AreEqual(result, new Rectangle()
            {
                LeftTopCorner     = new Point(5, 5),
                RightBottomCorner = new Point(10, 0)
            });

            result = RectangleIntersection.FindIntersection(new Rectangle()
            {
                LeftTopCorner     = new Point(0, 10),
                RightBottomCorner = new Point(4, 0)
            },
                                                            new Rectangle()
            {
                LeftTopCorner     = new Point(5, 5),
                RightBottomCorner = new Point(15, 0)
            });

            Assert.AreEqual(result, null);
        }
        public void RectIntersection_Smoke_Test()
        {
            var rectangleComparer = new RectangleComparer();

            var result = RectangleIntersection.FindIntersection(new Rectangle()
            {
                LeftTopCorner     = new Point(0, 10),
                RightBottomCorner = new Point(10, 0)
            },
                                                                new Rectangle()
            {
                LeftTopCorner     = new Point(5, 5),
                RightBottomCorner = new Point(15, 0)
            });

            Assert.IsTrue(rectangleComparer.Equals(result, new Rectangle()
            {
                LeftTopCorner     = new Point(5, 5),
                RightBottomCorner = new Point(10, 0)
            }));

            result = RectangleIntersection.FindIntersection(new Rectangle()
            {
                LeftTopCorner     = new Point(0, 10),
                RightBottomCorner = new Point(4, 0)
            },
                                                            new Rectangle()
            {
                LeftTopCorner     = new Point(5, 5),
                RightBottomCorner = new Point(15, 0)
            });

            Assert.IsTrue(rectangleComparer.Equals(result, null));
        }
        public void RectIntersection_Smoke_Test()
        {
            var result = RectangleIntersection.FindIntersection(new Rectangle()
            {
                LeftTopCorner = new Point()
                {
                    x = 0, y = 10
                },
                RightBottomCorner = new Point()
                {
                    x = 10, y = 0
                }
            },
                                                                new Rectangle()
            {
                LeftTopCorner = new Point()
                {
                    x = 5, y = 5
                },
                RightBottomCorner = new Point()
                {
                    x = 15, y = 0
                }
            });

            Assert.AreEqual(result, new Rectangle()
            {
                LeftTopCorner = new Point()
                {
                    x = 5, y = 5
                },
                RightBottomCorner = new Point()
                {
                    x = 10, y = 0
                }
            });

            result = RectangleIntersection.FindIntersection(new Rectangle()
            {
                LeftTopCorner = new Point()
                {
                    x = 0, y = 10
                },
                RightBottomCorner = new Point()
                {
                    x = 4, y = 0
                }
            },
                                                            new Rectangle()
            {
                LeftTopCorner = new Point()
                {
                    x = 5, y = 5
                },
                RightBottomCorner = new Point()
                {
                    x = 15, y = 0
                }
            });

            Assert.AreEqual(result, default(Rectangle));
        }