Example #1
0
        protected FillCurveSet2d ComputeFillPaths(GeneralPolygon2d poly, SegmentSet2d polyCache)
        {
            List <List <Segment2d> > StepSpans = ComputeSegments(poly, polyCache);
            int N = StepSpans.Count;

            //double hard_max_dist = 5 * PathSpacing;

            // [TODO] need a pathfinder here, that can chain segments efficiently

            // (for now just do dumb things?)

            FillCurveSet2d paths = new FillCurveSet2d();

            //FillPolyline2d cur = new FillPolyline2d();

            foreach (var seglist in StepSpans)
            {
                foreach (Segment2d seg in seglist)
                {
                    FillPolyline2d fill_seg = new FillPolyline2d()
                    {
                        TypeFlags = FillTypeFlags.SolidInfill
                    };
                    fill_seg.AppendVertex(seg.P0);
                    fill_seg.AppendVertex(seg.P1);
                    paths.Append(fill_seg);
                }
            }

            return(paths);
        }
Example #2
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);
        }
Example #3
0
        protected List <List <Segment2d> > ComputeSegments(GeneralPolygon2d poly, SegmentSet2d polyCache)
        {
            List <List <Segment2d> > PerRaySpans = new List <List <Segment2d> >();

            double   angleRad = AngleDeg * MathUtil.Deg2Rad;
            Vector2d dir      = new Vector2d(Math.Cos(angleRad), Math.Sin(angleRad));

            // compute projection span along axis
            Vector2d   axis         = dir.Perp;
            Interval1d axisInterval = Interval1d.Empty;
            Interval1d dirInterval  = Interval1d.Empty;

            foreach (Vector2d v in poly.Outer.Vertices)
            {
                dirInterval.Contain(v.Dot(dir));
                axisInterval.Contain(v.Dot(axis));
            }
            // [TODO] also check holes? or assume they are contained?

            dirInterval.a -= 10 * ToolWidth;
            dirInterval.b += 10 * ToolWidth;
            double extent = dirInterval.Length;

            axisInterval.a += ToolWidth * 0.1 + PathShift;
            axisInterval.b -= ToolWidth * 0.1;
            if (axisInterval.b < axisInterval.a)
            {
                return(PerRaySpans);                            // [RMS] is this right? I guess so. interval is too small to fill?
            }
            Vector2d startCorner = axisInterval.a * axis + dirInterval.a * dir;
            double   range       = axisInterval.Length;
            int      N           = (int)(range / PathSpacing);

            for (int ti = 0; ti <= N; ++ti)
            {
                double    t   = (double)ti / (double)N;
                Vector2d  o   = startCorner + (t * range) * axis;
                Segment2d ray = new Segment2d(o, o + extent * dir);

                List <Segment2d> spans = compute_polygon_ray_spans(poly, ray, startCorner, axis, t, polyCache);
                PerRaySpans.Add(spans);
            }

            return(PerRaySpans);
        }
Example #4
0
        public bool Compute()
        {
            if (InsetFromInputPolygon)
            {
                BoundaryPolygonCache = new SegmentSet2d(Polygon);
                List <GeneralPolygon2d> current = ClipperUtil.ComputeOffsetPolygon(Polygon, -ToolWidth / 2, true);
                foreach (GeneralPolygon2d poly in current)
                {
                    SegmentSet2d polyCache = new SegmentSet2d(poly);
                    Paths.Add(ComputeFillPaths(poly, polyCache));
                }
            }
            else
            {
                List <GeneralPolygon2d> boundary = ClipperUtil.ComputeOffsetPolygon(Polygon, ToolWidth / 2, true);
                BoundaryPolygonCache = new SegmentSet2d(boundary);

                SegmentSet2d polyCache = new SegmentSet2d(Polygon);
                Paths.Add(ComputeFillPaths(Polygon, polyCache));
            }

            return(true);
        }
Example #5
0
 protected FillCurveSet2d ComputeFillPaths(GeneralPolygon2d poly, SegmentSet2d polyCache)
 {
     return(null);
 }
Example #6
0
        // yikes not robust at all!!
        protected List <Segment2d> compute_polygon_ray_spans(GeneralPolygon2d poly, Segment2d ray, Vector2d axis_origin, Vector2d axis, double axisT, SegmentSet2d segments)
        {
            List <double> hits = new List <double>();               // todo reusable buffer

            segments.FindAllIntersections(ray, hits, null, null, false);
            hits.Sort();

            bool clean = true;

            for (int i = 0; i < hits.Count - 1 && clean; ++i)
            {
                if (hits[i + 1] - hits[i] < MathUtil.Epsilonf)
                {
                    clean = false;
                }
            }
            if (!clean)
            {
                hits = extract_valid_segments(poly, ray, hits);
            }

            if (hits.Count % 2 != 0)
            {
                throw new Exception("DenseLineFill.ComputeAllSpans: have not handled hard cases...");
            }

            List <Segment2d> spans = new List <Segment2d>();

            for (int i = 0; i < hits.Count / 2; ++i)
            {
                Vector2d p0 = ray.PointAt(hits[2 * i]);
                Vector2d p1 = ray.PointAt(hits[2 * i + 1]);
                spans.Add(new Segment2d(p0, p1));
            }

            return(spans);
        }