mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-30 16:41:34 -05:00
fix(benchmark): make manifest quarter turns exact
"rotations": [0, 90, 180, 270] mapped to automatic rotation, which allows any angle: Rectangles placed parts at minimum-area angles such as 279.8 degrees in jobs that allow only quarter turns. Quarter turns are now a 90 degree sweep from 0 to 270. Without "rotations", a part still rotates automatically (any angle), as before 2dab9232; the doc and comment that called that the quarter-turn default are corrected.
This commit is contained in:
1 parent
7dc8cbb22d
commit
8df4c73093
3 files changed
+25
-9
No files matched your search
@@ -135,13 +135,17 @@ namespace OpenNest.Benchmark
|
||||
throw new InvalidOperationException($"Failed to import DXF: {dxfPath}");
|
||||
|
||||
// A zero legacy step means automatic rotation to DrawingJobMapper, so lock it explicitly.
|
||||
// Quarter turns are a 90° sweep from 0 to 270°; automatic rotation allows any angle.
|
||||
var rotations = RotationSet(part);
|
||||
if (rotations != RotationChoice.QuarterTurns)
|
||||
if (rotations != RotationChoice.Any)
|
||||
{
|
||||
var quarter = rotations == RotationChoice.QuarterTurns;
|
||||
drawing.Constraints ??= new NestConstraints();
|
||||
drawing.Constraints.StepAngle = OpenNest.Math.Angle.TwoPI;
|
||||
drawing.Constraints.StepAngle = quarter
|
||||
? OpenNest.Math.Angle.HalfPI
|
||||
: OpenNest.Math.Angle.TwoPI;
|
||||
drawing.Constraints.StartAngle = 0;
|
||||
drawing.Constraints.EndAngle = 0;
|
||||
drawing.Constraints.EndAngle = quarter ? 3 * OpenNest.Math.Angle.HalfPI : 0;
|
||||
drawing.Constraints.Allow180Equivalent = rotations == RotationChoice.HalfTurns;
|
||||
}
|
||||
|
||||
@@ -163,16 +167,17 @@ namespace OpenNest.Benchmark
|
||||
None,
|
||||
HalfTurns,
|
||||
QuarterTurns,
|
||||
Any,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A part's "rotations" (degrees) must be {0}, {0, 180} or {0, 90, 180, 270}; without it,
|
||||
/// "allowRotation" picks quarter turns (true, the default) or none.
|
||||
/// "allowRotation" picks any angle (true, the default: automatic rotation) or none.
|
||||
/// </summary>
|
||||
private static RotationChoice RotationSet(ManifestPart part)
|
||||
{
|
||||
if (part.Rotations == null)
|
||||
return part.AllowRotation ? RotationChoice.QuarterTurns : RotationChoice.None;
|
||||
return part.AllowRotation ? RotationChoice.Any : RotationChoice.None;
|
||||
if (!part.AllowRotation)
|
||||
throw new InvalidOperationException(
|
||||
$"Manifest part '{part.Dxf}': set \"rotations\" or \"allowRotation\", not both."
|
||||
|
||||
@@ -227,15 +227,26 @@ public sealed class JobLoaderManifestTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Rotations_ZeroOnlyLocksAndQuarterTurnsAreAutomatic()
|
||||
public void Rotations_ZeroOnlyLocksAndQuarterTurnsAllowOnlyQuarterTurns()
|
||||
{
|
||||
var locked = RotationOf("[0]");
|
||||
Assert.Equal(RotationPolicyKind.BoundedSweep, locked.Kind);
|
||||
Assert.False(locked.Allow180Equivalent);
|
||||
Assert.Equal(new[] { 0.0 }, locked.EnumerateAngles());
|
||||
|
||||
Assert.Equal(RotationPolicyKind.Automatic, RotationOf("[0, 90, 180, 270]").Kind);
|
||||
Assert.Equal(RotationPolicyKind.Automatic, RotationOf("[0, -90, 450, 180]").Kind);
|
||||
// Automatic rotation would allow any angle; quarter turns must not.
|
||||
foreach (var set in new[] { "[0, 90, 180, 270]", "[0, -90, 450, 180]" })
|
||||
{
|
||||
var quarter = RotationOf(set);
|
||||
Assert.Equal(RotationPolicyKind.BoundedSweep, quarter.Kind);
|
||||
Assert.Equal(
|
||||
new[] { 0, System.Math.PI / 2, System.Math.PI, 3 * System.Math.PI / 2 },
|
||||
quarter.EnumerateAngles()
|
||||
);
|
||||
Assert.True(quarter.Allows(3 * System.Math.PI / 2));
|
||||
Assert.False(quarter.Allows(0.1));
|
||||
Assert.False(quarter.Allows(4.884));
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
||||
@@ -7,6 +7,6 @@ dotnet run --project OpenNest.Benchmark -- ./benchmark-jobs \
|
||||
--sheet-sizes 48x96,60x120,72x120 --engines Irregular,Rectangles --csv results.csv
|
||||
```
|
||||
|
||||
Supply `--sheet-sizes` for an independent candidate pool; otherwise a saved nest offers only its original sheet sizes, which can bias comparisons. A saved nest's first plate also supplies spacing, quadrant and clamps: its machine clamp rail is resolved for every candidate size, as desktop Auto Nest does, and its baseline layout is checked against the clamps it was made with. Manifests have no clamps. A manifest part allows quarter turns unless `"allowRotation": false` locks it at 0°, or `"rotations"` lists its angles in degrees: `[0]`, `[0, 180]` or `[0, 90, 180, 270]`. A saved nest records its salvage rate, but salvage credit applies only with a positive `--min-salvage-dimension`. Without it, every complete one-sheet layout costs the same, as in desktop Auto Nest on a single plate size. The default `--parallel 3` runs solves concurrently and confounds per-engine timing; use `--parallel 1` for timing comparisons. `--progress` logs each solve's start, engine progress, and finish. `--time-limit <seconds>` stops each solve at that wall-clock limit and scores the best valid plan the engine had reported (see [time limits](../nesting-engines.md#time-limits)); a solve with none counts as timed out. Without a limit the harness abandons a solve after five minutes; with one it waits for the limit plus a minute, so the engine's limit always fires first. Retain input hashes, exact commands, validity, fulfillment, costs, and raw results outside source control when comparing revisions; see [fill performance verification](fill-verification.md).
|
||||
Supply `--sheet-sizes` for an independent candidate pool; otherwise a saved nest offers only its original sheet sizes, which can bias comparisons. A saved nest's first plate also supplies spacing, quadrant and clamps: its machine clamp rail is resolved for every candidate size, as desktop Auto Nest does, and its baseline layout is checked against the clamps it was made with. Manifests have no clamps. A manifest part rotates freely (automatic rotation: any angle) unless `"allowRotation": false` locks it at 0°, or `"rotations"` lists its only angles in degrees: `[0]`, `[0, 180]` or `[0, 90, 180, 270]`. A saved nest records its salvage rate, but salvage credit applies only with a positive `--min-salvage-dimension`. Without it, every complete one-sheet layout costs the same, as in desktop Auto Nest on a single plate size. The default `--parallel 3` runs solves concurrently and confounds per-engine timing; use `--parallel 1` for timing comparisons. `--progress` logs each solve's start, engine progress, and finish. `--time-limit <seconds>` stops each solve at that wall-clock limit and scores the best valid plan the engine had reported (see [time limits](../nesting-engines.md#time-limits)); a solve with none counts as timed out. Without a limit the harness abandons a solve after five minutes; with one it waits for the limit plus a minute, so the engine's limit always fires first. Retain input hashes, exact commands, validity, fulfillment, costs, and raw results outside source control when comparing revisions; see [fill performance verification](fill-verification.md).
|
||||
|
||||
Custom engines are DLLs implementing `INestingEngine` with a public parameterless constructor, loaded from `Engines/` beside the benchmark executable. See [nesting engines](../nesting-engines.md) for built-ins and engine-change rules. Run `dotnet run --project OpenNest.Benchmark -- --help` for all options.
|
||||
Reference in new issue
Block a user