本文整理汇总了C#中Vertices.Reverse方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.Reverse方法的具体用法?C# Vertices.Reverse怎么用?C# Vertices.Reverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices.Reverse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvexPartition
/// <summary>
/// Decomposes a non-convex polygon into a number of convex polygons, up
/// to maxPolys (remaining pieces are thrown out).
/// Each resulting polygon will have no more than Settings.MaxPolygonVertices
/// vertices.
/// Warning: Only works on simple polygons
/// </summary>
/// <param name="vertices">The vertices.</param>
/// <param name="maxPolys">The maximum number of polygons.</param>
/// <param name="tolerance">The tolerance.</param>
/// <returns></returns>
public static List<Vertices> ConvexPartition(Vertices vertices, int maxPolys, float tolerance)
{
if (vertices.Count < 3)
return new List<Vertices> {vertices};
List<Triangle> triangulated;
if (vertices.IsCounterClockWise())
{
Vertices tempP = new Vertices(vertices);
tempP.Reverse();
triangulated = TriangulatePolygon(tempP);
}
else
{
triangulated = TriangulatePolygon(vertices);
}
if (triangulated.Count < 1)
{
//Still no luck? Oh well...
throw new Exception("Can't triangulate your polygon.");
}
List<Vertices> polygonizedTriangles = PolygonizeTriangles(triangulated, maxPolys, tolerance);
//The polygonized triangles are not guaranteed to be without collinear points. We remove
//them to be sure.
for (int i = 0; i < polygonizedTriangles.Count; i++)
{
polygonizedTriangles[i] = SimplifyTools.CollinearSimplify(polygonizedTriangles[i], 0);
}
return polygonizedTriangles;
}
示例2: ConvexPartition
//box2D rev 32 - for details, see http://www.box2d.org/forum/viewtopic.php?f=4&t=83&start=50
/// <summary>
/// Decompose the polygon into several smaller non-concave polygon.
/// Each resulting polygon will have no more than Settings.MaxPolygonVertices vertices.
/// </summary>
/// <param name="vertices">The vertices.</param>
/// <param name="maxPolys">The maximum number of polygons. The rest are thrown out.</param>
/// <param name="tolerance">The tolerance.</param>
public static List<Vertices> ConvexPartition(Vertices vertices, float tolerance = 0.001f)
{
if (vertices.Count <= 3)
return new List<Vertices> { vertices };
if (Settings.SkipSanityChecks)
Debug.Assert(!vertices.IsCounterClockWise(), "The Earclip algorithm expects the polygon to be clockwise.");
else
{
if (vertices.IsCounterClockWise())
{
Vertices temp = new Vertices(vertices);
temp.Reverse();
return TriangulatePolygon(temp, tolerance);
}
return TriangulatePolygon(vertices, tolerance);
}
return new List<Vertices>();
}
示例3: ConvexPartition
/// <summary>
/// Decompose the polygon into several smaller non-concave polygon.
/// If the polygon is already convex, it will return the original polygon, unless it is over Settings.MaxPolygonVertices.
/// </summary>
public static List<Vertices> ConvexPartition(Vertices vertices)
{
if (vertices.Count <= 3)
return new List<Vertices> { vertices };
if (Settings.SkipSanityChecks)
{
//We check for counter clockwise vertices, as it is a precondition in this algorithm.
Debug.Assert(vertices.IsCounterClockWise(), "The polygon is not counter clockwise. This is needed for Bayazit to work correctly.");
}
else
{
if (!vertices.IsCounterClockWise())
{
Vertices temp = new Vertices(vertices);
temp.Reverse();
return Triangulate(temp);
}
return Triangulate(vertices);
}
return new List<Vertices>();
}
示例4: ConvexPartition
/// <summary>
/// Decomposes a non-convex polygon into a number of convex polygons, up
/// to maxPolys (remaining pieces are thrown out).
/// Each resulting polygon will have no more than Settings.MaxPolygonVertices
/// vertices.
/// Warning: Only works on simple polygons
/// </summary>
/// <param name="vertices">The vertices.</param>
/// <param name="maxPolys">The maximum number of polygons.</param>
/// <param name="tolerance">The tolerance.</param>
/// <returns></returns>
public static List<Vertices> ConvexPartition(Vertices vertices, int maxPolys, float tolerance)
{
if (vertices.Count < 3)
return new List<Vertices> { vertices };
/*
if (vertices.IsConvex() && vertices.Count <= Settings.MaxPolygonVertices)
{
if (vertices.IsCounterClockWise())
{
Vertices tempP = new Vertices(vertices);
tempP.Reverse();
tempP = SimplifyTools.CollinearSimplify(tempP);
tempP.ForceCounterClockWise();
return new List<Vertices> { tempP };
}
vertices = SimplifyTools.CollinearSimplify(vertices);
vertices.ForceCounterClockWise();
return new List<Vertices> { vertices };
}
*/
List<Triangle> triangulated;
if (vertices.IsCounterClockWise())
{
Vertices tempP = new Vertices(vertices);
tempP.Reverse();
triangulated = TriangulatePolygon(tempP);
}
else
{
triangulated = TriangulatePolygon(vertices);
}
if (triangulated.Count < 1)
{
//Still no luck? Oh well...
throw new Exception("Can't triangulate your polygon.");
}
List<Vertices> polygonizedTriangles = PolygonizeTriangles(triangulated, maxPolys, tolerance);
//The polygonized triangles are not guaranteed to be without collinear points. We remove
//them to be sure.
for (int i = 0; i < polygonizedTriangles.Count; i++)
{
polygonizedTriangles[i] = SimplifyTools.CollinearSimplify(polygonizedTriangles[i], 0);
}
//Remove empty vertice collections
for (int i = polygonizedTriangles.Count - 1; i >= 0; i--)
{
if (polygonizedTriangles[i].Count == 0)
polygonizedTriangles.RemoveAt(i);
}
return polygonizedTriangles;
}
示例5: CreateTrapezoid
private Vertices CreateTrapezoid(float lowerWidth, float upperWidth,
float height)
{
Vertices trapezoid = new Vertices(4);
trapezoid.Add(new Vector2(-(lowerWidth / 2f), 0f));
trapezoid.Add(new Vector2(-(upperWidth / 2f), height));
trapezoid.Add(new Vector2(upperWidth / 2f, height));
trapezoid.Add(new Vector2(lowerWidth / 2f, 0f));
trapezoid.Reverse();
return trapezoid;
}
示例6: ConvexPartition
public static List<Vertices> ConvexPartition(Vertices vertices, TriangulationAlgorithm algorithm, bool discardAndFixInvalid = true, float tolerance = 0.001f)
{
if (vertices.Count <= 3)
return new List<Vertices> { vertices };
List<Vertices> results = null;
switch (algorithm)
{
case TriangulationAlgorithm.Earclip:
if (Settings.SkipSanityChecks)
Debug.Assert(!vertices.IsCounterClockWise(), "The Earclip algorithm expects the polygon to be clockwise.");
else
{
if (vertices.IsCounterClockWise())
{
Vertices temp = new Vertices(vertices);
temp.Reverse();
results = EarclipDecomposer.ConvexPartition(temp, tolerance);
}
else
results = EarclipDecomposer.ConvexPartition(vertices, tolerance);
}
break;
case TriangulationAlgorithm.Bayazit:
if (Settings.SkipSanityChecks)
Debug.Assert(vertices.IsCounterClockWise(), "The polygon is not counter clockwise. This is needed for Bayazit to work correctly.");
else
{
if (!vertices.IsCounterClockWise())
{
Vertices temp = new Vertices(vertices);
temp.Reverse();
results = BayazitDecomposer.ConvexPartition(temp);
}
else
results = BayazitDecomposer.ConvexPartition(vertices);
}
break;
case TriangulationAlgorithm.Flipcode:
if (Settings.SkipSanityChecks)
Debug.Assert(vertices.IsCounterClockWise(), "The polygon is not counter clockwise. This is needed for Bayazit to work correctly.");
else
{
if (!vertices.IsCounterClockWise())
{
Vertices temp = new Vertices(vertices);
temp.Reverse();
results = FlipcodeDecomposer.ConvexPartition(temp);
}
else
results = FlipcodeDecomposer.ConvexPartition(vertices);
}
break;
case TriangulationAlgorithm.Seidel:
results = SeidelDecomposer.ConvexPartition(vertices, tolerance);
break;
case TriangulationAlgorithm.SeidelTrapezoids:
results = SeidelDecomposer.ConvexPartitionTrapezoid(vertices, tolerance);
break;
case TriangulationAlgorithm.Delauny:
results = CDTDecomposer.ConvexPartition(vertices);
break;
default:
throw new ArgumentOutOfRangeException("algorithm");
}
if (discardAndFixInvalid)
{
for (int i = results.Count - 1; i >= 0; i--)
{
Vertices polygon = results[i];
if (!ValidatePolygon(polygon))
results.RemoveAt(i);
}
}
return results;
}
示例7: ValidatePolygon
private static bool ValidatePolygon(Vertices polygon)
{
PolygonError errorCode = polygon.CheckPolygon();
if (errorCode == PolygonError.InvalidAmountOfVertices || errorCode == PolygonError.AreaTooSmall || errorCode == PolygonError.SideTooSmall || errorCode == PolygonError.NotSimple)
return false;
if (errorCode == PolygonError.NotCounterClockWise) //NotCounterCloseWise is the last check in CheckPolygon(), thus we don't need to call ValidatePolygon again.
polygon.Reverse();
if (errorCode == PolygonError.NotConvex)
{
polygon = GiftWrap.GetConvexHull(polygon);
return ValidatePolygon(polygon);
}
return true;
}