Class EarclipDecomposer
- Assembly
- Alis.dll
Convex decomposition algorithm using ear clipping Properties:
- Only works on simple polygons.
- Does not support holes.
- Running time is O(n^2), n = number of vertices. Source: http://www.ewjordan.com/earClip/
internal static class EarclipDecomposer
Inheritance
Inherited Members
Methods
ConvexPartition(Vertices, float)
Decompose the polygon into several smaller non-concave polygon. Each resulting polygon will have no more than Settings.MaxPolygonVertices vertices.
public static List<Vertices> ConvexPartition(Vertices vertices, float tolerance = 0.001)
Parameters
Returns
IsEar(int, float[], float[], int)
Checks if vertex i is the tip of an ear in polygon defined by xv[] and yv[].
private static bool IsEar(int i, float[] xv, float[] yv, int xvLength)
Parameters
Returns
- bool
-
true
if the specified i is ear; otherwise,false
.
Remarks
Assumes clockwise orientation of polygon.
Remainder(int, int)
Fix for obnoxious behavior for the % operator for negative numbers...
private static int Remainder(int x, int modulus)
Parameters
Returns
ResolvePinchPoint(Vertices, out Vertices, out Vertices, float)
Finds and fixes "pinch points," points where two polygon vertices are at the same point. If a pinch point is found, pin is broken up into poutA and poutB and true is returned; otherwise, returns false. Mostly for internal use. O(N^2) time, which sucks...
private static bool ResolvePinchPoint(Vertices pin, out Vertices poutA, out Vertices poutB, float tolerance)
Parameters
Returns
TriangulatePolygon(Vertices, float)
Triangulates a polygon using simple ear-clipping algorithm. Returns size of Triangle array unless the polygon can't be triangulated. This should only happen if the polygon self-intersects, though it will not always return null for a bad polygon - it is the caller's responsibility to check for self-intersection, and if it doesn't, it should at least check that the return value is non-null before using. You're warned! Triangles may be degenerate, especially if you have identical points in the input to the algorithm. Check this before you use them. This is totally unoptimized, so for large polygons it should not be part of the simulation loop.
private static List<Vertices> TriangulatePolygon(Vertices vertices, float tolerance)
Parameters
Returns
Remarks
Only works on simple polygons.