本文整理汇总了C#中ClipperLib.Clipper类的典型用法代码示例。如果您正苦于以下问题:C# Clipper类的具体用法?C# Clipper怎么用?C# Clipper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Clipper类属于ClipperLib命名空间,在下文中一共展示了Clipper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClipPoly
//Apply a polygon clipper operation on subject vertices using cut vertices
public static List<Vector2[]> ClipPoly(Vector2[] subject, Vector2[] cut, ClipType operation)
{
List<Vector2[]> cutPolygons = new List<Vector2[]>();
Paths subj = new Paths(1);
subj.Add(Vector2ToIntList(subject));
Paths clip = new Paths(1);
clip.Add(Vector2ToIntList(cut));
Paths solution = new Paths();
Clipper c = new Clipper();
c.AddPaths(subj, PolyType.ptSubject, true);
c.AddPaths(clip, PolyType.ptClip, true);
c.Execute(operation,solution,
PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
/*
for(int i = 0; i<solution.Count; i++){
if( Mathf.Abs((float)Clipper.Area(solution[i])) > ignoreArea){
cutPolygons.Add( IntListToVector2( solution[i] ));
}
}
*/
return IntListsToVector2(solution);
}
示例2: clip
public static List<List<Vector2>> clip(List<Vector2> boundary, List<Vector2> region)
{
Polygons boundaryPoly = createPolygons(boundary);
Polygons regionPoly = createPolygons(region);
//clip triangular polygon against the boundary polygon
Polygons result = new Polygons();
Clipper c = new Clipper();
c.AddPaths(regionPoly, PolyType.ptClip, true);
c.AddPaths(boundaryPoly, PolyType.ptSubject, true);
c.Execute(ClipType.ctIntersection, result, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
List<List<Vector2>> clippedPolygons = new List<List<Vector2>>();
foreach (Polygon poly in result)
{
List<Vector2> clippedPoly = new List<Vector2>();
foreach (IntPoint p in poly)
{
clippedPoly.Add(new Vector2(p.X, p.Y) / multiplier);
}
clippedPolygons.Add(clippedPoly);
}
return clippedPolygons;
}
示例3: GetIntersection
public static XYPolygon GetIntersection(XYPolygon pol1, XYPolygon pol2)
{
List<List<IntPoint>> subj = new List<List<IntPoint>>();
subj.Add(new List<IntPoint>(pol1.Points.Count));
foreach(var p in pol1.Points)
subj[0].Add(new IntPoint(p.X, p.Y));
List<List<IntPoint>> clip = new List<List<IntPoint>>();
clip.Add(new List<IntPoint>(pol2.Points.Count));
foreach (var p in pol2.Points)
clip[0].Add(new IntPoint(p.X, p.Y));
List<List<IntPoint>> solution = new List<List<IntPoint>>();
Clipper c = new Clipper();
c.AddPaths(subj, PolyType.ptSubject, true);
c.AddPaths(clip, PolyType.ptClip, true);
c.Execute(ClipType.ctIntersection, solution,
PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
XYPolygon ToReturn = new XYPolygon();
if (solution.Count > 0)
foreach (var p in solution[0])
ToReturn.Points.Add(new XYPoint(p.X,p.Y));
return ToReturn;
}
示例4: Run
public List<List<IntPoint>> Run (List<List<IntPoint>> subject, double scale)
{
var c = ToClipper (scale, clip);
var clipper = new Clipper ();
clipper.AddPaths (subject, PolyType.ptSubject, subjectClosed);
clipper.AddPaths (c, PolyType.ptClip, true);
var solution = new List<List<IntPoint>> ();
clipper.Execute (type, solution, subjectFill, clipFill);
return solution;
}
示例5: GetArea
List<IntPoint> GetArea(Mesh mesh)
{
int[] triangles = mesh.triangles;
Vector3[] vertices = mesh.vertices;
List<Vector2> list = new List<Vector2>();
//Debug.Log("ver count: " + vertices.Length + " triangle: " + triangles.Length);
float y = float.MinValue;
for(int i=0; i < triangles.Length; i = i+3){
Vector3 p0 = vertices[triangles[i]];
Vector3 p1 = vertices[triangles[i+1]];
Vector3 p2 = vertices[triangles[i+2]];
if(Approximately(p0.y, p1.y) && Approximately(p0.y, p2.y)){
//Debug.Log(string.Format("({0}, {1}, {2})", p0, p1, p2));
if(y == float.MinValue){
y = p0.y;
}
if(Approximately(p0.y, y)){
list.Add(new Vector2(p0.x, p0.z));
list.Add(new Vector2(p1.x, p1.z));
list.Add(new Vector2(p2.x, p2.z));
}
}
}
//Debug.Log("list: " + list.Count);
List<List<IntPoint>> paths = new List<List<IntPoint>>();
for(int i=0; i < list.Count; i = i+3){
List<IntPoint> path = new List<IntPoint>();
for(int j=0; j < 3; j++){
path.Add(new IntPoint(list[i+j].x * clipScalling, list[i+j].y * clipScalling));
}
paths.Add(path);
}
Clipper clipper = new Clipper();
List<List<IntPoint>> solution = new List<List<IntPoint>>();
clipper.AddPaths(paths, PolyType.ptSubject, true);
clipper.Execute(ClipType.ctUnion, solution);
if(solution.Count > 0){
return solution[0];
}
return null;
}
示例6: DoCircleClipping
public void DoCircleClipping(Vector2 pos, float radius)
{
List<VertexPosition[]> shape_old = shape;
bool isCleared = false;
int sc = 0;
for (sc = 0; sc < shape_old.Count; sc++)
{
ClippingPolygons subj = new ClippingPolygons(1);
subj.Add(new ClippingPolygon(shape_old[sc].Length));
foreach (VertexPosition point in shape_old[sc])
{
subj[0].Add(new IntPoint((int)((point.Position.X) * accuracy), (int)((point.Position.Y) * accuracy)));
}
ClippingPolygons clip = new ClippingPolygons(1);
clip.Add(new ClippingPolygon());
for (int alpha = 0; alpha < 360; alpha += 10)
{
clip[0].Add(new IntPoint((int)(((Math.Sin((alpha) * Math.PI / 180.0) * radius) + pos.X) * accuracy), (int)(((Math.Cos((alpha) * Math.PI / 180.0) * radius) + pos.Y) * accuracy)));
//log.Log(pos.ToString());
}
ClippingPolygons solution = new ClippingPolygons();
Clipper c = new Clipper();
c.AddPolygons(subj, PolyType.ptSubject);
c.AddPolygons(clip, PolyType.ptClip);
if (c.Execute(ClipType.ctDifference, solution, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd))
{
if (!isCleared)
{
shape = new List<VertexPosition[]>();
drawer.Clear();
isCleared = true;
}
for (int f = 0; f < solution.Count; f++)
{
shape.Add(new VertexPosition[solution[f].Count]);
drawer.Add(new ChunkDrawer(ref log));
for (int i = 0; i < solution[f].Count; i++)
{
shape[shape.Count-1][i] = new VertexPosition(solution[f][i].X / accuracy, solution[f][i].Y / accuracy, 0);
}
drawer[shape.Count-1].BufferVertices(shape[shape.Count - 1]);
}
}
}
}
示例7: RelativeAreaDiff
public double RelativeAreaDiff (List<List<IntPoint>> actual, List<List<IntPoint>>expected)
{
var expectedArea = expected.Sum (path => Clipper.Area (path));
var difference = new List<List<IntPoint>> ();
var clipper = new Clipper ();
clipper.AddPaths (actual, PolyType.ptSubject, true);
clipper.AddPaths (expected, PolyType.ptClip, true);
clipper.Execute (ClipType.ctXor, difference, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
var differenceArea = difference.Sum (path => Clipper.Area (path));
return Math.Abs (differenceArea) / Math.Abs (expectedArea);
}
示例8: ClipperXor
// perform xor
public static Paths ClipperXor(this Polygon clip, Polygon subject)
{
var subj = new Paths();
subj.Add(subject.ToClipperPath());
var clp = new Paths();
clp.Add(clip.ToClipperPath());
var result = new Paths();
var c = new Clipper();
c.Execute(ClipType.ctXor, result, PolyFillType.pftPositive, PolyFillType.pftPositive);
return result;
}
示例9: IsIntersects
/// <summary>
/// Checks if polygons are intersecting
/// </summary>
/// <param name="p1">Subject polygon</param>
/// <param name="p2">Clip polygon(s)</param>
/// <returns>true if intersects</returns>
public static bool IsIntersects(Paths p1, params Paths[] p2)
{
Clipper c = new Clipper();
Paths solution = new Paths();
c.AddPaths(p1, PolyType.ptSubject, true);
for(int i = 0; i < p2.Length; i++)
c.AddPaths(p2[i], PolyType.ptClip, true);
c.Execute(ClipType.ctIntersection, solution, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
return solution.Count != 0;
}
示例10: MeshDifference
public static Vector3[] MeshDifference(Vector3[] mesh1, Vector3[] mesh2)
{
List<IntPoint> subj = MeshToPath3D(mesh1);
List<IntPoint> clip = MeshToPath3D(mesh2);
List<List<IntPoint>> solution = new List<List<IntPoint>>();
Clipper c = new Clipper();
c.AddPath(subj, PolyType.ptSubject, true);
c.AddPath(clip, PolyType.ptClip, true);
c.Execute(ClipType.ctDifference, solution,
PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
return PathToMesh3D(solution[0]);
}
示例11: ClipperUnion
// perform union on a list of polygons
public static Paths ClipperUnion(this List<Polygon> polygons)
{
var subj = new Paths(polygons.Count);
var clip = new Paths(polygons.Count);
foreach (var polygon in polygons)
{
subj.Add(polygon.ToClipperPath());
clip.Add(polygon.ToClipperPath());
}
var solution = new Paths();
var c = new Clipper();
c.AddPaths(subj, PolyType.ptSubject, true);
c.AddPaths(clip, PolyType.ptClip, true);
c.Execute(ClipType.ctUnion, solution, PolyFillType.pftPositive, PolyFillType.pftPositive);
return solution;
}
示例12: ClipPolygons
public static List<List<IntPoint>> ClipPolygons(List<Polygon> polygons)
{
var subj = new List<List<IntPoint>>(polygons.Count);
var clip = new List<List<IntPoint>>(polygons.Count);
foreach (var polygon in polygons)
{
subj.Add(polygon.ToClipperPath());
clip.Add(polygon.ToClipperPath());
}
var solution = new List<List<IntPoint>>();
var c = new Clipper();
c.AddPaths(subj, PolyType.ptSubject, true);
c.AddPaths(clip, PolyType.ptClip, true);
c.Execute(ClipType.ctUnion, solution, PolyFillType.pftPositive, PolyFillType.pftEvenOdd);
return solution;
}
示例13: Add
public static List<Vector2> Add(this Shape shape, Shape secondShape, Action<Shape> completed)
{
List<Vector2> points = new List<Vector2>();
Clipper c = new Clipper();
List<List<IntPoint>> subj = new List<List<IntPoint>>();
List<List<IntPoint>> clip = new List<List<IntPoint>>();
List<List<IntPoint>> solution = new List<List<IntPoint>>();
List<IntPoint> p1 = new List<IntPoint>();
List<IntPoint> p2 = new List<IntPoint>();
int i = 0, l = shape.Points.Length;
Vector2 pos = shape.BuiltGameObject.transform.position;
for(;i<l;++i)
{
IntPoint ip = new IntPoint(shape.Points[i].x + pos.x,shape.Points[i].y + pos.y);
p1.Add(ip);
}
p1.Add(p1[0]);
pos = secondShape.BuiltGameObject.transform.position;
i = 0; l = secondShape.Points.Length;
for(;i<l;++i)
{
IntPoint ip = new IntPoint(secondShape.Points[i].x + pos.x,secondShape.Points[i].y + pos.y);
p2.Add(ip);
}
p2.Add(p2[0]);
subj.Add(p1);
clip.Add(p2);
c.AddPaths(subj,PolyType.ptSubject,true);
c.AddPaths(clip,PolyType.ptClip,true);
c.Execute(ClipType.ctUnion,solution);
i = 0; l = solution[0].Count;
for(;i<l;++i)
{
float x = System.Convert.ToSingle(solution[0][i].X);
float y = System.Convert.ToSingle(solution[0][i].Y);
points.Add(new Vector2(x,y));
}
Mesh2D.Instance.ReBuild(shape.BuiltGameObject,points,completed,shape.Col);
return points;
}
示例14: Clip
public List<Polygon> Clip(Polygon p1, Polygon p2, OpType operation)
{
List<IntPoint> pol1 = new List<IntPoint>();
List<IntPoint> pol2 = new List<IntPoint>();
List<List<IntPoint>> res = new List<List<IntPoint>>();
foreach (Point point in p1.Points) {
pol1.Add(new IntPoint(point.X, point.Y));
}
foreach (Point point in p2.Points) {
pol2.Add(new IntPoint(point.X, point.Y));
}
Clipper clipper = new Clipper();
clipper.AddPolygon(pol1, PolyType.ptSubject);
clipper.AddPolygon(pol2, PolyType.ptClip);
switch (operation) {
case OpType.Difference:
clipper.Execute(ClipType.ctDifference, res);
break;
case OpType.Intersection:
clipper.Execute(ClipType.ctIntersection, res);
break;
case OpType.Union:
clipper.Execute(ClipType.ctUnion, res);
break;
case OpType.Xor:
clipper.Execute(ClipType.ctXor, res);
break;
}
List<Polygon> ret = new List<Polygon>();
foreach (var poly in res) {
Polygon pol = new Polygon() { Points = new List<Point>() };
foreach (var poi in poly) {
pol.Points.Add(new Point() { X = poi.X, Y = poi.Y });
}
ret.Add(pol);
}
return ret;
}
示例15: CombinePaths
private PathStorage CombinePaths(IVertexSource a, IVertexSource b, ClipType clipType)
{
List<List<IntPoint>> aPolys = VertexSourceToClipperPolygons.CreatePolygons(a);
List<List<IntPoint>> bPolys = VertexSourceToClipperPolygons.CreatePolygons(b);
Clipper clipper = new Clipper();
clipper.AddPaths(aPolys, PolyType.ptSubject, true);
clipper.AddPaths(bPolys, PolyType.ptClip, true);
List<List<IntPoint>> intersectedPolys = new List<List<IntPoint>>();
clipper.Execute(clipType, intersectedPolys);
PathStorage output = VertexSourceToClipperPolygons.CreatePathStorage(intersectedPolys);
output.Add(0, 0, ShapePath.FlagsAndCommand.CommandStop);
return output;
}