コード例 #1
0
        public void RTreeContainsTest()
        {
            Assert.IsFalse(_tree.Contains(null));
            Assert.IsFalse(_tree.Contains(_factory.CreatePoint(1000, 1000, 1000)));
            Assert.IsFalse(_tree.Contains(_factory.CreatePoint(Coordinate.Undefined)));

            foreach (IPoint geometry in _geometries)
            {
                Assert.IsTrue(_tree.Contains(geometry));
            }
        }
コード例 #2
0
        public void TestMultithreading()
        {
            var instance = new RTree <string>();

            Parallel.For(0, 100, i => {
                instance.Add(new Rectangle(0, 0, 0, 0, 0, 0), $"Origin-{Guid.NewGuid()}");
                instance.Add(new Rectangle(1, 1, 1, 1, 1, 1), $"Box1-{Guid.NewGuid()}");

                var rect_to_delete_name = $"Box 2-3-{Guid.NewGuid()}";
                instance.Add(new Rectangle(2, 2, 3, 3, 2, 3), rect_to_delete_name);
                instance.Add(new Rectangle(2, 2, 3, 3, 2, 3), $"Box 2-3-{Guid.NewGuid()}");

                var instancelist = instance.Contains(new Rectangle(-1, -1, 2, 2, -1, 2));
                Assert.IsTrue(instancelist.Count() > 0);

                var intersectlist = instance.Intersects(new Rectangle(3, 3, 5, 5, 3, 5));
                Assert.IsTrue(intersectlist.Count() > 1);
                Assert.IsTrue(intersectlist[0].StartsWith("Box 2-3"));

                var nearestlist = instance.Nearest(new Point(5, 5, 5), 10);

                Assert.IsTrue(nearestlist[0].StartsWith("Box 2-3"));

                instance.Delete(new Rectangle(2, 2, 3, 3, 2, 3), rect_to_delete_name);

                nearestlist = instance.Nearest(new Point(5, 5, 5), 10);

                Assert.IsTrue(nearestlist.Count() > 0);

                Assert.IsTrue(nearestlist[0].StartsWith("Box 2"));
            });
        }
コード例 #3
0
        public List <User> GetNearbyUsers(float longitude, float latitude,
                                          float maxDistance)
        {
            var        boundingBox  = GetBoundingBox(longitude, latitude, maxDistance);
            List <int> containedIds = _userMap.Contains(boundingBox);

            return(_userStore.GetUsers(containedIds));
        }
コード例 #4
0
        public void AddRailToRtree(Rail rail)
        {
            Point p0, p1;

            if (!rail.GetStartEnd(out p0, out p1))
            {
                return;
            }
            if (_railTree.Contains(new Rectangle(p0, p1), rail))
            {
                return;
            }
            _railTree.Add(new Rectangle(p0, p1), rail);
        }
コード例 #5
0
        /// <summary>
        /// Internally stores that a certain chunk has at least one item of the specified item ID.
        /// </summary>
        /// <param name="chunkLocation"></param>
        /// <param name="itemID"></param>
        internal static void RememberWhichChunk(Point2D chunkLocation, int itemID, int dimension)
        {
            RTree <Point2D> chunkLocations = World.Data.World.Dimensions[dimension].Items.ItemIDToChunk[itemID];
            List <Point2D>  result         = chunkLocations.Contains(new Rectangle(chunkLocation.X, chunkLocation.Y, chunkLocation.X, chunkLocation.Y));

            if (result.Count > 0)
            {
                //We already know that the specified chunk contains at least one of the item type.
                return;
            }
            else
            {
                chunkLocations.Add(new Rectangle(chunkLocation.X, chunkLocation.Y, chunkLocation.X, chunkLocation.Y), chunkLocation);
            }
        }
コード例 #6
0
        /// <summary>
        /// Lets a chunk know that there is an item of the specified type in the specified tile position.
        /// </summary>
        internal static void RememberWhichTile(Item item, Point2D mapLocation, Chunk chunk, int dimension)
        {
            if (!chunk.Items.ContainsKey(item.ItemID))
            {
                //chunk.Items doesn't store one key and value for every item in the game upfront.
                chunk.Items.Add(item.ItemID, new RTree <Point2D>());
            }

            RTree <Point2D> itemLocations = chunk.Items[item.ItemID];
            List <Point2D>  result        = itemLocations.Contains(new Rectangle(mapLocation.X, mapLocation.Y, mapLocation.X, mapLocation.Y));

            if (result.Count > 0)
            {
                //The chunk already knows that there is an item of the specified type in the specified position.
            }
            else
            {
                itemLocations.Add(new Rectangle(mapLocation.X, mapLocation.Y, mapLocation.X, mapLocation.Y), WorldUtil.GetTile(mapLocation, chunk).MapLocation);
            }
        }
コード例 #7
0
        private void runDeleteAllEntries(int minNodeEntries, int maxNodeEntries, int numRects)
        {
            RTree rtree = new RTree(minNodeEntries, maxNodeEntries);

            for (int i = 0; i <= numRects; i += 100)
            {
                // add some entries
                for (int j = 0; j < i; j++)
                {
                    rtree.Add(rects[j]);
                }
                Assert.True(rtree.checkConsistency());

                // now delete them all
                for (int j = 0; j < i; j++)
                {
                    rtree.Remove(rects[j]);
                }
                Assert.True(rtree.Count == 0);
                Assert.True(rtree.checkConsistency());

                // check that we can make queries on an empty rtree without error.
                Rectangle testRect  = new Rectangle(1, 2, 3, 4);
                Point     testPoint = new Point(1, 2);

                Counter counter = new Counter();
                rtree.Intersects(testRect, counter.execute);
                Assert.True(counter.count == 0);

                PriorityQueueRTree priorityQue = rtree.Nearest(testPoint, float.MaxValue);
                Assert.True(priorityQue.Count == 0);

                priorityQue = rtree.NearestN(testPoint, 10, float.MaxValue);
                Assert.True(priorityQue.Count == 0);

                rtree.Contains(testRect, counter.execute);
                Assert.True(counter.count == 0);
            }
        }
