当前位置: 首页>>代码示例>>C#>>正文


C# QuadTree.Query方法代码示例

本文整理汇总了C#中QuadTree.Query方法的典型用法代码示例。如果您正苦于以下问题:C# QuadTree.Query方法的具体用法?C# QuadTree.Query怎么用?C# QuadTree.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QuadTree的用法示例。


在下文中一共展示了QuadTree.Query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test1000ItemsWithQuery

        public void Test1000ItemsWithQuery()
        {
            Random rand = new Random ();
            var bounds = new RectangleF (0f,0f,100f,100f);
            QuadTree<RectangleF> tree = new QuadTree<RectangleF>(bounds) {
                GetRect = r => r
            };

            //add 10 items, assert no subnodes.
            for (int i = 0; i < 1000; i++)
            {
                var rect = new RectangleF ( rand.Next (0, 80), rand.Next (0, 80), rand.Next (1, 10), rand.Next (1, 10));
                tree.Insert (rect);
            }

            //insert a rect at 25, 25, 5, 5, and query for it.

            var searchRect = new RectangleF (25f, 25f, 5f, 5f);
            tree.Insert (searchRect);

            //now try and find it.

            bool found = false;
            int count = 0;
            foreach (var rect in tree.Query (new RectangleF (20f, 20f, 10f, 10f)))
            {
                count++;
                Console.WriteLine (rect);
                if (rect == searchRect)
                {
                    found = true;
                    break;
                }
            }

            Console.WriteLine ("count: " + count);

            Assert.That (found, Is.True);
        }
开发者ID:bennidhamma,项目名称:SimpleQuadTree,代码行数:39,代码来源:Tests.cs

示例2: ResolveAll

        public static void ResolveAll(List<IRigidBody> bodies, List<IRigidBody> mapbodies, QuadTree<IRigidBody> QTbodies, QuadTree<IRigidBody> QTmap)
        {
            var collisionData = new ConcurrentBag<CollisionData>();

            //foreach (var b in bodies)
            bodies.AsParallel().ForAll(b =>
            {
                var potHits = QTbodies.Query(b.BoundingBox); //broad-phase
                potHits.Remove(b); //the body itself will be included in query results.
                potHits.AddRange(QTmap.Query(b.BoundingBox));

                if (potHits.Count > 0)
                {
                    var allCollData = TestAndGetAllCollisionData(b, potHits); //narrow-phase

                    if (allCollData.Count > 0)
                    {
                        CollisionData aggrColData = AggrCollisionData(allCollData);
                        collisionData.Add(aggrColData);
                    }
                }
            });

            foreach (var cd in collisionData) ApplyCollisionData(cd); //apply all aggregated collision responses.
        }
开发者ID:tylermenezes,项目名称:ROIDS,代码行数:25,代码来源:CollisionEngine.cs

