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:
@@ -1,11 +1,11 @@
|
||||
using Microsoft.ML.OnnxRuntime;
|
||||
using Microsoft.ML.OnnxRuntime.Tensors;
|
||||
using OpenNest.Math;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.ML.OnnxRuntime;
|
||||
using Microsoft.ML.OnnxRuntime.Tensors;
|
||||
using OpenNest.Math;
|
||||
|
||||
namespace OpenNest.Engine.ML
|
||||
{
|
||||
@@ -16,8 +16,11 @@ namespace OpenNest.Engine.ML
|
||||
private static readonly object _lock = new();
|
||||
|
||||
public static List<double> PredictAngles(
|
||||
PartFeatures features, double sheetWidth, double sheetHeight,
|
||||
double threshold = 0.3)
|
||||
PartFeatures features,
|
||||
double sheetWidth,
|
||||
double sheetHeight,
|
||||
double threshold = 0.3
|
||||
)
|
||||
{
|
||||
var session = GetSession();
|
||||
if (session == null)
|
||||
@@ -41,7 +44,7 @@ namespace OpenNest.Engine.ML
|
||||
var tensor = new DenseTensor<float>(input, new[] { 1, 11 });
|
||||
var inputs = new List<NamedOnnxValue>
|
||||
{
|
||||
NamedOnnxValue.CreateFromTensor("features", tensor)
|
||||
NamedOnnxValue.CreateFromTensor("features", tensor),
|
||||
};
|
||||
|
||||
using var results = session.Run(inputs);
|
||||
|
||||
@@ -24,24 +24,32 @@ namespace OpenNest.Engine.ML
|
||||
|
||||
public static class BruteForceRunner
|
||||
{
|
||||
public static BruteForceResult Run(Drawing drawing, Plate plate, bool forceFullAngleSweep = false)
|
||||
public static BruteForceResult Run(
|
||||
Drawing drawing,
|
||||
Plate plate,
|
||||
bool forceFullAngleSweep = false
|
||||
)
|
||||
{
|
||||
var engine = new DefaultNestEngine(plate);
|
||||
engine.ForceFullAngleSweep = forceFullAngleSweep;
|
||||
var item = new NestItem { Drawing = drawing };
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
var parts = engine.Fill(item, plate.WorkArea(), null, System.Threading.CancellationToken.None);
|
||||
var parts = engine.Fill(
|
||||
item,
|
||||
plate.WorkArea(),
|
||||
null,
|
||||
System.Threading.CancellationToken.None
|
||||
);
|
||||
sw.Stop();
|
||||
|
||||
if (parts == null || parts.Count == 0)
|
||||
return null;
|
||||
|
||||
// Rank phase results — winner is explicit, runners-up sorted by count.
|
||||
var winner = engine.PhaseResults
|
||||
.FirstOrDefault(r => r.Phase == engine.WinnerPhase);
|
||||
var runnerUps = engine.PhaseResults
|
||||
.Where(r => r.PartCount > 0 && r.Phase != engine.WinnerPhase)
|
||||
var winner = engine.PhaseResults.FirstOrDefault(r => r.Phase == engine.WinnerPhase);
|
||||
var runnerUps = engine
|
||||
.PhaseResults.Where(r => r.PartCount > 0 && r.Phase != engine.WinnerPhase)
|
||||
.OrderByDescending(r => r.PartCount)
|
||||
.ToList();
|
||||
|
||||
@@ -60,19 +68,27 @@ namespace OpenNest.Engine.ML
|
||||
ThirdPlaceEngine = runnerUps.Count > 1 ? runnerUps[1].Phase.ToString() : "",
|
||||
ThirdPlacePartCount = runnerUps.Count > 1 ? runnerUps[1].PartCount : 0,
|
||||
ThirdPlaceTimeMs = runnerUps.Count > 1 ? runnerUps[1].TimeMs : 0,
|
||||
AngleResults = engine.AngleResults.ToList()
|
||||
AngleResults = engine.AngleResults.ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
private static string SerializeLayout(List<Part> parts)
|
||||
{
|
||||
var data = parts.Select(p => new { X = p.Location.X, Y = p.Location.Y, R = p.Rotation }).ToList();
|
||||
var data = parts
|
||||
.Select(p => new
|
||||
{
|
||||
X = p.Location.X,
|
||||
Y = p.Location.Y,
|
||||
R = p.Rotation,
|
||||
})
|
||||
.ToList();
|
||||
return System.Text.Json.JsonSerializer.Serialize(data);
|
||||
}
|
||||
|
||||
private static double CalculateUtilization(List<Part> parts, double plateArea)
|
||||
{
|
||||
if (plateArea <= 0) return 0;
|
||||
if (plateArea <= 0)
|
||||
return 0;
|
||||
return parts.Sum(p => p.BaseDrawing.Area) / plateArea;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using OpenNest.Geometry;
|
||||
using System.Linq;
|
||||
using OpenNest.Geometry;
|
||||
|
||||
namespace OpenNest.Engine.ML
|
||||
{
|
||||
@@ -7,10 +7,10 @@ namespace OpenNest.Engine.ML
|
||||
{
|
||||
// --- Geometric Features ---
|
||||
public double Area { get; set; }
|
||||
public double Convexity { get; set; } // Area / Convex Hull Area
|
||||
public double AspectRatio { get; set; } // Width / Length
|
||||
public double BoundingBoxFill { get; set; } // Area / (Width * Length)
|
||||
public double Circularity { get; set; } // 4 * PI * Area / Perimeter^2
|
||||
public double Convexity { get; set; } // Area / Convex Hull Area
|
||||
public double AspectRatio { get; set; } // Width / Length
|
||||
public double BoundingBoxFill { get; set; } // Area / (Width * Length)
|
||||
public double Circularity { get; set; } // 4 * PI * Area / Perimeter^2
|
||||
public double PerimeterToAreaRatio { get; set; } // Perimeter / Area — spacing sensitivity
|
||||
public int VertexCount { get; set; }
|
||||
|
||||
@@ -30,14 +30,16 @@ namespace OpenNest.Engine.ML
|
||||
// Normalize to canonical frame so features are invariant to import orientation.
|
||||
var canonical = CanonicalFrame.AsCanonicalCopy(drawing);
|
||||
|
||||
var entities = OpenNest.Converters.ConvertProgram.ToGeometry(canonical.Program)
|
||||
var entities = OpenNest
|
||||
.Converters.ConvertProgram.ToGeometry(canonical.Program)
|
||||
.Where(e => e.Layer != SpecialLayers.Rapid)
|
||||
.ToList();
|
||||
|
||||
var profile = new ShapeProfile(entities);
|
||||
var perimeter = profile.Perimeter;
|
||||
|
||||
if (perimeter == null) return null;
|
||||
if (perimeter == null)
|
||||
return null;
|
||||
|
||||
var polygon = perimeter.ToPolygonWithTolerance(0.01);
|
||||
polygon.UpdateBounds();
|
||||
@@ -53,12 +55,13 @@ namespace OpenNest.Engine.ML
|
||||
AspectRatio = bb.Length / (bb.Width > 0 ? bb.Width : 1.0),
|
||||
BoundingBoxFill = canonical.Area / (bb.Area() > 0 ? bb.Area() : 1.0),
|
||||
VertexCount = polygon.Vertices.Count,
|
||||
Bitmask = GenerateBitmask(polygon, 32)
|
||||
Bitmask = GenerateBitmask(polygon, 32),
|
||||
};
|
||||
|
||||
// Circularity = 4 * PI * Area / Perimeter^2
|
||||
var perimeterLen = polygon.Perimeter();
|
||||
features.Circularity = (4 * System.Math.PI * canonical.Area) / (perimeterLen * perimeterLen);
|
||||
features.Circularity =
|
||||
(4 * System.Math.PI * canonical.Area) / (perimeterLen * perimeterLen);
|
||||
features.PerimeterToAreaRatio = canonical.Area > 0 ? perimeterLen / canonical.Area : 0;
|
||||
|
||||
return features;
|
||||
|
||||
Reference in New Issue
Block a user