mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-06 02:59:25 -05:00
Split only cutting time into short steps, raise the automatic resolution, add an optional ILGPU accelerator with CPU fallback, and estimate heat off the UI thread. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
80 lines
2.5 KiB
C#
80 lines
2.5 KiB
C#
using OpenNest.CNC;
|
|
using OpenNest.CNC.Thermal;
|
|
using OpenNest.Desktop.Interaction;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Desktop.Tests.Interaction;
|
|
|
|
public class HeatEstimateTests
|
|
{
|
|
private sealed class BrokenAccelerator : IHeatAccelerator
|
|
{
|
|
public int Asked { get; private set; }
|
|
public string Name => "broken";
|
|
|
|
public IHeatKernel Create(int columns, int rows, ReadOnlySpan<HeatSample> samples)
|
|
{
|
|
Asked++;
|
|
throw new InvalidOperationException("out of memory");
|
|
}
|
|
}
|
|
|
|
private static (Plate Plate, CutSimulation Simulation) Job(double x = 5)
|
|
{
|
|
var program = new OpenNest.CNC.Program();
|
|
program.Codes.Add(new RapidMove(0, 0));
|
|
program.Codes.Add(new LinearMove(20, 0));
|
|
var plate = new Plate(80, 80);
|
|
plate.Parts.Add(new Part(new Drawing("part", program), new Vector(x, 5)));
|
|
return (plate, CutSimulation.Build(plate,
|
|
new CutParameters { Feedrate = 100, RapidTravelRate = 600, Units = Units.Inches }));
|
|
}
|
|
|
|
// 0.25 in cells on 80 in square: large enough to be accelerated.
|
|
private static ThermalParameters Parameters(IHeatAccelerator? accelerator) => new()
|
|
{
|
|
Thickness = 0.25,
|
|
Units = Units.Inches,
|
|
CellSize = 0.25,
|
|
Accelerator = accelerator,
|
|
};
|
|
|
|
[Fact]
|
|
public void AFailingAcceleratorFallsBackToTheProcessor()
|
|
{
|
|
var (plate, simulation) = Job();
|
|
var broken = new BrokenAccelerator();
|
|
|
|
using var estimate = HeatEstimate.Run(plate, simulation, Parameters!, broken);
|
|
|
|
Assert.Equal(1, broken.Asked);
|
|
Assert.Null(estimate.Device);
|
|
Assert.False(estimate.Heat.IsAccelerated);
|
|
Assert.True(estimate.Scale > 1);
|
|
Assert.Equal(TimeSpan.Zero, estimate.Heat.Time);
|
|
}
|
|
|
|
[Fact]
|
|
public void ACancelledEstimateThrows()
|
|
{
|
|
var (plate, simulation) = Job();
|
|
using var cancel = new CancellationTokenSource();
|
|
cancel.Cancel();
|
|
|
|
Assert.Throws<OperationCanceledException>(
|
|
() => HeatEstimate.Run(plate, simulation, Parameters!, null!, cancel.Token));
|
|
}
|
|
|
|
[Fact]
|
|
public void ARebuiltTimelineWithTheSameMovesMatches()
|
|
{
|
|
var (_, first) = Job();
|
|
var (_, again) = Job();
|
|
var (_, moved) = Job(x: 6);
|
|
|
|
Assert.True(HeatEstimate.SameMoves(first, again));
|
|
Assert.False(HeatEstimate.SameMoves(first, moved));
|
|
Assert.False(HeatEstimate.SameMoves(first, null!));
|
|
}
|
|
}
|