示例3: TestInsertSplitting

    public void TestInsertSplitting() {
      QuadTree<TestItem> quadTree = new QuadTree<TestItem>(
        new BoundingRectangle(-100.0f, -100.0f, 100.0f, 100.0f)
      );
      quadTree.MaxItemsPerNode = 6;

      TestItem[] items = new TestItem[] {
        // Unsplittable node to test FirstSplittableItemIndex
        new TestItem(new BoundingRectangle(-10.0f, -10.0f, 10.0f, 10.0f)),
        // Four corners
        new TestItem(new BoundingRectangle(-90.0f, -90.0f, -10.0f, -10.0f)),
        new TestItem(new BoundingRectangle(10.0f, -90.0f, 90.0f, -10.0f)),
        new TestItem(new BoundingRectangle(-90.0f, 10.0f, -10.0f, 90.0f)),
        new TestItem(new BoundingRectangle(10.0f, 10.0f, 90.0f, 90.0f)),
        // Unsplittable node to test split skipping
        new TestItem(new BoundingRectangle(-15.0f, -15.0f, 15.0f, 15.0f)),
        // Causes the node to split
        new TestItem(new BoundingRectangle(-90.0f, -90.0f, 90.0f, 90.0f)),
        // To test insertion into child nodes
        new TestItem(new BoundingRectangle(-5.0f, -5.0f, 5.0f, 5.0f)),
        new TestItem(new BoundingRectangle(-90.0f, -90.0f, -85.0f, -85.0f)),
        new TestItem(new BoundingRectangle(85.0f, -90.0f, 90.0f, -85.0f)),
        new TestItem(new BoundingRectangle(-90.0f, 85.0f, -85.0f, 90.0f)),
        new TestItem(new BoundingRectangle(85.0f, 85.0f, 90.0f, 90.0f))
      };
      foreach(TestItem item in items) {
        quadTree.Insert(item);
      }

      // Remember the current bounding rectangle lookups for the items which
      // should be situated in other quad-tree nodes by now
      int lookupCount2 = items[2].BoundRectangleLookups;
      int lookupCount3 = items[3].BoundRectangleLookups;
      int lookupCount4 = items[4].BoundRectangleLookups;

      // Perform the query
      List<TestItem> result = new List<TestItem>();
      quadTree.Query(new BoundingRectangle(-80.0f, -80.0f, -20.0f, -20.0f), result);

      // Make sure that the quad-tree didn't check the items that should have
      // been placed into other nodes
      Assert.AreEqual(lookupCount2, items[2].BoundRectangleLookups);
      Assert.AreEqual(lookupCount3, items[3].BoundRectangleLookups);
      Assert.AreEqual(lookupCount4, items[4].BoundRectangleLookups);

      // Make sure the query results are correct
      Assert.AreEqual(2, result.Count);
      Assert.Contains(items[1], result);
      Assert.Contains(items[6], result);
    }
开发者ID:pr0gramm3r1,项目名称:AngryTanks,代码行数:50,代码来源:QuadTree.Test.cs

示例4: TestQueryEntireNodes

    public void TestQueryEntireNodes() {
      QuadTree<TestItem> quadTree = new QuadTree<TestItem>(
        new BoundingRectangle(-100.0f, -100.0f, 100.0f, 100.0f)
      );
      quadTree.MaxItemsPerNode = 2;

      TestItem[] items = new TestItem[] {
        new TestItem(new BoundingRectangle(-30.0f, -30.0f, -29.9f, -29.9f)), // 0: tl-a
        new TestItem(new BoundingRectangle(-20.0f, -20.0f, -19.9f, -19.9f)), // 1: tl-b
        new TestItem(new BoundingRectangle(-10.0f, -10.0f, -9.9f, -9.9f)),   // 2: tl-c

        new TestItem(new BoundingRectangle(30.0f, -30.0f, 30.1f, -29.9f)),   // 3: tr-a
        new TestItem(new BoundingRectangle(20.0f, -20.0f, 20.1f, -19.9f)),   // 4: tr-b
        new TestItem(new BoundingRectangle(10.0f, -10.0f, 10.1f, -9.9f)),    // 5: tr-c

        new TestItem(new BoundingRectangle(-30.0f, 30.0f, -29.9f, 30.1f)),   // 6: br-a
        new TestItem(new BoundingRectangle(-20.0f, 20.0f, -19.9f, 20.1f)),   // 7: bl-b
        new TestItem(new BoundingRectangle(-10.0f, 10.0f, -9.9f, 10.1f)),    // 8: bl-c

        new TestItem(new BoundingRectangle(30.0f, 30.0f, 30.1f, 30.1f)),     // 9: br-a
        new TestItem(new BoundingRectangle(20.0f, 20.0f, 20.1f, 20.1f)),     // 10: br-b
        new TestItem(new BoundingRectangle(10.0f, 10.0f, 10.1f, 10.1f)),     // 11: br-c

        new TestItem(new BoundingRectangle(21.0f, 21.0f, 21.1f, 21.1f)),     // 12: c-a
        new TestItem(new BoundingRectangle(22.0f, 22.0f, 22.1f, 22.1f)),     // 13: c-b
        new TestItem(new BoundingRectangle(23.0f, 23.0f, 23.1f, 23.1f))      // 14: c-c
      };
      foreach(TestItem item in items) {
        quadTree.Insert(item);
      }

      // Perform some queries that would cause a normal quadtree to query all of
      // the contained items (because they're all outside the bounds of the tree)
      List<TestItem> result = new List<TestItem>();

      quadTree.Query(new BoundingRectangle(-60.0f, -60.0f, -15.0f, -15.0f), result);
      quadTree.Query(new BoundingRectangle(15.0f, -60.0f, 60.0f, -15.0f), result);
      quadTree.Query(new BoundingRectangle(-60.0f, 15.0f, -15.0f, 60.0f), result);
      quadTree.Query(new BoundingRectangle(15.0f, 15.0f, 60.0f, 60.0f), result);
    }
