本文整理汇总了C#中Vertices.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.IndexOf方法的具体用法?C# Vertices.IndexOf怎么用?C# Vertices.IndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices.IndexOf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSimplePolygon
/// <summary>
///
/// </summary>
/// <param name="entrance"></param>
/// <param name="last"></param>
/// <returns></returns>
private Vertices CreateSimplePolygon(Vector2 entrance, Vector2 last)
{
bool entranceFound = false;
bool endOfHull = false;
Vertices polygon = new Vertices(32);
Vertices hullArea = new Vertices(32);
Vertices endOfHullArea = new Vertices(32);
Vector2 current = Vector2.Zero;
#region Entrance check
// Get the entrance point. //todo: alle möglichkeiten testen
if (entrance == Vector2.Zero || !InBounds(ref entrance))
{
entranceFound = SearchHullEntrance(out entrance);
if (entranceFound)
{
current = new Vector2(entrance.X - 1f, entrance.Y);
}
}
else
{
if (IsSolid(ref entrance))
{
if (IsNearPixel(ref entrance, ref last))
{
current = last;
entranceFound = true;
}
else
{
Vector2 temp;
if (SearchNearPixels(false, ref entrance, out temp))
{
current = temp;
entranceFound = true;
}
else
{
entranceFound = false;
}
}
}
}
#endregion
if (entranceFound)
{
polygon.Add(entrance);
hullArea.Add(entrance);
Vector2 next = entrance;
do
{
// Search in the pre vision list for an outstanding point.
Vector2 outstanding;
if (SearchForOutstandingVertex(hullArea, out outstanding))
{
if (endOfHull)
{
// We have found the next pixel, but is it on the last bit of the hull?
if (endOfHullArea.Contains(outstanding))
{
// Indeed.
polygon.Add(outstanding);
}
// That's enough, quit.
break;
}
// Add it and remove all vertices that don't matter anymore
// (all the vertices before the outstanding).
polygon.Add(outstanding);
hullArea.RemoveRange(0, hullArea.IndexOf(outstanding));
}
// Last point gets current and current gets next. Our little spider is moving forward on the hull ;).
last = current;
current = next;
// Get the next point on hull.
if (GetNextHullPoint(ref last, ref current, out next))
{
// Add the vertex to a hull pre vision list.
hullArea.Add(next);
}
else
{
//.........这里部分代码省略.........
示例2: 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;
}
}
}
示例3: PreparePolygons
/// <summary>
/// Prepares the polygons.
/// </summary>
/// <param name="polygon1">The polygon1.</param>
/// <param name="polygon2">The polygon2.</param>
/// <param name="poly1">The poly1.</param>
/// <param name="poly2">The poly2.</param>
/// <param name="intersections">The intersections.</param>
/// <param name="error">The error.</param>
/// <returns></returns>
private static int PreparePolygons(Vertices polygon1, Vertices polygon2, out Vertices poly1, out Vertices poly2,
out List<EdgeIntersectInfo> intersections, out PolyUnionError error)
{
error = PolyUnionError.None;
// Make a copy of the polygons so that we dont modify the originals, and
// force vertices to integer (pixel) values.
poly1 = Round(polygon1);
poly2 = Round(polygon2);
// Find intersection points
if (!VerticesIntersect(poly1, poly2, out intersections))
{
// No intersections found - polygons do not overlap.
error = PolyUnionError.NoIntersections;
return -1;
}
// Add intersection points to original polygons, ignoring existing points.
foreach (EdgeIntersectInfo intersect in intersections)
{
if (!poly1.Contains(intersect.IntersectionPoint))
{
poly1.Insert(poly1.IndexOf(intersect.EdgeOne.EdgeStart) + 1, intersect.IntersectionPoint);
}
if (!poly2.Contains(intersect.IntersectionPoint))
{
poly2.Insert(poly2.IndexOf(intersect.EdgeTwo.EdgeStart) + 1, intersect.IntersectionPoint);
}
}
// Find starting point on the edge of polygon1
// that is outside of the intersected area
// to begin polygon trace.
int startingIndex = -1;
int currentIndex = 0;
do
{
if (!PointInPolygonAngle(poly1[currentIndex], poly2))
{
startingIndex = currentIndex;
break;
}
currentIndex = poly1.NextIndex(currentIndex);
} while (currentIndex != 0);
// If we dont find a point on polygon1 thats outside of the
// intersect area, the polygon1 must be inside of polygon2,
// in which case, polygon2 IS the union of the two.
if (startingIndex == -1)
{
error = PolyUnionError.Poly1InsidePoly2;
}
return startingIndex;
}