Table of Contents

Class EarclipDecomposer

Namespace
Alis.Core.Physic.Common.Decomposition
Assembly
Alis.dll

Convex decomposition algorithm using ear clipping Properties:

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

vertices Vertices

The vertices.

tolerance float

The tolerance.

Returns

List<Vertices>

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

i int

The i.

xv float[]

The xv.

yv float[]

The yv.

xvLength int

Length of the xv.

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

x int

The x.

modulus int

The modulus.

Returns

int

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

pin Vertices

The pin.

poutA Vertices

The pout A.

poutB Vertices

The pout B.

tolerance float

Returns

bool

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

vertices Vertices
tolerance float

Returns

List<Vertices>

Remarks

Only works on simple polygons.