开发者ID:pr0gramm3r1,项目名称:AngryTanks,代码行数:40,代码来源:QuadTree.Test.cs

示例5: TestQueryExternalItems

    public void TestQueryExternalItems() {
      QuadTree<TestItem> quadTree = new QuadTree<TestItem>(
        new BoundingRectangle(-100.0f, -100.0f, 100.0f, 100.0f)
      );
      quadTree.MaxItemsPerNode = 2;

      TestItem[] items = new TestItem[] {
        new TestItem(new BoundingRectangle(-90.0f, -110.0f, -89.9f, -109.9f)), // 0: u1
        new TestItem(new BoundingRectangle(-80.0f, -110.0f, -79.9f, -109.9f)), // 1: u2
        new TestItem(new BoundingRectangle(80.0f, -110.0f, 80.1f, -109.9f)),   // 2: u3
        new TestItem(new BoundingRectangle(90.0f, -110.0f, 90.1f, -109.9f)),   // 3: u4
        new TestItem(new BoundingRectangle(-110.0f, -90.0f, -109.9f, -89.9f)), // 4: l1
        new TestItem(new BoundingRectangle(-110.0f, -80.0f, -109.9f, -79.9f)), // 5: l2
        new TestItem(new BoundingRectangle(-110.0f, 80.0f, -109.9f, 80.1f)),   // 6: l3
        new TestItem(new BoundingRectangle(-110.0f, 90.0f, -109.9f, 90.1f)),   // 7: l4
        new TestItem(new BoundingRectangle(-90.0f, 110.0f, -89.9f, 110.1f)),   // 8: b1
        new TestItem(new BoundingRectangle(-80.0f, 110.0f, -79.9f, 110.1f)),   // 9: b2
        new TestItem(new BoundingRectangle(80.0f, 110.0f, 80.1f, 110.1f)),     // 10: b3
        new TestItem(new BoundingRectangle(90.0f, 110.0f, 90.1f, 110.1f)),     // 11: b4
        new TestItem(new BoundingRectangle(110.0f, -90.0f, 110.1f, -89.9f)),   // 12: r1
        new TestItem(new BoundingRectangle(110.0f, -80.0f, 110.1f, -79.9f)),   // 13: r2
        new TestItem(new BoundingRectangle(110.0f, 80.0f, 110.1f, 80.1f)),     // 14: r3
        new TestItem(new BoundingRectangle(110.0f, 90.0f, 110.1f, 90.1f))      // 15: r4
      };
      foreach(TestItem item in items) {
        quadTree.Insert(item);
      }

      List<TestItem> result = new List<TestItem>();

      //
      // Perform some queries that would cause a normal quadtree to query all of
      // the contained items (because they're all outside the bounds of the tree)
      //

      // Upper left
      int lookupCount2 = items[2].BoundRectangleLookups;
      int lookupCount6 = items[6].BoundRectangleLookups;
      quadTree.Query(new BoundingRectangle(-95.0f, -95.0f, -85.0f, -85.0f), result);
      Assert.AreEqual(lookupCount2, items[2].BoundRectangleLookups);
      Assert.AreEqual(lookupCount6, items[6].BoundRectangleLookups);

      // Upper right
      int lookupCount1 = items[1].BoundRectangleLookups;
      int lookupCount14 = items[14].BoundRectangleLookups;
      quadTree.Query(new BoundingRectangle(85.0f, -95.0f, 95.0f, -85.0f), result);
      Assert.AreEqual(lookupCount1, items[1].BoundRectangleLookups);
      Assert.AreEqual(lookupCount14, items[14].BoundRectangleLookups);

      // Lower left      
      int lookupCount5 = items[5].BoundRectangleLookups;
      int lookupCount10 = items[10].BoundRectangleLookups;
      quadTree.Query(new BoundingRectangle(-95.0f, 85.0f, -85.0f, 95.0f), result);
      Assert.AreEqual(lookupCount5, items[5].BoundRectangleLookups);
      Assert.AreEqual(lookupCount10, items[10].BoundRectangleLookups);

      // Lower right
      int lookupCount9 = items[9].BoundRectangleLookups;
      int lookupCount13 = items[13].BoundRectangleLookups;
      quadTree.Query(new BoundingRectangle(85.0f, 85.0f, 95.0f, 95.0f), result);
      Assert.AreEqual(lookupCount9, items[9].BoundRectangleLookups);
      Assert.AreEqual(lookupCount13, items[13].BoundRectangleLookups);
    }
