当前位置: 首页>>代码示例>>C#>>正文


C# Clipper.AddPaths方法代码示例

本文整理汇总了C#中ClipperLib.Clipper.AddPaths方法的典型用法代码示例。如果您正苦于以下问题:C# Clipper.AddPaths方法的具体用法?C# Clipper.AddPaths怎么用?C# Clipper.AddPaths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ClipperLib.Clipper的用法示例。


在下文中一共展示了Clipper.AddPaths方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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;
    }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:32,代码来源:ClipperTools.cs

示例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;
    }
开发者ID:Cyberbanan,项目名称:Unity-2D-Destruction,代码行数:26,代码来源:ClipperHelper.cs

示例3: 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);
    }
开发者ID:fjnoyp,项目名称:2dMultiplayerGame-150-hours,代码行数:29,代码来源:PolyClipper.cs

示例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;
 }
开发者ID:sverreeh,项目名称:clipper,代码行数:10,代码来源:Tester.cs

示例5: 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);
 }
开发者ID:sverreeh,项目名称:clipper,代码行数:11,代码来源:Tester.cs

示例6: 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;
        }
开发者ID:Sthephanfelix,项目名称:LeagueSharp-4,代码行数:19,代码来源:ClipperWrapper.cs

示例7: ClipPolygons

 public static Paths ClipPolygons(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.pftEvenOdd);
     return solution;
 }
开发者ID:654955321,项目名称:HY_Recommend,代码行数:16,代码来源:MyGeometry.cs

示例8: 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;
        }
开发者ID:DarrenTsung,项目名称:behavior-tree-game,代码行数:47,代码来源:MeshExtensions.cs

示例9: 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;
		}
开发者ID:glocklueng,项目名称:agg-sharp,代码行数:19,代码来源:PolygonClipping.cs

示例10: 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;
    }
开发者ID:zhutaorun,项目名称:unity-drawline,代码行数:55,代码来源:MeshAreaTest.cs

示例11: GenerateLinePaths

		public static void GenerateLinePaths(Polygons polygonToInfill, ref Polygons infillLinesToPrint, int lineSpacing, int infillExtendIntoPerimeter_um, double rotation, long rotationOffset = 0)
		{
			if (polygonToInfill.Count > 0)
			{
				Polygons outlines = polygonToInfill.Offset(infillExtendIntoPerimeter_um);
				if (outlines.Count > 0)
				{
					PointMatrix matrix = new PointMatrix(-(rotation + 90)); // we are rotating the part so we rotate by the negative so the lines go the way we expect

					outlines.ApplyMatrix(matrix);

					Aabb boundary = new Aabb(outlines);

					boundary.min.X = ((boundary.min.X / lineSpacing) - 1) * lineSpacing - rotationOffset;
					int xLineCount = (int)((boundary.max.X - boundary.min.X + (lineSpacing - 1)) / lineSpacing);
					Polygons unclipedPatern = new Polygons();

					long firstX = boundary.min.X / lineSpacing * lineSpacing;
					for (int lineIndex = 0; lineIndex < xLineCount; lineIndex++)
					{
						Polygon line = new Polygon();
						line.Add(new IntPoint(firstX + lineIndex * lineSpacing, boundary.min.Y));
						line.Add(new IntPoint(firstX + lineIndex * lineSpacing, boundary.max.Y));
						unclipedPatern.Add(line);
					}

					PolyTree ret = new PolyTree();
					Clipper clipper = new Clipper();
					clipper.AddPaths(unclipedPatern, PolyType.ptSubject, false);
					clipper.AddPaths(outlines, PolyType.ptClip, true);
					clipper.Execute(ClipType.ctIntersection, ret, PolyFillType.pftPositive, PolyFillType.pftEvenOdd);

					Polygons newSegments = Clipper.OpenPathsFromPolyTree(ret);
					PointMatrix inversematrix = new PointMatrix((rotation + 90));
					newSegments.ApplyMatrix(inversematrix);

					infillLinesToPrint.AddRange(newSegments);
				}
			}
		}
开发者ID:GearWalker,项目名称:MatterSlice,代码行数:40,代码来源:infill.cs

