Ejemplo n.º 1
0
        //------------------------------------------------------------------------------

        public static void AddPolyNodeToPolygons(PolyNode polynode, PolygonsClp polygons)
        {
            if (polynode.Contour.Count > 0)
                polygons.Add(polynode.Contour);
            foreach (PolyNode pn in polynode.Childs)
                AddPolyNodeToPolygons(pn, polygons);
        }
Ejemplo n.º 2
0
        //------------------------------------------------------------------------------

        public static PolygonsClp OffsetPolyLines(PolygonsClp lines,
          double delta, JoinType jointype, EndType endtype,
          double limit)
        {
            PolygonsClp result = new PolygonsClp();

            //automatically strip duplicate points because it gets complicated with
            //open and closed lines and when to strip duplicates across begin-end ...
            PolygonsClp pts = new PolygonsClp(lines);
            for (int i = 0; i < pts.Count; ++i)
            {
                for (int j = pts[i].Count - 1; j > 0; j--)
                    if (PointsEqual(pts[i][j], pts[i][j - 1]))
                        pts[i].RemoveAt(j);
            }

            if (endtype == EndType.etClosed)
            {
                int sz = pts.Count;
                pts.Capacity = sz * 2;
                for (int i = 0; i < sz; ++i)
                {
                    PolygonClp line = new PolygonClp(pts[i]);
                    line.Reverse();
                    pts.Add(line);
                }
                new PolyOffsetBuilder(pts, result, true, delta, jointype, endtype, limit);
            }
            else
                new PolyOffsetBuilder(pts, result, false, delta, jointype, endtype, limit);

            return result;
        }
Ejemplo n.º 3
0
        //------------------------------------------------------------------------------

        public static PolygonsClp CleanPolygons(PolygonsClp polys,
            double distance = 1.415)
        {
            PolygonsClp result = new PolygonsClp(polys.Count);
            for (int i = 0; i < polys.Count; i++)
                result.Add(CleanPolygon(polys[i], distance));
            return result;
        }
Ejemplo n.º 4
0
        //------------------------------------------------------------------------------

        private void BuildResult(PolygonsClp polyg)
        {
            polyg.Clear();
            polyg.Capacity = m_PolyOuts.Count;
            for (int i = 0; i < m_PolyOuts.Count; i++)
            {
                OutRec outRec = m_PolyOuts[i];
                if (outRec.pts == null) continue;
                OutPt p = outRec.pts;
                int cnt = PointCount(p);
                if (cnt < 3) continue;
                PolygonClp pg = new PolygonClp(cnt);
                for (int j = 0; j < cnt; j++)
                {
                    pg.Add(p.pt);
                    p = p.prev;
                }
                polyg.Add(pg);
            }
        }