feat: guard Plate quantity/utilization/overlap for IsCutOff parts
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -52,12 +52,14 @@ namespace OpenNest
|
|||||||
|
|
||||||
private void Parts_PartAdded(object sender, ItemAddedEventArgs<Part> e)
|
private void Parts_PartAdded(object sender, ItemAddedEventArgs<Part> e)
|
||||||
{
|
{
|
||||||
e.Item.BaseDrawing.Quantity.Nested += Quantity;
|
if (!e.Item.BaseDrawing.IsCutOff)
|
||||||
|
e.Item.BaseDrawing.Quantity.Nested += Quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Parts_PartRemoved(object sender, ItemRemovedEventArgs<Part> e)
|
private void Parts_PartRemoved(object sender, ItemRemovedEventArgs<Part> e)
|
||||||
{
|
{
|
||||||
e.Item.BaseDrawing.Quantity.Nested -= Quantity;
|
if (!e.Item.BaseDrawing.IsCutOff)
|
||||||
|
e.Item.BaseDrawing.Quantity.Nested -= Quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -454,24 +456,23 @@ namespace OpenNest
|
|||||||
/// <returns>Returns a number between 0.0 and 1.0</returns>
|
/// <returns>Returns a number between 0.0 and 1.0</returns>
|
||||||
public double Utilization()
|
public double Utilization()
|
||||||
{
|
{
|
||||||
return Parts.Sum(part => part.BaseDrawing.Area) / Area();
|
return Parts.Where(p => !p.BaseDrawing.IsCutOff).Sum(part => part.BaseDrawing.Area) / Area();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasOverlappingParts(out List<Vector> pts)
|
public bool HasOverlappingParts(out List<Vector> pts)
|
||||||
{
|
{
|
||||||
pts = new List<Vector>();
|
pts = new List<Vector>();
|
||||||
|
var realParts = Parts.Where(p => !p.BaseDrawing.IsCutOff).ToList();
|
||||||
|
|
||||||
for (int i = 0; i < Parts.Count; i++)
|
for (var i = 0; i < realParts.Count; i++)
|
||||||
{
|
{
|
||||||
var part1 = Parts[i];
|
var part1 = realParts[i];
|
||||||
|
|
||||||
for (int j = i + 1; j < Parts.Count; j++)
|
for (var j = i + 1; j < realParts.Count; j++)
|
||||||
{
|
{
|
||||||
var part2 = Parts[j];
|
var part2 = realParts[j];
|
||||||
|
|
||||||
List<Vector> pts2;
|
if (part1.Intersects(part2, out var pts2))
|
||||||
|
|
||||||
if (part1.Intersects(part2, out pts2))
|
|
||||||
pts.AddRange(pts2);
|
pts.AddRange(pts2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,4 +10,55 @@ public class CutOffTests
|
|||||||
var drawing = new Drawing("test", new Program());
|
var drawing = new Drawing("test", new Program());
|
||||||
Assert.False(drawing.IsCutOff);
|
Assert.False(drawing.IsCutOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Plate_CutOffPart_DoesNotIncrementQuantity()
|
||||||
|
{
|
||||||
|
var drawing = new Drawing("cutoff", new Program()) { IsCutOff = true };
|
||||||
|
var plate = new Plate(100, 100);
|
||||||
|
plate.Parts.Add(new Part(drawing));
|
||||||
|
Assert.Equal(0, drawing.Quantity.Nested);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Plate_Utilization_ExcludesCutOffParts()
|
||||||
|
{
|
||||||
|
var pgm = new Program();
|
||||||
|
pgm.Codes.Add(new RapidMove(new Geometry.Vector(0, 0)));
|
||||||
|
pgm.Codes.Add(new LinearMove(new Geometry.Vector(10, 0)));
|
||||||
|
pgm.Codes.Add(new LinearMove(new Geometry.Vector(10, 10)));
|
||||||
|
pgm.Codes.Add(new LinearMove(new Geometry.Vector(0, 10)));
|
||||||
|
pgm.Codes.Add(new LinearMove(new Geometry.Vector(0, 0)));
|
||||||
|
var realDrawing = new Drawing("real", pgm);
|
||||||
|
var cutoffDrawing = new Drawing("cutoff", new Program()) { IsCutOff = true };
|
||||||
|
|
||||||
|
var plate = new Plate(100, 100);
|
||||||
|
plate.Parts.Add(new Part(realDrawing));
|
||||||
|
plate.Parts.Add(new Part(cutoffDrawing));
|
||||||
|
|
||||||
|
var utilization = plate.Utilization();
|
||||||
|
var expected = realDrawing.Area / plate.Area();
|
||||||
|
Assert.Equal(expected, utilization, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Plate_HasOverlappingParts_SkipsCutOffParts()
|
||||||
|
{
|
||||||
|
var pgm = new Program();
|
||||||
|
pgm.Codes.Add(new RapidMove(new Geometry.Vector(0, 0)));
|
||||||
|
pgm.Codes.Add(new LinearMove(new Geometry.Vector(10, 0)));
|
||||||
|
pgm.Codes.Add(new LinearMove(new Geometry.Vector(10, 10)));
|
||||||
|
pgm.Codes.Add(new LinearMove(new Geometry.Vector(0, 10)));
|
||||||
|
pgm.Codes.Add(new LinearMove(new Geometry.Vector(0, 0)));
|
||||||
|
|
||||||
|
var realDrawing = new Drawing("real", pgm);
|
||||||
|
var cutoffDrawing = new Drawing("cutoff", pgm) { IsCutOff = true };
|
||||||
|
|
||||||
|
var plate = new Plate(100, 100);
|
||||||
|
plate.Parts.Add(new Part(realDrawing));
|
||||||
|
plate.Parts.Add(new Part(cutoffDrawing));
|
||||||
|
|
||||||
|
var hasOverlap = plate.HasOverlappingParts(out var pts);
|
||||||
|
Assert.False(hasOverlap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user