示例12: CombinePaths

		private PathStorage CombinePaths(IVertexSource a, IVertexSource b, ClipType clipType)
		{
			List<List<IntPoint>> aPolys = CreatePolygons(a);
			List<List<IntPoint>> bPolys = 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 = new PathStorage();

			foreach (List<IntPoint> polygon in intersectedPolys)
			{
				bool first = true;
				foreach (IntPoint point in polygon)
				{
					if (first)
					{
						output.Add(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandMoveTo);
						first = false;
					}
					else
					{
						output.Add(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandLineTo);
					}
				}

				output.ClosePolygon();
			}

			output.Add(0, 0, ShapePath.FlagsAndCommand.CommandStop);

			return output;
		}
开发者ID:CNCBrasil,项目名称:agg-sharp,代码行数:38,代码来源:PolygonClipping.cs

示例13: Clip

        public void Clip(double x0, double x1, double y0, double y1)
        {
            var p00 = new Point3d(x0, y0, 0.0);
            var p01 = new Point3d(x0, y1, 0.0);
            var p11 = new Point3d(x1, y1, 0.0);
            var p10 = new Point3d(x1, y0, 0.0);

            var clip = new[] { p00, p10, p11, p01, p00 }.ToPolygon(Plane.WorldXY, Unit);

            var clipper = new Clipper();

            clipper.AddPaths(Polygons, PolyType.ptSubject, true);
            clipper.AddPath(clip, PolyType.ptClip, true);

            var solution = new List<List<IntPoint>>();

            clipper.Execute(ClipType.ctIntersection, solution, PolyFillType.pftEvenOdd, PolyFillType.pftNonZero);

            Polygons = solution;
            Curves = Polygons.ToCurves(Plane, Unit);
        }
开发者ID:olitur,项目名称:Bowerbird,代码行数:21,代码来源:SlitPlane.cs

示例14: TestCliper

        private static void TestCliper()
        {
            Paths subj = new Paths(2);
            subj.Add(new Path(4));
            subj[0].Add(new IntPoint(180, 200));
            subj[0].Add(new IntPoint(260, 200));
            subj[0].Add(new IntPoint(260, 150));
            subj[0].Add(new IntPoint(180, 150));

            subj.Add(new Path(3));
            subj[1].Add(new IntPoint(215, 160));
            subj[1].Add(new IntPoint(230, 190));
            subj[1].Add(new IntPoint(200, 190));

            Paths clip = new Paths(1);
            clip.Add(new Path(4));
            clip[0].Add(new IntPoint(190, 210));
            clip[0].Add(new IntPoint(240, 210));
            clip[0].Add(new IntPoint(240, 130));
            clip[0].Add(new IntPoint(190, 130));

            //DrawPolygons(subj, Color.FromArgb(0x16, 0, 0, 0xFF),
            //  Color.FromArgb(0x60, 0, 0, 0xFF));
            //DrawPolygons(clip, Color.FromArgb(0x20, 0xFF, 0xFF, 0),
            //  Color.FromArgb(0x30, 0xFF, 0, 0));

            Paths solution = new Paths();

            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);
            //DrawPolygons(solution, Color.FromArgb(0x30, 0, 0xFF, 0),
            //  Color.FromArgb(0xFF, 0, 0x66, 0));
        }
开发者ID:necdnk,项目名称:Kisslicer_Bridges,代码行数:36,代码来源:Program.cs

示例15: InterceptionQ

        private static void InterceptionQ(Obj_AI_Hero Enemy)
        {
            Geometry.Polygon.Circle Qspellpoly = new Geometry.Polygon.Circle(PreCastPos(Enemy, 0.6f), 130f);

            Paths subjs = new Paths();
            foreach (var bla in WPPolygon(Enemy).ToPolygons())
            {
                subjs.Add(bla.ToClipperPath());
            }

            Paths clips = new Paths(1);
            clips.Add(Qspellpoly.ToClipperPath());

            Paths solution = new Paths();
            Clipper c = new Clipper();
            c.AddPaths(subjs, PolyType.ptSubject, true);
            c.AddPaths(clips, PolyType.ptClip, true);
            c.Execute(ClipType.ctIntersection, solution);

            foreach (var bli in solution.ToPolygons())
            {
                bli.Draw(System.Drawing.Color.Blue);
            }
        }
开发者ID:BaFuSs,项目名称:test,代码行数:24,代码来源:Program.cs


注:本文中的ClipperLib.Clipper.AddPaths方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。