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


C# RectangleF.Intersects方法代码示例

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


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

示例1: TestNotRectangleIntersectsCircle

        public void TestNotRectangleIntersectsCircle()
        {
            // ARRANGE.
            var rectangle = new RectangleF(new Vector2F(0.0f, 0.0f), new Vector2F(1.0f, 1.0f));
            var circle = new CircleF(new Vector2F(2.0f, 2.0f), 0.5f);

            // ASSERT.
            Assert.IsFalse(rectangle.Intersects(circle));
        }
开发者ID:npruehs,项目名称:game-math,代码行数:9,代码来源:RectangleIntersectionTests.cs

示例2: TestRectangleIntersectsRectangle

        public void TestRectangleIntersectsRectangle()
        {
            // ARRANGE.
            var first = new RectangleF(new Vector2F(0.0f, 0.0f), new Vector2F(2.0f, 2.0f));
            var second = new RectangleF(new Vector2F(1.0f, 1.0f), new Vector2F(2.0f, 2.0f));

            // ASSERT.
            Assert.IsTrue(first.Intersects(second));
        }
开发者ID:npruehs,项目名称:game-math,代码行数:9,代码来源:RectangleIntersectionTests.cs

示例3: BuildDoodads

        public IEnumerable<SceneObject> BuildDoodads(IEnumerable<IModelDefinition> definitions, IList<StringReference> references, 
            RectangleF bounds, Matrix? rootTransform = null)
        {
            foreach (var definition in definitions)
            {
                if (definition.Id != null && !_builtIds.Add(definition.Id.Value)) continue;
                var doodad = Files.GetDoodad(definition.GetModelReference(references));
                if (doodad.Triangles.Length == 0) continue;

                var transform = definition.GetTranform();
                if (rootTransform.HasValue) transform = transform * rootTransform.Value;

                var sceneObject = BuildModelFromTransform(doodad.Vertices, doodad.Triangles, transform, definition.GetModelReference(references));
                if (bounds.Intersects(sceneObject.Bounds)) yield return sceneObject;
            }
        }
开发者ID:sgraf812,项目名称:BananaMpq,代码行数:16,代码来源:DoodadBuilder.cs

示例4: BuildWmos

        public WmoBuildResults BuildWmos(IEnumerable<IModelDefinition> definitions, IList<StringReference> references, RectangleF bounds)
        {
            var groups = Enumerable.Empty<SceneObject>();
            var liquids = Enumerable.Empty<SceneObject>();
            var doodads = Enumerable.Empty<SceneObject>();
            foreach (var definition in definitions)
            {
                if (definition.Id != null && !_builtIds.Add(definition.Id.Value)) continue;
                var file = definition.GetModelReference(references);
                var wmo = Files.GetWmo(file);
                var transform = definition.GetTranform();

                var doodadDefs = definition.FilterDoodadSetDefinitions(wmo.DoodadSets, wmo.DoodadDefinitions);
                doodads = doodads.Concat(_doodadBuilder.BuildDoodads(doodadDefs, wmo.DoodadReferences, bounds, transform));

                groups = groups.Concat(from g in wmo.Groups
                                       let collisionTriangles =
                                           g.Triangles.Where((t, i) => (g.TriangleFlags[i] & MopyChunk.NoCollision) == 0)
                                       where collisionTriangles.Any()
                                       select BuildModelFromTransform(g.Vertices, collisionTriangles, transform, file) into sceneObject
                                       where bounds.Intersects(sceneObject.Bounds)
                                       select sceneObject);

                liquids = liquids.Concat(from g in wmo.Groups
                                         where g.Liquid != null
                                         let l = g.Liquid
                                         let meshBuilder = new SquareMeshBuilder(l.HeightMap, new Vector3(l.Position.X, l.Position.Y, 0.0f),
                                             MapChunk.TileSize, transform)
                                         let materialProperties = _getLiquidMaterial(g.DetermineLiquidType())
                                         select meshBuilder.BuildSquareMesh((c, r) => !l.ExistsTable[r, c], materialProperties, bounds)
                                         into sceneObject
                                         where sceneObject != null
                                         select sceneObject);
            }

            return new WmoBuildResults
            {
                GroupObjects = groups,
                Doodads = doodads,
                Liquids = liquids
            };
        }
开发者ID:sgraf812,项目名称:BananaMpq,代码行数:42,代码来源:WmoBuilder.cs

示例5: TestIntersectsWithRectangleReference

    public void TestIntersectsWithRectangleReference() {
      RectangleF testRectangle = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f);
      bool result;

      RectangleF insideRectangle = new RectangleF(3.0f, 6.0f, 3.7f, 5.2f);
      testRectangle.Intersects(ref insideRectangle, out result);
      Assert.IsTrue(result);

      RectangleF outsideRectangle = new RectangleF(1.1f, 3.3f, 5.8f, 8.0f);
      testRectangle.Intersects(ref outsideRectangle, out result);
      Assert.IsTrue(result);

      RectangleF horizontalTouchingRectangle = new RectangleF(3.0f, 0.0f, 3.7f, 16.0f);
      testRectangle.Intersects(ref horizontalTouchingRectangle, out result);
      Assert.IsTrue(result);

      RectangleF verticalTouchingRectangle = new RectangleF(0.0f, 6.0f, 12.0f, 5.2f);
      testRectangle.Intersects(ref verticalTouchingRectangle, out result);
      Assert.IsTrue(result);

      RectangleF upperLeftTouchingRectangle = new RectangleF(0.0f, 0.0f, 1.2f, 3.4f);
      testRectangle.Intersects(ref upperLeftTouchingRectangle, out result);
      Assert.IsFalse(result);

      RectangleF lowerRightTouchingRectangle = new RectangleF(6.8f, 10.2f, 1.0f, 1.0f);
      testRectangle.Intersects(ref lowerRightTouchingRectangle, out result);
      Assert.IsFalse(result);
    }
