style: apply CSharpier formatting to all C# sources
Repo-wide sweep with the pinned CSharpier 1.3.0 tool. Whitespace and line-wrapping only; OpenNest.Engine.Tests (109) and OpenNest.IO.Tests pass after reformat, full solution builds 0 errors. Added .csharpierignore so csproj/config XML keeps its existing layout (CSharpier's XML wrapping churns attributes with zero benefit). Formatting is now enforceable: dotnet csharpier check . passes.
This commit is contained in:
@@ -10,24 +10,46 @@ public static class DrawingJobMapper
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(drawing);
|
||||
var constraints = drawing.Constraints;
|
||||
return new NestJobPart(partId, PartGeometrySnapshot.FromProgram(drawing.Program), quantity, drawing.Priority,
|
||||
constraints == null ? RotationPolicy.Automatic :
|
||||
RotationPolicy.FromLegacy(constraints.StepAngle, constraints.StartAngle, constraints.EndAngle));
|
||||
return new NestJobPart(
|
||||
partId,
|
||||
PartGeometrySnapshot.FromProgram(drawing.Program),
|
||||
quantity,
|
||||
drawing.Priority,
|
||||
constraints == null
|
||||
? RotationPolicy.Automatic
|
||||
: RotationPolicy.FromLegacy(
|
||||
constraints.StepAngle,
|
||||
constraints.StartAngle,
|
||||
constraints.EndAngle
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static NestJobPart FromItem(string partId, NestItem item)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(item);
|
||||
ArgumentNullException.ThrowIfNull(item.Drawing);
|
||||
return new NestJobPart(partId, PartGeometrySnapshot.FromProgram(item.Drawing.Program), item.Quantity,
|
||||
item.Priority, RotationPolicy.FromLegacy(item.StepAngle, item.RotationStart, item.RotationEnd));
|
||||
return new NestJobPart(
|
||||
partId,
|
||||
PartGeometrySnapshot.FromProgram(item.Drawing.Program),
|
||||
item.Quantity,
|
||||
item.Priority,
|
||||
RotationPolicy.FromLegacy(item.StepAngle, item.RotationStart, item.RotationEnd)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Available stock is explicit; the legacy plate repeat count is not inventory.</summary>
|
||||
public static NestPlateStock FromPlate(string stockId, Plate plate, int? quantity)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(plate);
|
||||
return new NestPlateStock(stockId, plate.Size, quantity, plate.PartSpacing, plate.EdgeSpacing, plate.Quadrant);
|
||||
return new NestPlateStock(
|
||||
stockId,
|
||||
plate.Size,
|
||||
quantity,
|
||||
plate.PartSpacing,
|
||||
plate.EdgeSpacing,
|
||||
plate.Quadrant
|
||||
);
|
||||
}
|
||||
|
||||
public static Program ToProgram(PartGeometrySnapshot geometry)
|
||||
@@ -40,9 +62,17 @@ public static class DrawingJobMapper
|
||||
{
|
||||
CodeType.RapidMove => (Motion)new RapidMove(motion.X, motion.Y),
|
||||
CodeType.LinearMove => new LinearMove(motion.X, motion.Y) { Layer = motion.Layer },
|
||||
CodeType.ArcMove => new ArcMove(motion.X, motion.Y, motion.CenterX, motion.CenterY, motion.Rotation)
|
||||
{ Layer = motion.Layer },
|
||||
_ => throw new NotSupportedException("Unsupported snapshot motion.")
|
||||
CodeType.ArcMove => new ArcMove(
|
||||
motion.X,
|
||||
motion.Y,
|
||||
motion.CenterX,
|
||||
motion.CenterY,
|
||||
motion.Rotation
|
||||
)
|
||||
{
|
||||
Layer = motion.Layer,
|
||||
},
|
||||
_ => throw new NotSupportedException("Unsupported snapshot motion."),
|
||||
};
|
||||
code.Suppressed = motion.Suppressed;
|
||||
program.Codes.Add(code);
|
||||
@@ -58,20 +88,21 @@ public static class DrawingJobMapper
|
||||
{
|
||||
StepAngle = LegacyStep(part.Rotation),
|
||||
StartAngle = part.Rotation.Start,
|
||||
EndAngle = part.Rotation.End
|
||||
EndAngle = part.Rotation.End,
|
||||
};
|
||||
return drawing;
|
||||
}
|
||||
|
||||
// A fixed angle needs a nonzero legacy step so it is not misread as automatic.
|
||||
internal static double LegacyStep(RotationPolicy policy) => policy.Kind == RotationPolicyKind.Fixed
|
||||
? OpenNest.Math.Angle.TwoPI : policy.Step;
|
||||
internal static double LegacyStep(RotationPolicy policy) =>
|
||||
policy.Kind == RotationPolicyKind.Fixed ? OpenNest.Math.Angle.TwoPI : policy.Step;
|
||||
|
||||
internal static Plate CreatePlate(NestPlateStock stock) => new(stock.Size)
|
||||
{
|
||||
Quantity = 1,
|
||||
PartSpacing = stock.PartSpacing,
|
||||
EdgeSpacing = stock.EdgeSpacing,
|
||||
Quadrant = stock.Quadrant
|
||||
};
|
||||
internal static Plate CreatePlate(NestPlateStock stock) =>
|
||||
new(stock.Size)
|
||||
{
|
||||
Quantity = 1,
|
||||
PartSpacing = stock.PartSpacing,
|
||||
EdgeSpacing = stock.EdgeSpacing,
|
||||
Quadrant = stock.Quadrant,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -23,8 +23,11 @@ public sealed class LegacyPlateNesterAdapter : IPlateNester
|
||||
/// process-global NestEngineRegistry.</summary>
|
||||
public static IPlateNester Create(string strategy) => PlateNesterFactory.Create(strategy);
|
||||
|
||||
public PlateCandidate Place(PlatePlacementRequest request, IProgress<NestJobProgress> progress = null,
|
||||
CancellationToken token = default)
|
||||
public PlateCandidate Place(
|
||||
PlatePlacementRequest request,
|
||||
IProgress<NestJobProgress> progress = null,
|
||||
CancellationToken token = default
|
||||
)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
token.ThrowIfCancellationRequested();
|
||||
@@ -35,37 +38,50 @@ public sealed class LegacyPlateNesterAdapter : IPlateNester
|
||||
{
|
||||
var drawing = DrawingJobMapper.CreateDrawing(requirement);
|
||||
identities.Add(drawing, requirement.Id);
|
||||
items.Add(new NestItem
|
||||
{
|
||||
Drawing = drawing,
|
||||
Quantity = requirement.Quantity,
|
||||
Priority = requirement.Priority,
|
||||
StepAngle = DrawingJobMapper.LegacyStep(requirement.Rotation),
|
||||
RotationStart = requirement.Rotation.Start,
|
||||
RotationEnd = requirement.Rotation.End
|
||||
});
|
||||
items.Add(
|
||||
new NestItem
|
||||
{
|
||||
Drawing = drawing,
|
||||
Quantity = requirement.Quantity,
|
||||
Priority = requirement.Priority,
|
||||
StepAngle = DrawingJobMapper.LegacyStep(requirement.Rotation),
|
||||
RotationStart = requirement.Rotation.Start,
|
||||
RotationEnd = requirement.Rotation.End,
|
||||
}
|
||||
);
|
||||
}
|
||||
var engine = engineFactory(plate) ?? throw new InvalidOperationException("Legacy engine factory returned null.");
|
||||
var legacyProgress = progress == null ? null : new LegacyProgress(progress, request.Stock.Id);
|
||||
var engine =
|
||||
engineFactory(plate)
|
||||
?? throw new InvalidOperationException("Legacy engine factory returned null.");
|
||||
var legacyProgress =
|
||||
progress == null ? null : new LegacyProgress(progress, request.Stock.Id);
|
||||
var parts = engine.Nest(items, legacyProgress, token);
|
||||
token.ThrowIfCancellationRequested();
|
||||
if (parts == null) throw new InvalidOperationException("Legacy engine returned null placements.");
|
||||
if (parts == null)
|
||||
throw new InvalidOperationException("Legacy engine returned null placements.");
|
||||
var placements = new List<NestJobPlacement>();
|
||||
foreach (var part in parts)
|
||||
{
|
||||
if (part?.BaseDrawing == null || !identities.TryGetValue(part.BaseDrawing, out var id))
|
||||
throw new InvalidOperationException("Legacy placement does not reference a private requirement drawing.");
|
||||
placements.Add(new NestJobPlacement(id, 0, part.Location.X, part.Location.Y, part.Rotation));
|
||||
throw new InvalidOperationException(
|
||||
"Legacy placement does not reference a private requirement drawing."
|
||||
);
|
||||
placements.Add(
|
||||
new NestJobPlacement(id, 0, part.Location.X, part.Location.Y, part.Rotation)
|
||||
);
|
||||
}
|
||||
return new PlateCandidate(placements);
|
||||
}
|
||||
|
||||
private sealed class LegacyProgress(IProgress<NestJobProgress> progress, string stockId) : IProgress<NestProgress>
|
||||
private sealed class LegacyProgress(IProgress<NestJobProgress> progress, string stockId)
|
||||
: IProgress<NestProgress>
|
||||
{
|
||||
public void Report(NestProgress value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
progress.Report(new NestJobProgress(NestJobStage.EvaluatingCandidate, stockId, -1, 0, 0, value));
|
||||
progress.Report(
|
||||
new NestJobProgress(NestJobStage.EvaluatingCandidate, stockId, -1, 0, 0, value)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,15 +27,23 @@ public static class NestResultMaterializer
|
||||
ArgumentNullException.ThrowIfNull(job);
|
||||
ArgumentNullException.ThrowIfNull(result);
|
||||
var nest = new Nest();
|
||||
var drawings = job.Parts.ToDictionary(p => p.Id, DrawingJobMapper.CreateDrawing, StringComparer.Ordinal);
|
||||
foreach (var drawing in drawings.Values) nest.Drawings.Add(drawing);
|
||||
var drawings = job.Parts.ToDictionary(
|
||||
p => p.Id,
|
||||
DrawingJobMapper.CreateDrawing,
|
||||
StringComparer.Ordinal
|
||||
);
|
||||
foreach (var drawing in drawings.Values)
|
||||
nest.Drawings.Add(drawing);
|
||||
foreach (var sheet in result.Plates)
|
||||
{
|
||||
var plate = DrawingJobMapper.CreatePlate(sheet.Stock);
|
||||
foreach (var pose in sheet.Placements)
|
||||
{
|
||||
if (!drawings.TryGetValue(pose.PartId, out var drawing))
|
||||
throw new ArgumentException("Result contains a requirement not present in the job.", nameof(result));
|
||||
throw new ArgumentException(
|
||||
"Result contains a requirement not present in the job.",
|
||||
nameof(result)
|
||||
);
|
||||
// Do not use CreateAtOrigin: it normalizes bounds and would change the snapshot frame.
|
||||
var part = new Part(drawing);
|
||||
part.Rotate(pose.Rotation);
|
||||
|
||||
Reference in New Issue
Block a user