protected virtual ElementLocation FindLoopEntryPoint(FillLoop poly, Vector2d currentPos2)
        {
            int startIndex;

            if (Settings.Part.ZipperAlignedToPoint && poly.FillType.IsEntryLocationSpecified())
            {
                // split edges to position zipper closer to the desired point?
                // TODO: Enter midsegment
                Vector2d zipperLocation = new Vector2d(Settings.Part.ZipperLocationX, Settings.Part.ZipperLocationY);
                startIndex = CurveUtils2.FindNearestVertex(zipperLocation, poly.Vertices(true));
            }
            else if (Settings.Part.ShellRandomizeStart && poly.FillType.IsEntryLocationSpecified())
            {
                // split edges for a actual random location along the perimeter instead of a random vertex?
                Random rnd = new Random();
                startIndex = rnd.Next(poly.ElementCount);
            }
            else
            {
                // use the vertex closest to the current nozzle position
                startIndex = CurveUtils2.FindNearestVertex(currentPos2, poly.Vertices(true));
            }

            return(new ElementLocation(startIndex, 0));
        }
 protected virtual void BuildLoop(FillLoop loop, double useSpeed)
 {
     if (!(loop is FillLoop <FillSegment> o))
     {
         throw new NotImplementedException($"FillPathScheduler2d does not support type {loop.GetType()}.");
     }
     BuildLoopConcrete(o, useSpeed);
 }
 protected virtual FillLoop SelectLoopDirection(FillLoop loop)
 {
     if (loop.IsHoleShell != loop.IsClockwise())
     {
         return(loop.Reversed());
     }
     return(loop);
 }
        // [TODO] no reason we couldn't start on edge midpoint??
        public virtual void AppendFillLoop(FillLoop loop)
        {
            AssertValidLoop(loop);

            var oriented = SelectLoopDirection(loop);
            var rolled   = SelectLoopEntry(oriented, Builder.Position.xy);

            AppendTravel(Builder.Position.xy, rolled.Entry);

            double useSpeed = SelectSpeed(rolled);

            BuildLoop(rolled, useSpeed);
        }
        protected void AssertValidLoop(FillLoop curve)
        {
            int N = curve.ElementCount;

            if (N < 2)
            {
                StackFrame frame  = new StackFrame(1);
                var        method = frame.GetMethod();
                var        type   = method.DeclaringType;
                var        name   = method.Name;
                throw new ArgumentException($"{type}.{name}: degenerate loop; must have at least 2 edges");
            }
        }
Exemple #6
0
 public void Append(FillLoop loop)
 {
     Loops.Add(loop);
 }
        protected virtual FillLoop SelectLoopEntry(FillLoop loop, Vector2d currentPosition)
        {
            var location = FindLoopEntryPoint(loop, currentPosition);

            return(loop.RollBetweenVertices(location));
        }
 protected virtual void BuildLoopConcrete <TSegment>(FillLoop <TSegment> rolled, double useSpeed) where TSegment : IFillSegment, new()
 {
     Builder.AppendExtrude(rolled.Vertices(true).ToList(), useSpeed, rolled.FillType, null);
 }