本文整理汇总了C#中Vertices.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.RemoveAt方法的具体用法?C# Vertices.RemoveAt怎么用?C# Vertices.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices.RemoveAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateIntersections
/// <summary>
/// Calculates all intersections between two polygons.
/// </summary>
/// <param name="polygon1">The first polygon.</param>
/// <param name="polygon2">The second polygon.</param>
/// <param name="slicedPoly1">Returns the first polygon with added intersection points.</param>
/// <param name="slicedPoly2">Returns the second polygon with added intersection points.</param>
private static void CalculateIntersections(Vertices polygon1, Vertices polygon2,
out Vertices slicedPoly1, out Vertices slicedPoly2)
{
slicedPoly1 = new Vertices(polygon1);
slicedPoly2 = new Vertices(polygon2);
// Iterate through polygon1's edges
for (int i = 0; i < polygon1.Count; i++)
{
// Get edge vertices
Vector2 a = polygon1[i];
Vector2 b = polygon1[polygon1.NextIndex(i)];
// Get intersections between this edge and polygon2
for (int j = 0; j < polygon2.Count; j++)
{
Vector2 c = polygon2[j];
Vector2 d = polygon2[polygon2.NextIndex(j)];
Vector2 intersectionPoint;
// Check if the edges intersect
if (LineTools.LineIntersect(a, b, c, d, out intersectionPoint))
{
// calculate alpha values for sorting multiple intersections points on a edge
float alpha;
// Insert intersection point into first polygon
alpha = GetAlpha(a, b, intersectionPoint);
if (alpha > 0f && alpha < 1f)
{
int index = slicedPoly1.IndexOf(a) + 1;
while (index < slicedPoly1.Count &&
GetAlpha(a, b, slicedPoly1[index]) <= alpha)
{
++index;
}
slicedPoly1.Insert(index, intersectionPoint);
}
// Insert intersection point into second polygon
alpha = GetAlpha(c, d, intersectionPoint);
if (alpha > 0f && alpha < 1f)
{
int index = slicedPoly2.IndexOf(c) + 1;
while (index < slicedPoly2.Count &&
GetAlpha(c, d, slicedPoly2[index]) <= alpha)
{
++index;
}
slicedPoly2.Insert(index, intersectionPoint);
}
}
}
}
// Check for very small edges
for (int i = 0; i < slicedPoly1.Count; ++i)
{
int iNext = slicedPoly1.NextIndex(i);
//If they are closer than the distance remove vertex
if ((slicedPoly1[iNext] - slicedPoly1[i]).LengthSquared() <= ClipperEpsilonSquared)
{
slicedPoly1.RemoveAt(i);
--i;
}
}
for (int i = 0; i < slicedPoly2.Count; ++i)
{
int iNext = slicedPoly2.NextIndex(i);
//If they are closer than the distance remove vertex
if ((slicedPoly2[iNext] - slicedPoly2[i]).LengthSquared() <= ClipperEpsilonSquared)
{
slicedPoly2.RemoveAt(i);
--i;
}
}
}
示例2: ParseFixture
private void ParseFixture(JObject jsonFixture, Body body)
{
Shape shape = null;
var circles = (JObject)jsonFixture["circle"];
var polygons = (JObject)jsonFixture["polygon"];
var chains = (JObject)jsonFixture["chain"];
if (circles != null)
{
var center = Vector2.Zero;
float radius = 0;
foreach (JProperty circleProperty in circles.Children())
{
switch (circleProperty.Name)
{
case "center":
center = ParseVector2(circleProperty);
break;
case "radius":
radius = HexToFloat(circleProperty.Value.ToString());
break;
}
}
shape = new CircleShape(radius, 1);
var circleShape = (CircleShape) shape;
circleShape.Position = center;
}
else if (polygons != null)
{
Vertices vertices = null;
foreach (var polygonProperty in polygons.Children().Cast<JProperty>().Where(polygonProperty => polygonProperty.Name == "vertices"))
vertices = new Vertices(ParseVector2Array(polygonProperty));
if (vertices != null)
shape = new PolygonShape(vertices, 1);
}
else if (chains != null)
{
//shape = new
Vertices vertices = null;
bool isLoopShape = false;
bool hasNextVertex;
bool hasPrevVertex;
Vector2 nextVertex = Vector2.Zero;
Vector2 prevVertex = Vector2.Zero;
foreach (JProperty chainProperty in chains.Children())
{
switch (chainProperty.Name)
{
case "vertices":
vertices = new Vertices(ParseVector2Array(chainProperty));
break;
case "hasNextVertex":
isLoopShape = true;
hasNextVertex = (bool) chainProperty.Value;
break;
case "hasPrevVertex":
hasPrevVertex = (bool) chainProperty.Value;
break;
case "nextVertex":
nextVertex = ParseVector2(chainProperty);
break;
case "prevVertex":
prevVertex = ParseVector2(chainProperty);
break;
default:
System.Diagnostics.Debug.WriteLine(chainProperty.Name + " not supported!");
break;
}
}
if (isLoopShape)
{
var lastvertexIndex = vertices.Count - 1;
if (vertices[0] == vertices[lastvertexIndex])
vertices.RemoveAt(lastvertexIndex);
shape = new LoopShape(vertices);
//var loopShape = (LoopShape) shape;
}
else
{
throw new NotImplementedException();
//shape = new EdgeShape(prevVertex, nextVertex);
//var edgeShape = (EdgeShape) shape;
}
}
var fixture = body.CreateFixture(shape);
foreach (JProperty fixtureProperty in jsonFixture.Children())
{
//Fixture properties
switch (fixtureProperty.Name)
{
case "name":
var value = fixtureProperty.Value.ToString();
_namedFixtures.Add(fixture, value);
break;
case "density":
//.........这里部分代码省略.........