コード例 #8
0
        /// <summary>
        /// Lets a chunk know that there is an item of the specified type in the specified tile position.
        /// </summary>
        private static void RememberWhichTile(Item item, Point2D mapLocation, Chunk chunk)
        {
            if (!chunk.Items.ContainsKey(item.ItemID))
            {
                //chunk.Items doesn't store one key and value for every item in the game upfront.
                chunk.Items.Add(item.ItemID, new RTree <Point2D>());
            }

            RTree <Point2D> itemLocations = chunk.Items[item.ItemID];
            List <Point2D>  result        = itemLocations.Contains(new Rectangle(mapLocation.X, mapLocation.Y, mapLocation.X, mapLocation.Y));

            if (result.Count > 0)
            {
                //The chunk already knows that there is an item of the specified type in the specified position.
            }
            else
            {
                Rectangle           r          = new Rectangle(mapLocation.X, mapLocation.Y, mapLocation.X, mapLocation.Y);
                Tile                tile       = WorldUtil.GetTile(mapLocation, chunk);
                ComponentSelectable selectable = tile.GetExactComponent <ComponentSelectable>();

                itemLocations.Add(r, selectable.MapLocation);
            }
        }
コード例 #9
0
        static void Main(string[] args)
        {
            RTree <Node> tree  = new RTree <Node>(2, 4);
            Node         node1 = new Node()
            {
                x = 1, y = 1
            };
            Rectangle reactangle1 = new Rectangle(node1.x, node1.y, node1.x, node1.y, 0, 0);

            tree.Add(reactangle1, node1);
            Node node2 = new Node()
            {
                x = 4, y = 3
            };
            Rectangle reactangle2 = new Rectangle(node2.x, node2.y, node2.x, node2.y, 0, 0);

            tree.Add(reactangle2, node2);
            Node node3 = new Node()
            {
                x = 2, y = 9
            };
            Rectangle reactangle3 = new Rectangle(node3.x, node3.y, node3.x, node3.y, 0, 0);

            tree.Add(reactangle3, node3);
            Node node4 = new Node()
            {
                x = 5, y = 7
            };
            Rectangle reactangle4 = new Rectangle(node4.x, node4.y, node4.x, node4.y, 0, 0);

            tree.Add(reactangle4, node4);
            Node node5 = new Node()
            {
                x = 6, y = 10
            };
            Rectangle reactangle5 = new Rectangle(node5.x, node5.y, node5.x, node5.y, 0, 0);

            tree.Add(reactangle5, node5);
            Node node6 = new Node()
            {
                x = 7, y = 6
            };
            Rectangle reactangle6 = new Rectangle(node6.x, node6.y, node6.x, node6.y, 0, 0);

            tree.Add(reactangle6, node6);
            Node node7 = new Node()
            {
                x = 9, y = 11
            };
            Rectangle reactangle7 = new Rectangle(node7.x, node7.y, node7.x, node7.y, 0, 0);

            tree.Add(reactangle7, node7);
            Node node8 = new Node()
            {
                x = 6, y = 2
            };
            Rectangle reactangle8 = new Rectangle(node8.x, node8.y, node8.x, node8.y, 0, 0);

            Console.WriteLine("测试开始:");
            Console.WriteLine("测试Contains函数:");
            Console.Write("判断是否存在区域<2,9>:");
            List <Node> resultOfContains1 = tree.Contains(reactangle3);

            foreach (Node node in resultOfContains1)
            {
                Console.Write("<" + node.x + "," + node.y + "> ");
            }
            Console.WriteLine();
            Console.Write("判断是否存在区域8:");
            List <Node> resultOfContains2 = tree.Contains(reactangle8);

            foreach (Node node in resultOfContains2)
            {
                Console.Write("<" + node.x + "," + node.y + "> ");
            }
            Console.WriteLine();
            Console.WriteLine("测试Count值:" + tree.Count);
            Console.WriteLine("测试getBounds函数:" + tree.getBounds().ToString());
            Console.Write("测试Intersect函数:");
            List <Node> resultOfIntersect = tree.Intersects(new Rectangle((float)4.5, 5, 7, 12, 0, 0));

            foreach (Node node in resultOfIntersect)
            {
                Console.Write("<" + node.x + "," + node.y + "> ");
            }
            Console.WriteLine();
            Console.Write("测试Nearest函数:");
            List <Node> resultOfNearset = tree.Nearest(new Point(2, 4, 0), 1000);

            foreach (Node node in resultOfNearset)
            {
                Console.Write("<" + node.x + "," + node.y + "> ");
            }
            Console.WriteLine();
            Console.WriteLine("测试GetMBRs函数:");
            List <Rectangle> rectangleList = tree.GetMBRs();

            foreach (Rectangle rectangle in rectangleList)
            {
                Console.WriteLine("MBR[" + rectangle.ToString() + "], ");
            }
            Console.WriteLine("测试结束!");
        }
コード例 #10
0
 /// <summary>
 /// Returns a list of features that contains the specified rectangle.
 /// </summary>
 /// <param name="r">The r.</param>
 /// <returns></returns>
 public FdoFeature[] Contains(Rectangle r)
 {
     return(_tree.Contains(r).ToArray());
 }