Scales down lead-ins that would place the pierce point too close to the opposite wall of small holes. Uses quadratic solve to find the maximum safe distance inside a clearance-reduced radius. Adds Scale() method to all LeadIn types and applies clamping in both the strategy and the interactive preview. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
using OpenNest.Geometry;
|
|
using System.Collections.Generic;
|
|
|
|
namespace OpenNest.CNC.CuttingStrategy
|
|
{
|
|
public class ArcLeadIn : LeadIn
|
|
{
|
|
public double Radius { get; set; }
|
|
|
|
public override List<ICode> Generate(Vector contourStartPoint, double contourNormalAngle,
|
|
RotationType winding = RotationType.CW)
|
|
{
|
|
var piercePoint = GetPiercePoint(contourStartPoint, contourNormalAngle);
|
|
|
|
var arcCenter = new Vector(
|
|
contourStartPoint.X + Radius * System.Math.Cos(contourNormalAngle),
|
|
contourStartPoint.Y + Radius * System.Math.Sin(contourNormalAngle));
|
|
|
|
return new List<ICode>
|
|
{
|
|
new RapidMove(piercePoint),
|
|
new ArcMove(contourStartPoint, arcCenter, winding) { Layer = LayerType.Leadin }
|
|
};
|
|
}
|
|
|
|
public override Vector GetPiercePoint(Vector contourStartPoint, double contourNormalAngle)
|
|
{
|
|
var arcCenterX = contourStartPoint.X + Radius * System.Math.Cos(contourNormalAngle);
|
|
var arcCenterY = contourStartPoint.Y + Radius * System.Math.Sin(contourNormalAngle);
|
|
|
|
return new Vector(
|
|
arcCenterX + Radius * System.Math.Cos(contourNormalAngle),
|
|
arcCenterY + Radius * System.Math.Sin(contourNormalAngle));
|
|
}
|
|
|
|
public override LeadIn Scale(double factor) =>
|
|
new ArcLeadIn { Radius = Radius * factor };
|
|
}
|
|
}
|