refactor: use ShapeProfile perimeter for boundary and intersection

Replace shape-list iteration with ShapeProfile.Perimeter in both
Part.Intersects and PartBoundary, simplifying the logic and ensuring
only the outermost contour is used for collision detection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-14 12:41:03 -04:00
parent 65ded42120
commit a9aaab8337
2 changed files with 29 additions and 31 deletions

View File

@@ -149,31 +149,25 @@ namespace OpenNest
pts = new List<Vector>();
var entities1 = ConvertProgram.ToGeometry(Program)
.Where(e => e.Layer != SpecialLayers.Rapid);
.Where(e => e.Layer != SpecialLayers.Rapid)
.ToList();
var entities2 = ConvertProgram.ToGeometry(part.Program)
.Where(e => e.Layer != SpecialLayers.Rapid);
.Where(e => e.Layer != SpecialLayers.Rapid)
.ToList();
var shapes1 = Helper.GetShapes(entities1);
var shapes2 = Helper.GetShapes(entities2);
if (entities1.Count == 0 || entities2.Count == 0)
return false;
shapes1.ForEach(shape => shape.Offset(Location));
shapes2.ForEach(shape => shape.Offset(part.Location));
var perimeter1 = new ShapeProfile(entities1).Perimeter;
var perimeter2 = new ShapeProfile(entities2).Perimeter;
for (int i = 0; i < shapes1.Count; i++)
{
var shape1 = shapes1[i];
if (perimeter1 == null || perimeter2 == null)
return false;
for (int j = 0; j < shapes2.Count; j++)
{
var shape2 = shapes2[j];
List<Vector> pts2;
perimeter1.Offset(Location);
perimeter2.Offset(part.Location);
if (shape1.Intersects(shape2, out pts2))
pts.AddRange(pts2);
}
}
return pts.Count > 0;
return perimeter1.Intersects(perimeter2, out pts);
}
public double Left