using System;
namespace OpenNest
{
///
/// The sheet edge a clamp sits on, named relative to the plate
/// origin so one rail resolves onto every sheet size and quadrant.
///
public enum ClampEdge
{
/// The edge along X through the origin (operator side).
OriginSide = 0,
/// The edge along X across the sheet's width from the origin.
FarSide = 1,
/// The edge along Y through the origin.
OriginEnd = 2,
/// The edge along Y across the sheet's length from the origin.
FarEnd = 3,
}
public static class ClampEdges
{
/// True for the two edges along X, whose clamp positions are X distances.
public static bool RunsAlongX(this ClampEdge edge) =>
edge is ClampEdge.OriginSide or ClampEdge.FarSide;
public static bool IsDefined(ClampEdge edge) =>
edge is ClampEdge.OriginSide or ClampEdge.FarSide or ClampEdge.OriginEnd or ClampEdge.FarEnd;
}
///
/// One clamp of a : its edge and its center measured from the plate
/// origin along that edge (X for the sides, Y for the ends). Orders by edge, then center.
///
public readonly record struct RailClamp(ClampEdge Edge, double Center) : IComparable
{
public int CompareTo(RailClamp other)
{
var edge = Edge.CompareTo(other.Edge);
return edge != 0 ? edge : Center.CompareTo(other.Center);
}
}
}