mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-20 14:37:41 -05:00
Geometry, nesting and import code now call PortableMath instead of System.Math for Sin, Cos, Tan, Atan, Atan2, Asin and Acos (Core, Engine, IO, Data; 269 calls in 64 files). A test fails if those projects call the runtime's trig again. With the runtime's trig, Windows and Linux disagreed in the last bit at non-quarter angles and the same job could nest differently: the learned-angle nests (a cross fixture) placed 23 parts in Strip on Windows and 28 on Linux. Now every Engine.Tests pin gives the same layout on both (3600 passing on Linux and on DesktopPC), Linux layouts are unchanged, and the learned-angle rows are re-pinned to the shared layouts, which pass the overlap and work-area checks, and run on every platform again. Fixes Project Memory 518f3b58.
63 lines
2.4 KiB
C#
63 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
using OpenNest.Geometry;
|
|
using OpenNest.Math;
|
|
|
|
namespace OpenNest.CNC.CuttingStrategy
|
|
{
|
|
/// <summary>
|
|
/// A single arc that ends tangent to the cut. Its center lies <see cref="Radius"/> along the
|
|
/// contour normal and it turns <see cref="SweepAngle"/> degrees in the lead's turn direction:
|
|
/// 90 is a quarter circle, 180 (the default) a half circle starting two radii out.
|
|
/// </summary>
|
|
public class ArcLeadIn : LeadIn
|
|
{
|
|
public const double DefaultSweepAngle = 180.0;
|
|
|
|
public double Radius { get; set; }
|
|
|
|
/// <summary>Degrees of arc, in (0, 180].</summary>
|
|
public double SweepAngle { get; set; } = DefaultSweepAngle;
|
|
|
|
public override List<ICode> Generate(
|
|
Vector contourStartPoint,
|
|
double contourNormalAngle,
|
|
RotationType winding = RotationType.CW
|
|
)
|
|
{
|
|
return new List<ICode>
|
|
{
|
|
new RapidMove(GetPiercePoint(contourStartPoint, contourNormalAngle, winding)),
|
|
new ArcMove(contourStartPoint, ArcCenter(contourStartPoint, contourNormalAngle), winding)
|
|
{
|
|
Layer = LayerType.Leadin,
|
|
},
|
|
};
|
|
}
|
|
|
|
public override Vector GetPiercePoint(
|
|
Vector contourStartPoint,
|
|
double contourNormalAngle,
|
|
RotationType winding = RotationType.CW
|
|
)
|
|
{
|
|
// The contour point sits opposite the normal from the center; the pierce is the
|
|
// sweep back from there, against the turn. A half circle pierces on the normal.
|
|
var shortfall = Angle.ToRadians(DefaultSweepAngle - SweepAngle);
|
|
var angle = contourNormalAngle + (winding == RotationType.CCW ? shortfall : -shortfall);
|
|
var center = ArcCenter(contourStartPoint, contourNormalAngle);
|
|
return new Vector(
|
|
center.X + Radius * PortableMath.Cos(angle),
|
|
center.Y + Radius * PortableMath.Sin(angle)
|
|
);
|
|
}
|
|
|
|
public override LeadIn Scale(double factor) =>
|
|
new ArcLeadIn { Radius = Radius * factor, SweepAngle = SweepAngle };
|
|
|
|
private Vector ArcCenter(Vector contourStartPoint, double contourNormalAngle) => new Vector(
|
|
contourStartPoint.X + Radius * PortableMath.Cos(contourNormalAngle),
|
|
contourStartPoint.Y + Radius * PortableMath.Sin(contourNormalAngle)
|
|
);
|
|
}
|
|
}
|