本文整理汇总了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));
}
示例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));
}
示例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;
}
}
示例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
};
}
示例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);
}
示例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));
}
示例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;
}
示例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);
}
示例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));
}
示例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);
}