public Slice_sequence Run(List <Point2F> points, double tool_r, double slice_radius, RotationDirection dir) { Slice root_slice = new Slice(points[0], slice_radius, dir == RotationDirection.Unknown ? RotationDirection.CCW : dir); _sequence.Add(root_slice); for (int i = 1; i < points.Count; i++) { Slice new_slice = new Slice(_sequence.Last_slice, points[i], slice_radius, dir, tool_r, _sequence.Last_slice.End); if (new_slice.Placement != Slice_placement.NORMAL) { throw new Exception("bad slice placement"); } if (true) { new_slice.Refine(_sequence.Find_slices_colliding_with(new_slice), tool_r, tool_r); } if (i == 1) { Logger.log("changing startpoint of root slice"); _sequence.Root_slice.Change_startpoint(new_slice.Start); new_slice.Append_leadin_and_leadout(0, Slice_leadout_angle); } else { new_slice.Append_leadin_and_leadout(Slice_leadin_angle, Slice_leadout_angle); } _sequence.Add(new_slice); } return(_sequence); }
private void trace_branch(Branch branch, Slice parent_slice) { double t = 0; while (true) { Slice new_slice = null; branch.Bisect(pt => evaluate_possible_slice(parent_slice, pt, ref new_slice), ref t, _general_tolerance); if (new_slice == null) { break; } if (new_slice.Max_ted < _min_ted) // discard slice if outside the specified min TED { break; } // discard slice if outside the final allowed percentage double err = (new_slice.Max_ted - _max_ted) / _max_ted; if (err > FINAL_ALLOWED_TED_OVERSHOOT_PERCENTAGE) { Logger.warn("failed to create slice within stepover limit. stopping slicing the branch"); break; } // if last slice was a root slice, adjust root slice startpoint to remove extra travel and // append leadout to the candindate. leadin is not needed, since join with root will be exact // otherwise append both leadin and leadout if (_sequence.Last_slice == _sequence.Root_slice) { Logger.log("changing startpoint of root slice"); _sequence.Root_slice.Change_startpoint(new_slice.Start); new_slice.Append_leadin_and_leadout(0, Slice_leadout_angle); } else { new_slice.Append_leadin_and_leadout(Slice_leadin_angle, Slice_leadout_angle); } // generate guide move if this slice is not a simple continuation if (parent_slice != _sequence.Last_slice) { new_slice.Guide = _sequence.Trace_branch_switch(new_slice, _sequence.Last_slice); } _sequence.Add(new_slice); parent_slice = new_slice; } // need to go deeper foreach (Branch b in branch.Children) { trace_branch(b, parent_slice); } }