public static void CombinePaths( VertexStore a, VertexStore b, VxsClipperType vxsClipType, bool separateIntoSmallSubPaths, List <VertexStore> results) { using (VectorToolBox.Borrow(out VxsClipper clipper)) { clipper.CombinePathsInternal(a, b, vxsClipType, separateIntoSmallSubPaths, results); } }
// void CombinePathsInternal( VertexStore a, VertexStore b, VxsClipperType vxsClipType, bool separateIntoSmallSubPaths, List <VertexStore> resultList) { //prepare instance //reset all used fields ClipType clipType = (ClipType)vxsClipType; CreatePolygons(a, _aPolys); CreatePolygons(b, _bPolys); _clipper.AddPaths(_aPolys, PolyType.ptSubject, true); _clipper.AddPaths(_bPolys, PolyType.ptClip, true); _clipper.Execute(clipType, _intersectedPolys); if (separateIntoSmallSubPaths) { foreach (List <IntPoint> polygon in _intersectedPolys) { int j = polygon.Count; if (j > 0) { //first one IntPoint point = polygon[0]; using (VxsTemp.Borrow(out VertexStore v1)) using (VectorToolBox.Borrow(v1, out PathWriter pw)) { pw.MoveTo(point.X / 1000.0, point.Y / 1000.0); //next others ... if (j > 1) { for (int i = 1; i < j; ++i) { point = polygon[i]; pw.LineTo(point.X / 1000.0, point.Y / 1000.0); } } pw.CloseFigure(); resultList.Add(v1.CreateTrim()); //copy pw.Clear(); } } } } else { using (VxsTemp.Borrow(out VertexStore v1)) using (VectorToolBox.Borrow(v1, out PathWriter pw)) { foreach (List <IntPoint> polygon in _intersectedPolys) { int j = polygon.Count; if (j > 0) { //first one IntPoint point = polygon[0]; pw.MoveTo(point.X / 1000.0, point.Y / 1000.0); //next others ... if (j > 1) { for (int i = 1; i < j; ++i) { point = polygon[i]; pw.LineTo(point.X / 1000.0, point.Y / 1000.0); } } pw.CloseFigure(); } } pw.Stop(); resultList.Add(v1.CreateTrim()); } } }
// VertexStore CombinePathsInternal( VertexStore a, VertexStore b, VxsClipperType vxsClipType, bool separateIntoSmallSubPaths, List <VertexStore> resultList) { //prepare instance //reset all used fields ClipType clipType = (ClipType)vxsClipType; CreatePolygons(a, _aPolys); CreatePolygons(b, _bPolys); _clipper.AddPaths(_aPolys, PolyType.ptSubject, true); _clipper.AddPaths(_bPolys, PolyType.ptClip, true); _clipper.Execute(clipType, _intersectedPolys); if (separateIntoSmallSubPaths) { VertexStore firstOutput = null; //in this case we expect that resultList must not be null*** foreach (List <IntPoint> polygon in _intersectedPolys) { int j = polygon.Count; //*** if (j > 0) { //first one IntPoint point = polygon[0]; using (VxsTemp.Borrow(out VertexStore v1)) using (VectorToolBox.Borrow(v1, out PathWriter pw)) { pw.MoveTo(point.X / 1000.0, point.Y / 1000.0); //next others ... if (j > 1) { for (int i = 1; i < j; ++i) { point = polygon[i]; pw.LineTo(point.X / 1000.0, point.Y / 1000.0); } } pw.CloseFigure(); VertexStore result = v1.CreateTrim(); if (firstOutput == null) { firstOutput = result; } resultList.Add(result); //copy pw.Clear(); } } } return(firstOutput); } else { using (VxsTemp.Borrow(out var v1)) using (VectorToolBox.Borrow(v1, out PathWriter pw)) { foreach (List <IntPoint> polygon in _intersectedPolys) { int j = polygon.Count; if (j > 0) { //first one IntPoint point = polygon[0]; pw.MoveTo(point.X / 1000.0, point.Y / 1000.0); //next others ... if (j > 1) { for (int i = 1; i < j; ++i) { point = polygon[i]; pw.LineTo(point.X / 1000.0, point.Y / 1000.0); } } pw.CloseFigure(); } } pw.Stop(); VertexStore output = v1.CreateTrim(); if (resultList != null) { resultList.Add(output);//also add to here } return(output); } } }
public static List <VertexStore> CombinePaths(VertexStoreSnap a, VertexStoreSnap b, VxsClipperType vxsClipType, bool separateIntoSmallSubPaths) { //TODO: optimize here ClipType clipType = (ClipType)vxsClipType; 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); List <VertexStore> resultList = new List <VertexStore>(); PathWriter outputPathWriter = new PathWriter(); if (separateIntoSmallSubPaths) { foreach (List <IntPoint> polygon in intersectedPolys) { int j = polygon.Count; if (j > 0) { //first one IntPoint point = polygon[0]; outputPathWriter.MoveTo(point.X / 1000.0, point.Y / 1000.0); //next others ... if (j > 1) { for (int i = 1; i < j; ++i) { point = polygon[i]; outputPathWriter.LineTo(point.X / 1000.0, point.Y / 1000.0); } } outputPathWriter.CloseFigure(); resultList.Add(outputPathWriter.Vxs); //--- //clear outputPathWriter.ClearAndStartNewVxs(new VertexStore()); } } } else { foreach (List <IntPoint> polygon in intersectedPolys) { int j = polygon.Count; if (j > 0) { //first one IntPoint point = polygon[0]; outputPathWriter.MoveTo(point.X / 1000.0, point.Y / 1000.0); //next others ... if (j > 1) { for (int i = 1; i < j; ++i) { point = polygon[i]; outputPathWriter.LineTo(point.X / 1000.0, point.Y / 1000.0); } } outputPathWriter.CloseFigure(); } } //TODO: review here outputPathWriter.Stop(); resultList.Add(outputPathWriter.Vxs); } return(resultList); }
public static List <VertexStore> CombinePaths(VertexStoreSnap a, VertexStoreSnap b, VxsClipperType vxsClipType, bool separateIntoSmallSubPaths) { ClipType clipType = (ClipType)vxsClipType; 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); List <VertexStore> resultList = new List <VertexStore>(); PathWriter output = new PathWriter(); if (separateIntoSmallSubPaths) { foreach (List <IntPoint> polygon in intersectedPolys) { int j = polygon.Count; if (j > 0) { //first one IntPoint point = polygon[0]; output.MoveTo(point.X / 1000.0, point.Y / 1000.0); //next others ... if (j > 1) { for (int i = 1; i < j; ++i) { point = polygon[i]; output.LineTo(point.X / 1000.0, point.Y / 1000.0); } } output.CloseFigure(); resultList.Add(output.Vxs); //--- //clear output.ClearAndStartNewVxs(); } } } else { foreach (List <IntPoint> polygon in intersectedPolys) { int j = polygon.Count; if (j > 0) { //first one IntPoint point = polygon[0]; output.MoveTo(point.X / 1000.0, point.Y / 1000.0); //next others ... if (j > 1) { for (int i = 1; i < j; ++i) { point = polygon[i]; output.LineTo(point.X / 1000.0, point.Y / 1000.0); } } output.CloseFigure(); } //bool first = true; //foreach (IntPoint point in polygon) //{ // if (first) // { // output.AddVertex(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandMoveTo); // first = false; // } // else // { // output.AddVertex(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandLineTo); // } //} } output.Stop(); resultList.Add(output.Vxs); } return(resultList); }
public static List<VertexStore> CombinePaths(VertexStoreSnap a, VertexStoreSnap b, VxsClipperType vxsClipType, bool separateIntoSmallSubPaths) { ClipType clipType = (ClipType)vxsClipType; 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); List<VertexStore> resultList = new List<VertexStore>(); PathWriter output = new PathWriter(); if (separateIntoSmallSubPaths) { foreach (List<IntPoint> polygon in intersectedPolys) { int j = polygon.Count; if (j > 0) { //first one IntPoint point = polygon[0]; output.MoveTo(point.X / 1000.0, point.Y / 1000.0); //next others ... if (j > 1) { for (int i = 1; i < j; ++i) { point = polygon[i]; output.LineTo(point.X / 1000.0, point.Y / 1000.0); } } output.CloseFigure(); resultList.Add(output.Vxs); //--- //clear output.ClearAndStartNewVxs(new VertexStore()); } } } else { foreach (List<IntPoint> polygon in intersectedPolys) { int j = polygon.Count; if (j > 0) { //first one IntPoint point = polygon[0]; output.MoveTo(point.X / 1000.0, point.Y / 1000.0); //next others ... if (j > 1) { for (int i = 1; i < j; ++i) { point = polygon[i]; output.LineTo(point.X / 1000.0, point.Y / 1000.0); } } output.CloseFigure(); } //bool first = true; //foreach (IntPoint point in polygon) //{ // if (first) // { // output.AddVertex(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandMoveTo); // first = false; // } // else // { // output.AddVertex(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandLineTo); // } //} } output.Stop(); resultList.Add(output.Vxs); } return resultList; }