feat: add FillLinear class with geometry-aware copy distance

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 00:54:06 -05:00
parent f4779b878c
commit b8d9155cd0
2 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
using System.Collections.Generic;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest
{
public class FillLinear
{
public FillLinear(Box workArea, double partSpacing)
{
WorkArea = workArea;
PartSpacing = partSpacing;
}
public Box WorkArea { get; }
public double PartSpacing { get; }
/// <summary>
/// Finds the geometry-aware copy distance between two identical parts along an axis.
/// Places part B at bounding box offset from part A, then pushes B back toward A
/// using directional distance to find the tightest non-overlapping position.
/// </summary>
private double FindCopyDistance(Part partA, NestDirection direction)
{
var bbox = partA.BoundingBox;
double bboxDim;
PushDirection pushDir;
Vector copyOffset;
if (direction == NestDirection.Horizontal)
{
bboxDim = bbox.Width;
pushDir = PushDirection.Left;
copyOffset = new Vector(bboxDim, 0);
}
else
{
bboxDim = bbox.Height;
pushDir = PushDirection.Down;
copyOffset = new Vector(0, bboxDim);
}
// Create part B offset by bounding box dimension (guaranteed no overlap).
var partB = (Part)partA.Clone();
partB.Offset(copyOffset);
// Get geometry lines for push calculation.
var opposite = Helper.OppositeDirection(pushDir);
var movingLines = PartSpacing > 0
? Helper.GetOffsetPartLines(partB, PartSpacing, pushDir)
: Helper.GetPartLines(partB, pushDir);
var stationaryLines = Helper.GetPartLines(partA, opposite);
// Find how far B can slide toward A.
var slideDistance = Helper.DirectionalDistance(movingLines, stationaryLines, pushDir);
if (slideDistance >= double.MaxValue || slideDistance < 0)
return bboxDim;
return bboxDim - slideDistance;
}
}
}

View File

@@ -42,6 +42,7 @@
<Compile Include="CirclePacking\FillEndOdd.cs" />
<Compile Include="CirclePacking\FillEngine.cs" />
<Compile Include="CirclePacking\Item.cs" />
<Compile Include="FillLinear.cs" />
<Compile Include="NestDirection.cs" />
<Compile Include="NestEngine.cs" />
<Compile Include="NestItem.cs" />