本文整理汇总了C#中Circle.Intersects方法的典型用法代码示例。如果您正苦于以下问题:C# Circle.Intersects方法的具体用法?C# Circle.Intersects怎么用?C# Circle.Intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Circle
的用法示例。
在下文中一共展示了Circle.Intersects方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCirclesIntersects
/// <summary>
/// tests that the circle.Intersects method properly determines whether 2
/// circles Intersects
/// </summary>
public void TestCirclesIntersects()
{
//create a few circles
Circle circle1 = new Circle { Center = new Point(0,0), Radius = 2};
Circle circle2 = new Circle { Center = new Point(0,0), Radius = 3};
Circle circle3 = new Circle { Center = new Point(6, 0), Radius = 3 };
Circle circle4 = new Circle { Center = new Point(1, 1), Radius = 3 };
//non-Intersectsing circles
Assert.IsFalse(circle1.Intersects(circle3));
Assert.IsFalse(circle3.Intersects(circle1));
Assert.IsFalse(circle1.Intersects(null));
//touching circles
Assert.IsTrue(circle2.Intersects(circle3));
Assert.IsTrue(circle3.Intersects(circle2));
//Intersectsing circles
Assert.IsTrue(circle1.Intersects(circle2));
Assert.IsTrue(circle2.Intersects(circle1));
Assert.IsTrue(circle2.Intersects(circle4));
Assert.IsTrue(circle4.Intersects(circle2));
Assert.IsTrue(circle1.Intersects(circle4));
Assert.IsTrue(circle4.Intersects(circle1));
Assert.IsTrue(circle3.Intersects(circle4));
Assert.IsTrue(circle4.Intersects(circle3));
}
示例2: CanStructureBePlaced
public bool CanStructureBePlaced(Point location, int size, Unit builder, bool cutCorners)
{
List<PathNode> placingStructurePathNodes = new List<PathNode>();
Circle collisionCircle = new Circle(new Vector2(location.X * Map.TileSize + (size / 2) * Map.TileSize, location.Y * Map.TileSize + (size / 2) * Map.TileSize), size * Map.TileSize);
//placingStructureCenterPoint = collisionCircle.CenterPoint;
for (int x = location.X; x < location.X + size; x++)
{
for (int y = location.Y; y < location.Y + size; y++)
{
PathNode node = Rts.pathFinder.PathNodes[(int)MathHelper.Clamp(y, 0, Map.Height - 1), (int)MathHelper.Clamp(x, 0, Map.Width - 1)];
if (collisionCircle.Intersects(node.Tile))
{
placingStructurePathNodes.Add(node);
}
}
}
// remove corners
if (cutCorners)
{
placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[location.Y, location.X]);
if (location.X + size <= Map.Width - 1)
placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[location.Y, location.X + size - 1]);
else
return false;
if (location.Y + size <= Map.Height - 1)
placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[location.Y + size - 1, location.X]);
else
return false;
placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[location.Y + size - 1, location.X + size - 1]);
}
foreach (PathNode node in placingStructurePathNodes)
{
if (!node.Tile.Walkable || node.Blocked)
return false;
if (node.UnitsContained.Count > 0)
{
if (node.UnitsContained.Count == 1 && node.UnitsContained.ElementAt<Unit>(0) == builder)
continue;
else
{
bool allow = true;
foreach (Unit unit in node.UnitsContained)
{
if (unit.Team != builder.Team)
{
allow = false;
break;
}
}
if (!allow)
return false;
}
}
}
return true;
}
示例3: updatePlacingStructure
void updatePlacingStructure()
{
if (!placingStructure)
return;
Vector2 mousePosition = new Vector2(mouseState.X, mouseState.Y);
mousePosition = Vector2.Transform(mousePosition, Matrix.Invert(camera.get_transformation(worldViewport)));
placingStructureLocation.X = (int)Math.Round(MathHelper.Clamp(mousePosition.X / map.TileSize - placingStructureType.Size / 2f, 0, map.Width - 1));
placingStructureLocation.Y = (int)Math.Round(MathHelper.Clamp(mousePosition.Y / map.TileSize - placingStructureType.Size / 2f, 0, map.Height - 1));
placingStructureCenterPoint.X = placingStructureLocation.X * map.TileSize + (placingStructureType.Size * map.TileSize) / 2;
placingStructureCenterPoint.Y = placingStructureLocation.Y * map.TileSize + (placingStructureType.Size * map.TileSize) / 2;
placingStructurePathNodes.Clear();
placingStructureBlockedPathNodes.Clear();
allowPlacingStructure = true;
Circle collisionCircle = new Circle(new Vector2(placingStructureLocation.X * map.TileSize + (placingStructureType.Size / 2) * map.TileSize, placingStructureLocation.Y * map.TileSize + (placingStructureType.Size / 2) * map.TileSize), placingStructureType.Size * map.TileSize);
//placingStructureCenterPoint = collisionCircle.CenterPoint;
if (placingStructureType == StructureType.TownHall)
{
foreach (Resource resource in Resource.Resources)
{
if (Vector2.Distance(collisionCircle.CenterPoint, resource.CenterPoint) < map.TileSize * 9)
{
allowPlacingStructure = false;
tooCloseToResource = true;
}
}
}
else
tooCloseToResource = false;
for (int x = placingStructureLocation.X; x < placingStructureLocation.X + placingStructureType.Size; x++)
{
for (int y = placingStructureLocation.Y; y < placingStructureLocation.Y + placingStructureType.Size; y++)
{
PathNode node = Rts.pathFinder.PathNodes[(int)MathHelper.Clamp(y, 0, map.Height - 1), (int)MathHelper.Clamp(x, 0, map.Width - 1)];
if (collisionCircle.Intersects(node.Tile))
{
placingStructurePathNodes.Add(node);
}
}
}
// remove corners
if (placingStructureType.CutCorners)
{
placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[placingStructureLocation.Y, placingStructureLocation.X]);
if (placingStructureLocation.X + placingStructureType.Size <= map.Width - 1)
placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[placingStructureLocation.Y, placingStructureLocation.X + placingStructureType.Size - 1]);
else
allowPlacingStructure = false;
if (placingStructureLocation.Y + placingStructureType.Size <= map.Height - 1)
placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[placingStructureLocation.Y + placingStructureType.Size - 1, placingStructureLocation.X]);
else
allowPlacingStructure = false;
if (allowPlacingStructure)
placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[placingStructureLocation.Y + placingStructureType.Size - 1, placingStructureLocation.X + placingStructureType.Size - 1]);
}
for (int i = 0; i < placingStructurePathNodes.Count; )
{
PathNode node = placingStructurePathNodes[i];
if (!node.Tile.Walkable || (node.Blocked && node.Blocker is Structure && ((Structure)node.Blocker).Visible) || (node.Blocked && node.Blocker is Resource))
{
allowPlacingStructure = false;
placingStructurePathNodes.Remove(node);
placingStructureBlockedPathNodes.Add(node);
}
else
i++;
}
}
示例4: WillStructureFit
public bool WillStructureFit(Point location, int size, bool cutCorners)
{
List<PathNode> placingStructurePathNodes = new List<PathNode>();
Circle collisionCircle = new Circle(new Vector2(location.X * Map.TileSize + (size / 2) * Map.TileSize, location.Y * Map.TileSize + (size / 2) * Map.TileSize), size * Map.TileSize);
//placingStructureCenterPoint = collisionCircle.CenterPoint;
for (int x = location.X; x < location.X + size; x++)
{
for (int y = location.Y; y < location.Y + size; y++)
{
PathNode node = Rts.pathFinder.PathNodes[(int)MathHelper.Clamp(y, 0, Map.Height - 1), (int)MathHelper.Clamp(x, 0, Map.Width - 1)];
if (collisionCircle.Intersects(node.Tile))
{
placingStructurePathNodes.Add(node);
}
}
}
// remove corners
if (cutCorners)
{
placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[location.Y, location.X]);
if (location.X + size <= Map.Width - 1)
placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[location.Y, location.X + size - 1]);
else
return false;
if (location.Y + size <= Map.Height - 1)
placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[location.Y + size - 1, location.X]);
else
return false;
placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[location.Y + size - 1, location.X + size - 1]);
}
foreach (PathNode node in placingStructurePathNodes)
{
if (!node.Tile.Walkable || (node.Blocked && node.Blocker is Structure && ((Structure)node.Blocker).Visible) || (node.Blocked && node.Blocker is Resource))
return false;
}
return true;
}
示例5: GetNeighbors
//Returns all the neighbors within a given circle
public Buffer<GameObject> GetNeighbors(Circle c, Unit u)
{
neighborList.Clear();
int xMin = (int)(c.Center.X - c.Radius);
int xMax = (int)(c.Center.X + c.Radius);
int yMin = (int)(c.Center.Y - c.Radius);
int yMax = (int)(c.Center.Y + c.Radius);
xMin = (int)Math.Max(xMin, 0f);
yMin = (int)Math.Max(yMin, 0f);
xMax = (int)Math.Min(xMax, width - 1);
yMax = (int)Math.Min(yMax, height - 1);
for (int i = xMin; i <= xMax; i++)
{
for (int j = yMin; j <= yMax; j++)
{
for (int k = 0; k < objectMap[i, j].GetCount(); k++)
{
GameObject go = objectMap[i, j][k];
if (c.Intersects(go.GetBounds()) && !neighborList.Contains(go))
{
if (u == null)
{
neighborList.Add(go);
}
else if (!u.Equals(go))
{
neighborList.Add(go);
}
}
}
}
}
return neighborList;
}
示例6: Intersects
/// <summary>
/// Determines if Vector2 position is inside or on the edge of a circle.
/// </summary>
/// <param name="vector">Vector2 instance to check.</param>
/// <param name="circle">Circle instance to check.</param>
/// <returns>True if the Vector2 position is completely inside or along the edge of the target circle, false if not.</returns>
public static bool Intersects(this Vector2 vector, Circle circle)
{
return circle.Intersects(vector);
}
示例7: GetObjectCountInCircle
public int GetObjectCountInCircle(Circle c)
{
int count = 0;
int radius = (int)c.Radius;
int centerXCoord = (int)c.Center.X;
int centerYCoord = (int)c.Center.Y;
int xMin = centerXCoord - radius;
int xMax = centerXCoord + radius;
int yMin = centerYCoord - radius;
int yMax = centerYCoord + radius;
xMin = (int)Math.Max(xMin, 0);
yMin = (int)Math.Max(yMin, 0);
xMax = (int)Math.Min(xMax, width);
yMax = (int)Math.Min(yMax, height);
for (int i = xMin; i < xMax; i++)
{
for (int j = yMin; j < yMax; j++)
{
for (int k = 0; k < objectMap[i, j].GetCount(); k++)
{
if (c.Intersects(objectMap[i, j][k].GetBounds()))
{
count++;
}
}
}
}
return count;
}
示例8: FindSelectedVertex
private void FindSelectedVertex(Point mousePos)
{
if (_editState != EditState.Default)
{
return;
}
if (_selectedPoly == null)
{
_selectedVert = -1;
return;
}
for (int i = 0; i < _selectedPoly.Vertices.Count; i++)
{
Circle circle = new Circle(_selectedPoly.Vertices[i].X, _selectedPoly.Vertices[i].Y, 15);
if (circle.Intersects(mousePos))
{
_selectedVert = i;
return;
}
}
_selectedVert = -1;
}
示例9: distanceThresholdReached
private bool distanceThresholdReached(int distance)
{
Circle threshold = new Circle(Ship.WorldCenter, distance);
if (threshold.Intersects(Player.Ship.BoundingCircle))
return true;
else
return false;
}
示例10: CircleRectangleCollision
public static bool CircleRectangleCollision(Circle circle, PhysicalRectangle rectangle)
{
return circle.Intersects(rectangle);
}
示例11: PointCircleCollision
public static bool PointCircleCollision(ref Vector3 point, Circle circle)
{
return circle.Intersects(ref point);
}
示例12: CircleCircleCollision
public static bool CircleCircleCollision(Circle circle1, Circle circle2)
{
return circle1.Intersects(circle2);
}