Esempio n. 1
0
        protected FillCurveSet2d ComputeFillPaths(GeneralPolygon2d poly, SegmentSet2d polyCache)
        {
            var stepSpans = ComputeSegments(poly, polyCache);

            // [TODO] need a pathfinder here, that can chain segments efficiently
            // (for now just do dumb things?)

            FillCurveSet2d paths = new FillCurveSet2d();

            foreach (var seglist in stepSpans)
            {
                foreach (Segment2d seg in seglist)
                {
                    // Discard paths that are too short
                    if (seg.Length < MinPathLengthMM)
                    {
                        continue;
                    }

                    var fill_seg = new FillCurve <FillSegment>()
                    {
                        FillType = FillType,
                    };
                    fill_seg.BeginCurve(seg.P0);
                    fill_seg.AddToCurve(seg.P1, new FillSegment());
                    paths.Append(fill_seg);
                }
            }

            return(paths);
        }
Esempio n. 2
0
        private FillCurveSet2d WalkPathGraph(DGraph2 pathGraph)
        {
            var boundaries = IdentifyBoundaryHashSet(pathGraph);

            var paths = new FillCurveSet2d();

            // walk paths from boundary vertices
            while (boundaries.Count > 0)
            {
                int start_vid = boundaries.First();
                boundaries.Remove(start_vid);
                int vid = start_vid;
                int eid = pathGraph.GetVtxEdges(vid)[0];

                var path = new FillCurve <FillSegment>()
                {
                    FillType = this.FillType
                };

                path.BeginCurve(pathGraph.GetVertex(vid));
                while (true)
                {
                    Index2i next = DGraph2Util.NextEdgeAndVtx(eid, vid, pathGraph);
                    eid = next.a;
                    vid = next.b;
                    int gid = pathGraph.GetEdgeGroup(eid);
                    if (gid < 0)
                    {
                        path.AddToCurve(pathGraph.GetVertex(vid), new FillSegment(true));
                    }
                    else
                    {
                        path.AddToCurve(pathGraph.GetVertex(vid));
                    }

                    if (boundaries.Contains(vid))
                    {
                        boundaries.Remove(vid);
                        break;
                    }
                }

                // discard paths that are too short
                if (path.TotalLength() < MinPathLengthMM)
                {
                    continue;
                }

                // run polyline simplification to get rid of unneccesary detail in connectors
                // [TODO] we could do this at graph level...)
                // [TODO] maybe should be checking for collisions? we could end up creating
                //  non-trivial overlaps here...
                if (SimplifyAmount != SimplificationLevel.None && path.Elements.Count > 1)
                {
                    path = SimplifyPath(path);
                }

                paths.Append(path);
            }
            return(paths);
        }