//------------------------------------------------------------------------------ public void Execute(ref PolyTree solution, double delta) { solution.Clear(); FixOrientations(); DoOffset(delta); //now clean up 'corners' ... Clipper clpr = new Clipper(); clpr.AddPaths(m_destPolys, PolyType.ptSubject, true); if (delta > 0) { clpr.Execute(ClipType.ctUnion, solution, PolyFillType.pftPositive, PolyFillType.pftPositive); } else { IntRect r = Clipper.GetBounds(m_destPolys); List <IntPoint> outer = new List <IntPoint>(4); outer.Add(new IntPoint(r.left - 10, r.bottom + 10)); outer.Add(new IntPoint(r.right + 10, r.bottom + 10)); outer.Add(new IntPoint(r.right + 10, r.top - 10)); outer.Add(new IntPoint(r.left - 10, r.top - 10)); clpr.AddPath(outer, PolyType.ptSubject, true); clpr.ReverseSolution = true; clpr.Execute(ClipType.ctUnion, solution, PolyFillType.pftNegative, PolyFillType.pftNegative); //remove the outer PolyNode rectangle ... if (solution.ChildCount == 1 && solution.Childs[0].ChildCount > 0) { PolyNode outerNode = solution.Childs[0]; solution.Childs.Capacity = outerNode.ChildCount; solution.Childs[0] = outerNode.Childs[0]; solution.Childs[0].m_Parent = solution; for (int i = 1; i < outerNode.ChildCount; i++) { solution.AddChild(outerNode.Childs[i]); } } else { solution.Clear(); } } }
public void Execute(ref PolyTree solution, double delta) { solution.Clear(); FixOrientations(); DoOffset(delta); Clipper clipper = new Clipper(0); clipper.AddPaths(m_destPolys, PolyType.ptSubject, true); if (delta > 0.0) { clipper.Execute(ClipType.ctUnion, solution, PolyFillType.pftPositive, PolyFillType.pftPositive); } else { IntRect bounds = ClipperBase.GetBounds(m_destPolys); List <IntPoint> list = new List <IntPoint>(4); list.Add(new IntPoint(bounds.left - 10, bounds.bottom + 10)); list.Add(new IntPoint(bounds.right + 10, bounds.bottom + 10)); list.Add(new IntPoint(bounds.right + 10, bounds.top - 10)); list.Add(new IntPoint(bounds.left - 10, bounds.top - 10)); clipper.AddPath(list, PolyType.ptSubject, true); clipper.ReverseSolution = true; clipper.Execute(ClipType.ctUnion, solution, PolyFillType.pftNegative, PolyFillType.pftNegative); if (solution.ChildCount == 1 && solution.Childs[0].ChildCount > 0) { PolyNode polyNode = solution.Childs[0]; solution.Childs.Capacity = polyNode.ChildCount; solution.Childs[0] = polyNode.Childs[0]; solution.Childs[0].m_Parent = solution; for (int i = 1; i < polyNode.ChildCount; i++) { solution.AddChild(polyNode.Childs[i]); } } else { solution.Clear(); } } }
//------------------------------------------------------------------------------ private void BuildResult2(PolyTree polytree) { polytree.Clear(); //add each output polygon/contour to polytree ... polytree.m_AllPolys.Capacity = m_PolyOuts.Count; for (int i = 0; i < m_PolyOuts.Count; i++) { OutRec outRec = m_PolyOuts[i]; int cnt = PointCount(outRec.pts); if (cnt < 3) continue; FixHoleLinkage(outRec); PolyNode pn = new PolyNode(); polytree.m_AllPolys.Add(pn); outRec.polyNode = pn; pn.m_polygon.Capacity = cnt; OutPt op = outRec.pts; for (int j = 0; j < cnt; j++) { pn.m_polygon.Add(op.pt); op = op.prev; } } //fixup PolyNode links etc ... polytree.m_Childs.Capacity = m_PolyOuts.Count; for (int i = 0; i < m_PolyOuts.Count; i++) { OutRec outRec = m_PolyOuts[i]; if (outRec.polyNode == null) continue; if (outRec.FirstLeft == null) polytree.AddChild(outRec.polyNode); else outRec.FirstLeft.polyNode.AddChild(outRec.polyNode); } }
//------------------------------------------------------------------------------ private void BuildResult2(PolyTree polytree) { polytree.Clear(); //add each output polygon/contour to polytree ... polytree.m_AllPolys.Capacity = m_PolyOuts.Count; for (int i = 0; i < m_PolyOuts.Count; i++) { OutRec outRec = m_PolyOuts[i]; int cnt = PointCount(outRec.Pts); if ((outRec.IsOpen && cnt < 2) || (!outRec.IsOpen && cnt < 3)) continue; FixHoleLinkage(outRec); PolyNode pn = new PolyNode(); polytree.m_AllPolys.Add(pn); outRec.PolyNode = pn; pn.m_polygon.Capacity = cnt; OutPt op = outRec.Pts.Prev; for (int j = 0; j < cnt; j++) { pn.m_polygon.Add(op.Pt); op = op.Prev; } } //fixup PolyNode links etc ... polytree.m_Childs.Capacity = m_PolyOuts.Count; for (int i = 0; i < m_PolyOuts.Count; i++) { OutRec outRec = m_PolyOuts[i]; if (outRec.PolyNode == null) continue; else if (outRec.IsOpen) { outRec.PolyNode.IsOpen = true; polytree.AddChild(outRec.PolyNode); } else if (outRec.FirstLeft != null && outRec.FirstLeft.PolyNode != null) outRec.FirstLeft.PolyNode.AddChild(outRec.PolyNode); else polytree.AddChild(outRec.PolyNode); } }
//------------------------------------------------------------------------------ public void Execute(ref PolyTree solution, double delta) { solution.Clear(); FixOrientations(); DoOffset(delta); //now clean up 'corners' ... Clipper clpr = new Clipper(); clpr.AddPaths(m_destPolys, PolyType.ptSubject, true); if (delta > 0) { clpr.Execute(ClipType.ctUnion, solution, PolyFillType.pftPositive, PolyFillType.pftPositive); } else { IntRect r = Clipper.GetBounds(m_destPolys); List<IntPoint> outer = new List<IntPoint>(4); outer.Add(new IntPoint(r.left - 10, r.bottom + 10)); outer.Add(new IntPoint(r.right + 10, r.bottom + 10)); outer.Add(new IntPoint(r.right + 10, r.top - 10)); outer.Add(new IntPoint(r.left - 10, r.top - 10)); clpr.AddPath(outer, PolyType.ptSubject, true); clpr.ReverseSolution = true; clpr.Execute(ClipType.ctUnion, solution, PolyFillType.pftNegative, PolyFillType.pftNegative); //remove the outer PolyNode rectangle ... if (solution.ChildCount == 1 && solution.Childs[0].ChildCount > 0) { PolyNode outerNode = solution.Childs[0]; solution.Childs.Capacity = outerNode.ChildCount; solution.Childs[0] = outerNode.Childs[0]; solution.Childs[0].m_Parent = solution; for (int i = 1; i < outerNode.ChildCount; i++) solution.AddChild(outerNode.Childs[i]); } else solution.Clear(); } }