开发者ID:pr0gramm3r1,项目名称:AngryTanks,代码行数:28,代码来源:RectangleF.Test.cs

示例6: TestIntersectsWithRectangle

    public void TestIntersectsWithRectangle() {
      RectangleF testRectangle = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f);

      RectangleF insideRectangle = new RectangleF(3.0f, 6.0f, 3.7f, 5.2f);
      Assert.IsTrue(testRectangle.Intersects(insideRectangle));

      RectangleF outsideRectangle = new RectangleF(1.1f, 3.3f, 5.8f, 8.0f);
      Assert.IsTrue(testRectangle.Intersects(outsideRectangle));

      RectangleF horizontalTouchingRectangle = new RectangleF(3.0f, 0.0f, 3.7f, 16.0f);
      Assert.IsTrue(testRectangle.Intersects(horizontalTouchingRectangle));

      RectangleF verticalTouchingRectangle = new RectangleF(0.0f, 6.0f, 12.0f, 5.2f);
      Assert.IsTrue(testRectangle.Intersects(verticalTouchingRectangle));

      RectangleF upperLeftTouchingRectangle = new RectangleF(0.0f, 0.0f, 1.2f, 3.4f);
      Assert.IsFalse(testRectangle.Intersects(upperLeftTouchingRectangle));

      RectangleF lowerRightTouchingRectangle = new RectangleF(6.8f, 10.2f, 1.0f, 1.0f);
      Assert.IsFalse(testRectangle.Intersects(lowerRightTouchingRectangle));
    }
开发者ID:pr0gramm3r1,项目名称:AngryTanks,代码行数:21,代码来源:RectangleF.Test.cs

示例7: IsOccupied

        public bool IsOccupied(RectangleF area, out RectangleF collisionArea, bool checkCollisionAgainstCannons = true, bool checkCollisionsAgainstDoors = true)
        {
            /* Tiles */
            int leftTile = Tile.WorldToTileCoordinate(area.Left);
            int topTile = Tile.WorldToTileCoordinate(area.Top);
            int rightTile = Tile.WorldToTileCoordinate(FlaiMath.Ceiling(area.Right / Tile.Size) * Tile.Size) - 1;
            int bottomTile = Tile.WorldToTileCoordinate(FlaiMath.Ceiling(area.Bottom / Tile.Size) * Tile.Size) - 1;

            for (int y = topTile; y <= bottomTile; y++)
            {
                for (int x = leftTile; x <= rightTile; x++)
                {
                    if (Tile.IsSolid(_worldMap[x, y]) && (checkCollisionAgainstCannons || !Tile.IsCannon(_worldMap[x, y])) && (checkCollisionsAgainstDoors || _worldMap[x, y] != TileType.DoorLock))
                    {
                        collisionArea = Tile.GetTileBounds(x, y);
                        return true;
                    }
                }
            }

            // Game objects
            foreach (GameObject gameObject in this.CollisionGameObjects)
            {
                if (gameObject.CollidesWithPlayer)
                {
                    if (area.Intersects(gameObject.Area) && area.Intersects(gameObject.Area))
                    {
                        if (!checkCollisionAgainstCannons && gameObject.GetType() == typeof(Cannon))
                        {
                            continue;
                        }

                        if (!checkCollisionsAgainstDoors && gameObject.GetType() == typeof(Door))
                        {
                            continue;
                        }

                        collisionArea = gameObject.Area; // !!!! ......
                        return true;
                    }
                }
            }

            collisionArea = default(RectangleF);
            return false;
        }
开发者ID:JaakkoLipsanen,项目名称:WVVW,代码行数:46,代码来源:World.cs

示例8: CheckBounds

 /// <summary>
 /// Checks if current instance bounds intersects with viewport or not.
 /// </summary>
 /// <param name="viewport">The viewport.</param>
 /// <returns>Return <c>True</c> if bounds intersects with viewport, otherwise <c>False</c>.</returns>
 public bool CheckBounds(RectangleF viewport)
 {
     return viewport.Intersects(this.bounds);
 }
开发者ID:huoxudong125,项目名称:oxyplot,代码行数:9,代码来源:TextRenderUnit.cs

示例9: IntersectsTest1

        public void IntersectsTest1()
        {
            RectangleF sourceRect = new RectangleF(0f, 0f, 100f, 100f);
            RectangleF contained = new RectangleF(10f, 10f, 10f, 10f);
            RectangleF intersectsOnRight = new RectangleF(90f, 0f, 100f, 100f);
            RectangleF noIntersection = new RectangleF(101f, 101f, 10f, 10f);
            RectangleF onTheLine = new RectangleF(100f, 100f, 1f, 1f);

            Assert.IsTrue(sourceRect.Intersects(contained));
            Assert.IsTrue(sourceRect.Intersects(intersectsOnRight));
            Assert.IsFalse(sourceRect.Intersects(noIntersection));
            Assert.IsFalse(sourceRect.Intersects(onTheLine));
        }
开发者ID:shadercoder,项目名称:Icicle-Framework,代码行数:13,代码来源:RectangleFTest.cs

示例10: RectRect

 /// <summary> Пересечение прямоугольников типа float. </summary>
 /// <param name="r1"> Прямоугольник 1. </param>
 /// <param name="r2"> Прямоугольник 2. </param>
 public static bool RectRect(RectangleF r1, RectangleF r2)
 {
     return r1.Intersects(r2);
 }
开发者ID:Psy-Effects,项目名称:DoomEffect,代码行数:7,代码来源:Collision.cs


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