diff --git a/OpenNest.Engine/Fill/EndRowRefiller.cs b/OpenNest.Engine/Fill/EndRowRefiller.cs index 2660683d..9bd4fb42 100644 --- a/OpenNest.Engine/Fill/EndRowRefiller.cs +++ b/OpenNest.Engine/Fill/EndRowRefiller.cs @@ -185,7 +185,7 @@ namespace OpenNest.Engine.Fill for (var i = 0; i <= samples; i++) { var across = lo + (hi - lo) * i / samples; - var copy = StartBeyond(template, workArea, spacing, slide, across, vertical); + var copy = SlideStart.Beyond(template, workArea, spacing, slide, across, vertical); moving.Clear(); moving.Add(copy); var travel = Compactor.Push(moving, workArea, direction, obstacleSet); @@ -208,42 +208,6 @@ namespace OpenNest.Engine.Fill return best; } - /// - /// A copy of just beyond the work-area edge the slide - /// starts from, its inner bound at across the row. - /// - private static Part StartBeyond( - Part template, - Box workArea, - double spacing, - PushDirection slide, - double across, - bool vertical - ) - { - var box = template.BoundingBox; - var gap = spacing + 1.0; - double dx, dy; - if (vertical) - { - dy = across - box.Bottom; - dx = slide == PushDirection.Left - ? workArea.Right + gap - box.Left - : workArea.Left - gap - box.Right; - } - else - { - dx = across - box.Left; - dy = slide == PushDirection.Down - ? workArea.Top + gap - box.Bottom - : workArea.Bottom - gap - box.Top; - } - - var copy = template.CloneAtOffset(new Vector(dx, dy)); - copy.UpdateBounds(); - return copy; - } - /// How far the copy got: smaller is deeper along the slide. private static double LeadingEdge(Box box, PushDirection slide) => slide switch diff --git a/OpenNest.Engine/Fill/GridEndInserter.cs b/OpenNest.Engine/Fill/GridEndInserter.cs index 816b3a83..5cba38c1 100644 --- a/OpenNest.Engine/Fill/GridEndInserter.cs +++ b/OpenNest.Engine/Fill/GridEndInserter.cs @@ -206,7 +206,7 @@ namespace OpenNest.Engine.Fill void Try(Part template, double across) { - var copy = StartBeyond(template, area, spacing, slide, across, horizontal); + var copy = SlideStart.Beyond(template, area, spacing, slide, across, horizontal); moving.Clear(); moving.Add(copy); if (Compactor.Push(moving, area, direction, obstacles) <= 0) @@ -264,42 +264,6 @@ namespace OpenNest.Engine.Fill return best; } - /// - /// A copy of just beyond the area edge the slide starts from, - /// its lower bound across the slide at . - /// - private static Part StartBeyond( - Part template, - Box area, - double spacing, - PushDirection slide, - double across, - bool horizontal - ) - { - var box = template.BoundingBox; - var gap = spacing + 1.0; - double dx, dy; - if (horizontal) - { - dy = across - box.Bottom; - dx = slide == PushDirection.Left - ? area.Right + gap - box.Left - : area.Left - gap - box.Right; - } - else - { - dx = across - box.Left; - dy = slide == PushDirection.Down - ? area.Top + gap - box.Bottom - : area.Bottom - gap - box.Top; - } - - var copy = template.CloneAtOffset(new Vector(dx, dy)); - copy.UpdateBounds(); - return copy; - } - /// How far the copy got: smaller is deeper along the slide. private static double LeadingEdge(Box box, PushDirection slide) => slide switch diff --git a/OpenNest.Engine/Fill/SlideStart.cs b/OpenNest.Engine/Fill/SlideStart.cs new file mode 100644 index 00000000..c7e515e2 --- /dev/null +++ b/OpenNest.Engine/Fill/SlideStart.cs @@ -0,0 +1,51 @@ +using OpenNest.Geometry; + +namespace OpenNest.Engine.Fill +{ + /// Starting positions for copies slid into an area with a push. + internal static class SlideStart + { + /// + /// A copy of just beyond the area edge the slide starts from + /// (one part spacing plus one unit clear of it), its lower bound across the slide at + /// . + /// + /// + /// True when is or + /// : the copy's bottom goes to + /// and it starts beyond the area's right or left edge. False for an up/down slide: its left + /// goes to and it starts beyond the area's top or bottom edge. + /// + internal static Part Beyond( + Part template, + Box area, + double spacing, + PushDirection slide, + double across, + bool slideAlongX + ) + { + var box = template.BoundingBox; + var gap = spacing + 1.0; + double dx, dy; + if (slideAlongX) + { + dy = across - box.Bottom; + dx = slide == PushDirection.Left + ? area.Right + gap - box.Left + : area.Left - gap - box.Right; + } + else + { + dx = across - box.Left; + dy = slide == PushDirection.Down + ? area.Top + gap - box.Bottom + : area.Bottom - gap - box.Top; + } + + var copy = template.CloneAtOffset(new Vector(dx, dy)); + copy.UpdateBounds(); + return copy; + } + } +}