refactor(engine): extract default and remnant plate fillers
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenNest.Engine;
|
||||
using OpenNest.Engine.Fill;
|
||||
using OpenNest.Engine.Jobs.Placement.Fillers;
|
||||
using OpenNest.Engine.Strategies;
|
||||
using OpenNest.Geometry;
|
||||
using OpenNest.Math;
|
||||
|
||||
namespace OpenNest.Engine
|
||||
{
|
||||
/// <summary>
|
||||
/// Optimizes for the largest right-side vertical drop.
|
||||
/// Scores by count first, then minimizes X-extent.
|
||||
/// Prefers horizontal nest direction and angles that keep parts narrow in X.
|
||||
/// </summary>
|
||||
public class VerticalRemnantEngine : DefaultNestEngine
|
||||
{
|
||||
@@ -21,31 +18,17 @@ namespace OpenNest.Engine
|
||||
|
||||
public override string Description => "Optimizes for largest right-side vertical drop";
|
||||
|
||||
protected override IFillComparer CreateComparer() => new VerticalRemnantComparer();
|
||||
protected override IFillComparer CreateComparer() => RemnantFillPolicy.Vertical.CreateComparer();
|
||||
|
||||
public override NestDirection? PreferredDirection => NestDirection.Horizontal;
|
||||
public override NestDirection? PreferredDirection => RemnantFillPolicy.Vertical.PreferredDirection;
|
||||
|
||||
public override List<double> BuildAngles(
|
||||
NestItem item,
|
||||
ClassificationResult classification,
|
||||
Box workArea
|
||||
)
|
||||
{
|
||||
var baseAngles = new List<double>
|
||||
{
|
||||
classification.PrimaryAngle,
|
||||
classification.PrimaryAngle + Angle.HalfPI,
|
||||
};
|
||||
baseAngles.Sort((a, b) => RotatedWidth(item, a).CompareTo(RotatedWidth(item, b)));
|
||||
return baseAngles;
|
||||
}
|
||||
) => RemnantFillPolicy.Vertical.BuildAngles(item, classification);
|
||||
|
||||
private static double RotatedWidth(NestItem item, double angle)
|
||||
{
|
||||
var bb = item.Drawing.Program.BoundingBox();
|
||||
var cos = System.Math.Abs(System.Math.Cos(angle));
|
||||
var sin = System.Math.Abs(System.Math.Sin(angle));
|
||||
return bb.Length * cos + bb.Width * sin;
|
||||
}
|
||||
internal override DefaultPlateFiller CreateFiller(Plate plate) =>
|
||||
CreateRemnantFiller(plate, RemnantFillPolicy.Vertical);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user