Class YuPengClipper
- Assembly
- Alis.dll
The yu peng clipper class
public static class YuPengClipper
Inheritance
Inherited Members
Fields
ClipperEpsilonSquared
The clipper epsilon squared
private const float ClipperEpsilonSquared = 1.1920929E-07
Field Value
Methods
BuildPolygonsFromChain(List<Edge>, out List<Vertices>)
Calculates the polygon(s) from the result simplical chain.
private static PolyClipError BuildPolygonsFromChain(List<YuPengClipper.Edge> simplicies, out List<Vertices> result)
Parameters
simplicies
List<YuPengClipper.Edge>result
List<Vertices>
Returns
Remarks
Used by method Execute()
.
CalculateBeta(Vector2, Edge, float)
Needed to calculate the characteristics function of a simplex.
private static float CalculateBeta(Vector2 point, YuPengClipper.Edge e, float coefficient)
Parameters
point
Vector2e
YuPengClipper.Edgecoefficient
float
Returns
Remarks
Used by method CalculateEdgeCharacter()
.
CalculateIntersections(Vertices, Vertices, out Vertices, out Vertices)
Calculates all intersections between two polygons.
private static void CalculateIntersections(Vertices polygon1, Vertices polygon2, out Vertices slicedPoly1, out Vertices slicedPoly2)
Parameters
polygon1
Vertices-
The first polygon.
polygon2
Vertices-
The second polygon.
slicedPoly1
Vertices-
Returns the first polygon with added intersection points.
slicedPoly2
Vertices-
Returns the second polygon with added intersection points.
CalculateResultChain(List<float>, List<Edge>, List<float>, List<Edge>, PolyClipType, out List<Edge>)
Calculates the characteristics function for all edges of the given simplical chains and builds the result chain.
private static void CalculateResultChain(List<float> poly1Coeff, List<YuPengClipper.Edge> poly1Simplicies, List<float> poly2Coeff, List<YuPengClipper.Edge> poly2Simplicies, PolyClipType clipType, out List<YuPengClipper.Edge> resultSimplices)
Parameters
poly1Coeff
List<float>poly1Simplicies
List<YuPengClipper.Edge>poly2Coeff
List<float>poly2Simplicies
List<YuPengClipper.Edge>clipType
PolyClipTyperesultSimplices
List<YuPengClipper.Edge>
Remarks
Used by method Execute()
.
CalculateSimplexCoefficient(Vector2, Vector2, Vector2)
Returns the coefficient of a simplex.
private static float CalculateSimplexCoefficient(Vector2 a, Vector2 b, Vector2 c)
Parameters
Returns
Remarks
Used by method CalculateSimplicalChain()
.
CalculateSimplicalChain(Vertices, out List<float>, out List<Edge>)
Calculates the simplical chain corresponding to the input polygon.
private static void CalculateSimplicalChain(Vertices poly, out List<float> coeff, out List<YuPengClipper.Edge> simplicies)
Parameters
Remarks
Used by method Execute()
.
Difference(Vertices, Vertices, out PolyClipError)
Differences the polygon 1
public static List<Vertices> Difference(Vertices polygon1, Vertices polygon2, out PolyClipError error)
Parameters
polygon1
Vertices-
The polygon
polygon2
Vertices-
The polygon
error
PolyClipError-
The error
Returns
Execute(Vertices, Vertices, PolyClipType, out PolyClipError)
Implements "A new algorithm for Boolean operations on general polygons" available here: http://liama.ia.ac.cn/wiki/_media/user:dong:dong_cg_05.pdf Merges two polygons, a subject and a clip with the specified operation. Polygons may not be self-intersecting. Warning: May yield incorrect results or even crash if polygons contain collinear points.
private static List<Vertices> Execute(Vertices subject, Vertices clip, PolyClipType clipType, out PolyClipError error)
Parameters
subject
Vertices-
The subject polygon.
clip
Vertices-
The clip polygon, which is added, substracted or intersected with the subject
clipType
PolyClipType-
The operation to be performed. Either Union, Difference or Intersection.
error
PolyClipError-
The error generated (if any)
Returns
- List<Vertices>
-
A list of closed polygons, which make up the result of the clipping operation. Outer contours are ordered counter clockwise, holes are ordered clockwise.
GetAlpha(Vector2, Vector2, Vector2)
Needed for sorting multiple intersections points on the same edge.
private static float GetAlpha(Vector2 start, Vector2 end, Vector2 point)
Parameters
Returns
Remarks
Used by method CalculateIntersections()
.
Intersect(Vertices, Vertices, out PolyClipError)
Intersects the polygon 1
public static List<Vertices> Intersect(Vertices polygon1, Vertices polygon2, out PolyClipError error)
Parameters
polygon1
Vertices-
The polygon
polygon2
Vertices-
The polygon
error
PolyClipError-
The error
Returns
PointInSimplex(Vector2, Edge)
Winding number test for a point in a simplex.
private static bool PointInSimplex(Vector2 point, YuPengClipper.Edge edge)
Parameters
point
Vector2-
The point to be tested.
edge
YuPengClipper.Edge-
The edge that the point is tested against.
Returns
- bool
-
False if the winding number is even and the point is outside the simplex and True otherwise.
PointOnLineSegment(Vector2, Vector2, Vector2)
Tests if a point lies on a line segment.
private static bool PointOnLineSegment(Vector2 start, Vector2 end, Vector2 point)
Parameters
Returns
Remarks
Used by method CalculateBeta()
.
Union(Vertices, Vertices, out PolyClipError)
Unions the polygon 1
public static List<Vertices> Union(Vertices polygon1, Vertices polygon2, out PolyClipError error)
Parameters
polygon1
Vertices-
The polygon
polygon2
Vertices-
The polygon
error
PolyClipError-
The error
Returns
VectorEqual(Vector2, Vector2)
Describes whether vector equal
private static bool VectorEqual(Vector2 vec1, Vector2 vec2)
Parameters
Returns
- bool
-
The bool