Merge branch 'fix/benchmark-scoring'
This commit is contained in:
@@ -43,7 +43,7 @@ internal static class NestJobPlacementValidator
|
||||
counts.TryGetValue(placement.PartId, out var count);
|
||||
if (count >= available)
|
||||
throw new InvalidOperationException("Candidate overproduces a requirement.");
|
||||
if (!RotationIsAllowed(part.Rotation, placement.Rotation))
|
||||
if (!part.Rotation.Allows(placement.Rotation))
|
||||
throw new InvalidOperationException(
|
||||
"Candidate rotation is not allowed for the requirement."
|
||||
);
|
||||
@@ -78,25 +78,6 @@ internal static class NestJobPlacementValidator
|
||||
_ = CreateShape(geometry);
|
||||
}
|
||||
|
||||
private static bool RotationIsAllowed(RotationPolicy policy, double rotation)
|
||||
{
|
||||
if (policy.Kind == RotationPolicyKind.Automatic)
|
||||
return true;
|
||||
if (policy.Kind == RotationPolicyKind.Fixed)
|
||||
return AnglesEqual(rotation, policy.Start);
|
||||
if (rotation < policy.Start - Epsilon || rotation > policy.End + Epsilon)
|
||||
return false;
|
||||
var steps = (rotation - policy.Start) / policy.Step;
|
||||
return System.Math.Abs(steps - System.Math.Round(steps)) <= Epsilon;
|
||||
}
|
||||
|
||||
private static bool AnglesEqual(double left, double right)
|
||||
{
|
||||
var delta = (left - right) % (System.Math.PI * 2);
|
||||
return System.Math.Abs(delta) <= Epsilon
|
||||
|| System.Math.Abs(System.Math.Abs(delta) - System.Math.PI * 2) <= Epsilon;
|
||||
}
|
||||
|
||||
private static ShapeTopology CreateShape(PartGeometrySnapshot geometry)
|
||||
{
|
||||
var entities = ConvertProgram.ToGeometry(DrawingJobMapper.ToProgram(geometry));
|
||||
|
||||
@@ -44,4 +44,25 @@ public sealed class RotationPolicy
|
||||
double rotationStart,
|
||||
double rotationEnd
|
||||
) => stepAngle == 0 ? Automatic : BoundedSweep(rotationStart, rotationEnd, stepAngle);
|
||||
|
||||
/// <summary>True when a placement rotation (radians) satisfies this policy: anything for
|
||||
/// Automatic, the fixed angle modulo a full turn, or an exact step inside a bounded sweep.</summary>
|
||||
public bool Allows(double rotation)
|
||||
{
|
||||
const double epsilon = 0.0000001;
|
||||
if (!double.IsFinite(rotation))
|
||||
return false;
|
||||
if (Kind == RotationPolicyKind.Automatic)
|
||||
return true;
|
||||
if (Kind == RotationPolicyKind.Fixed)
|
||||
{
|
||||
var delta = (rotation - Start) % (System.Math.PI * 2);
|
||||
return System.Math.Abs(delta) <= epsilon
|
||||
|| System.Math.Abs(System.Math.Abs(delta) - System.Math.PI * 2) <= epsilon;
|
||||
}
|
||||
if (rotation < Start - epsilon || rotation > End + epsilon)
|
||||
return false;
|
||||
var steps = (rotation - Start) / Step;
|
||||
return System.Math.Abs(steps - System.Math.Round(steps)) <= epsilon;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user