mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-06 06:29:24 -05:00
test(heat): report pierce temperatures in the heat measurement
Part starts cannot judge a hole order inside a part, so the harness also reports the mean temperature within 0.5 in of every pierce when it starts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1772eb04e0
commit
4a5c96f011
1 file changed
+40
-6
@@ -112,11 +112,13 @@ public class HeatOrderMeasurementTests(ITestOutputHelper output)
|
||||
var cut = CutParameters.Default;
|
||||
cut.Units = nest.Units;
|
||||
var simulation = CutSimulation.Build(plate, cut);
|
||||
var (p95, p75, starts, every, grid) = Heat(plate, simulation, nest);
|
||||
var (p95, p75, starts, every, grid, pierces) = Heat(plate, simulation, nest);
|
||||
var sorted = starts.Order().ToArray();
|
||||
double At(double q) => sorted.Length == 0 ? 0 : sorted[(int)(q * (sorted.Length - 1))];
|
||||
var all = every.Order().ToArray();
|
||||
double AllAt(double q) => all.Length == 0 ? 0 : all[(int)(q * (all.Length - 1))];
|
||||
var pierced = pierces.Order().ToArray();
|
||||
double PierceAt(double q) => pierced.Length == 0 ? 0 : pierced[(int)(q * (pierced.Length - 1))];
|
||||
return FormattableString.Invariant(
|
||||
$"{label}: {result.Status}{(result.IsSafestRouteFallback ? " (safest route)" : "")}")
|
||||
+ FormattableString.Invariant(
|
||||
@@ -127,15 +129,18 @@ public class HeatOrderMeasurementTests(ITestOutputHelper output)
|
||||
+ FormattableString.Invariant(
|
||||
$"starts ({sorted.Length}) median {At(0.5):0.0} P90 {At(0.9):0.0} max {At(1):0.0}, ")
|
||||
+ FormattableString.Invariant(
|
||||
$"every part median {AllAt(0.5):0.0} P90 {AllAt(0.9):0.0} max {AllAt(1):0.0}, plan {planSeconds:0.0} s");
|
||||
$"every part median {AllAt(0.5):0.0} P90 {AllAt(0.9):0.0} max {AllAt(1):0.0}, ")
|
||||
+ FormattableString.Invariant(
|
||||
$"pierces ({pierced.Length}) median {PierceAt(0.5):0.0} P90 {PierceAt(0.9):0.0} P99 {PierceAt(0.99):0.0} max {PierceAt(1):0.0}, plan {planSeconds:0.0} s");
|
||||
}
|
||||
|
||||
// The hottest average over each 4 in square during the cut, as the 95th and 75th percentile
|
||||
// over squares (sampled every second, every 10 s past 1,000 parts), and the mean temperature
|
||||
// over each start's part when the cut reaches it. Cells whose slug fell away do not count. On
|
||||
// a grid (CuttingGridOrder.Bins along the axis consecutive parts mostly share) a start is a
|
||||
// line's first part; otherwise every part.
|
||||
private static (double P95, double P75, List<double> Starts, List<double> Every, bool Grid) Heat(Plate plate,
|
||||
// line's first part; otherwise every part. Pierces: the mean temperature within 0.5 in of each
|
||||
// pierce when it starts, so a hole order inside a part is judged where it pierces.
|
||||
private static (double P95, double P75, List<double> Starts, List<double> Every, bool Grid, List<double> Pierces) Heat(Plate plate,
|
||||
CutSimulation simulation, Nest nest)
|
||||
{
|
||||
var boxes = plate.Parts.Select(p => p.BoundingBox).ToArray();
|
||||
@@ -177,6 +182,11 @@ public class HeatOrderMeasurementTests(ITestOutputHelper output)
|
||||
events.Add((t, -1));
|
||||
for (var part = 0; part < boxes.Length; part++)
|
||||
events.Add((simulation.PartStarts[part].TotalSeconds, part));
|
||||
var piercePoints = simulation.Steps.Where(step => step.Kind == CutSimulationStepKind.Pierce).ToArray();
|
||||
for (var pierce = 0; pierce < piercePoints.Length; pierce++)
|
||||
events.Add((piercePoints[pierce].StartTime.TotalSeconds, -2 - pierce));
|
||||
var pierces = new List<double>();
|
||||
var reach = nest.Units == Units.Millimeters ? 12.7 : 0.5;
|
||||
var isStart = lineStarts.ToHashSet();
|
||||
var starts = new List<double>();
|
||||
var every = new List<double>();
|
||||
@@ -184,6 +194,29 @@ public class HeatOrderMeasurementTests(ITestOutputHelper output)
|
||||
{
|
||||
heat.AdvanceTo(TimeSpan.FromSeconds(time));
|
||||
var temperatures = heat.Temperatures;
|
||||
if (part <= -2)
|
||||
{
|
||||
var at = piercePoints[-2 - part].Start;
|
||||
double sum = 0;
|
||||
var count = 0;
|
||||
var span = (int)System.Math.Ceiling(reach / heat.CellSize);
|
||||
var centerColumn = (int)((at.X - heat.OriginX) / heat.CellSize);
|
||||
var centerRow = (int)((at.Y - heat.OriginY) / heat.CellSize);
|
||||
for (var row = System.Math.Max(0, centerRow - span); row <= System.Math.Min(heat.Rows - 1, centerRow + span); row++)
|
||||
for (var column = System.Math.Max(0, centerColumn - span); column <= System.Math.Min(heat.Columns - 1, centerColumn + span); column++)
|
||||
{
|
||||
var x = heat.OriginX + (column + 0.5) * heat.CellSize - at.X;
|
||||
var y = heat.OriginY + (row + 0.5) * heat.CellSize - at.Y;
|
||||
var index = row * heat.Columns + column;
|
||||
if (x * x + y * y > reach * reach || heat.IsRemoved(index))
|
||||
continue;
|
||||
sum += temperatures[index];
|
||||
count++;
|
||||
}
|
||||
if (count > 0)
|
||||
pierces.Add(sum / count);
|
||||
continue;
|
||||
}
|
||||
if (part >= 0)
|
||||
{
|
||||
var box = boxes[part];
|
||||
@@ -232,7 +265,8 @@ public class HeatOrderMeasurementTests(ITestOutputHelper output)
|
||||
}
|
||||
}
|
||||
var values = hottest.Where((_, z) => seen[z]).Order().ToArray();
|
||||
return values.Length == 0 ? (0, 0, starts, every, grid)
|
||||
: (values[(int)(0.95 * (values.Length - 1))], values[(int)(0.75 * (values.Length - 1))], starts, every, grid);
|
||||
return values.Length == 0 ? (0, 0, starts, every, grid, pierces)
|
||||
: (values[(int)(0.95 * (values.Length - 1))], values[(int)(0.75 * (values.Length - 1))], starts, every, grid,
|
||||
pierces);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user