开发者ID:pr0gramm3r1,项目名称:AngryTanks,代码行数:63,代码来源:QuadTree.Test.cs

示例6: TestOnRandomPlaces

        private static void TestOnRandomPlaces(QuadTree<byte> Qtree, string[] CountryNames)
        {
            // Oxford (UK)
            var countryResult = Qtree.Query(new Geomoir.Data.Coordinate(-1.25f, 51.7f));
            Console.WriteLine("GOT {0}", CountryNames[countryResult]);

            // Pyongyang (North Korea)
            countryResult = Qtree.Query(new Geomoir.Data.Coordinate(125.3f, 39.0f));
            Console.WriteLine("GOT {0}", CountryNames[countryResult]);

            // Seoul (South Korea)
            countryResult = Qtree.Query(new Geomoir.Data.Coordinate(126.98f, 37.57f));
            Console.WriteLine("GOT {0}", CountryNames[countryResult]);

            // Madrid (Spain)
            countryResult = Qtree.Query(new Geomoir.Data.Coordinate(-3.68f, 40.04f));
            Console.WriteLine("GOT {0}", CountryNames[countryResult]);

            // Lima (Peru)
            countryResult = Qtree.Query(new Geomoir.Data.Coordinate(-77.03f, -12.04f));
            Console.WriteLine("GOT {0}", CountryNames[countryResult]);

            // Zanzibar (Tanzania)
            countryResult = Qtree.Query(new Geomoir.Data.Coordinate(39.32f, -6.13f));
            Console.WriteLine("GOT {0}", CountryNames[countryResult]);

            // Vancouver (Canada)
            countryResult = Qtree.Query(new Geomoir.Data.Coordinate(-123.1f, 49.25f));
            Console.WriteLine("GOT {0}", CountryNames[countryResult]);

            // Honolulu (USA)
            countryResult = Qtree.Query(new Geomoir.Data.Coordinate(-157.8f, 21.3f));
            Console.WriteLine("GOT {0}", CountryNames[countryResult]);

            // Londonderry (UK)
            countryResult = Qtree.Query(new Geomoir.Data.Coordinate(-7.31f, 54.996f));
            Console.WriteLine("GOT {0}", CountryNames[countryResult]);

            // Donegal (Ireland)
            countryResult = Qtree.Query(new Geomoir.Data.Coordinate(-8f, 54.917f));
            Console.WriteLine("GOT {0}", CountryNames[countryResult]);
        }
开发者ID:peterdn,项目名称:Geomoir,代码行数:42,代码来源:Program.cs


注:本文中的QuadTree.Query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。