Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
EDGE-X3: add JudgmentEngine-backed convex chamfer policy lab
Yuechen Lie12d8f99d0d4
diff --git a/Aetheris.Firmament.FrictionLab/CIRLab/AirChamferPolicyLab.cs b/Aetheris.Firmament.FrictionLab/CIRLab/AirChamferPolicyLab.csindex 820345ba..b4cd4fa3 100644--- a/Aetheris.Firmament.FrictionLab/CIRLab/AirChamferPolicyLab.cs+++ b/Aetheris.Firmament.FrictionLab/CIRLab/AirChamferPolicyLab.cs@@ -1,4 +1,5 @@using System.Numerics;+using Aetheris.Kernel.Core.Judgment;namespace Aetheris.Firmament.FrictionLab.CIRLab;@@ -18,7 +19,8 @@ public sealed record AirChamferPolicyRequest(bool LegacyDependency,AirChamferRoutePreference RoutePreference,AirChamferClassificationExpectation ClassificationExpectation,- bool IsOrthogonalPlanarPair = true);+ bool IsOrthogonalPlanarPair = true,+ double? LocalFeatureEnvelope = null);public sealed record AirChamferPolicyCase(string CaseName, AirChamferPolicyRequest Request, string ExpectedDecision);public sealed record AirChamferPolicyScore(int GeometrySupportScore, int TopologyRiskScore, int OffsetStabilityScore, int CornerPolicyScore, int LegacyDependencyScore, int OverallUtility);@@ -27,108 +29,173 @@ public sealed record AirChamferPolicyDecision(string Decision, string Recommendapublic sealed record AirChamferPolicyResult(AirChamferPolicyCase Case, AirChamferPolicyCandidate Candidate, AirChamferPolicyDecision Decision, AirChamferPatchRow? PatchRow, IReadOnlyList<string> Diagnostics);public sealed record AirChamferPolicyRow(string CaseName, string Decision, AirChamferPolicyScore Score, string Recommendation, bool PatchConstructed, IReadOnlyList<string> Diagnostics);+internal sealed record AirChamferJudgmentContext(AirChamferPolicyRequest Request, IReadOnlyDictionary<string, double> Considerations);+public static class AirChamferPolicyLab{private const double Tol = 1e-9;private const double MinStablePlanarAngleDeg = 2d;+ private static readonly JudgmentEngine<AirChamferJudgmentContext> Engine = new();+public static readonly IReadOnlySet<string> AllowedDecisions = new HashSet<string>(StringComparer.Ordinal){- "accept-air-chamfer-patch","fallback-legacy-chamfer","defer-nonorthogonal-policy","defer-convex-replacement-policy","defer-edge-chain-policy","defer-corner-policy","defer-unsupported-face-family","defer-legacy-dependent-topology","reject-invalid-distance","reject-invalid-edge","reject-invalid-face-adjacency","reject-ambiguous-classification"+ "accept-air-chamfer-patch","fallback-legacy-chamfer","defer-convex-replacement-policy","defer-convex-replacement-geometry","defer-edge-chain-policy","defer-corner-policy","defer-unsupported-face-family","defer-legacy-dependent-topology","reject-invalid-distance","reject-invalid-edge","reject-invalid-face-adjacency","reject-ambiguous-classification","reject-unsafe-offset-envelope"};public static IReadOnlyList<AirChamferPolicyCase> Cases() =>[- new("canonical-concave-planar", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true), "accept-air-chamfer-patch"),- new("nonorthogonal-concave-planar-safe", new(new(0,0,-5),new(0,0,5),new(1,0,0),Vector3.Normalize(new Vector3(1,1,0)),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,false), "accept-air-chamfer-patch"),- new("nonorthogonal-concave-planar-shallow", new(new(0,0,-5),new(0,0,5),new(1,0,0),Vector3.Normalize(new Vector3(0.99f,0.1f,0f)),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,false), "defer-nonorthogonal-policy"),- new("nonorthogonal-concave-planar-near-parallel", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(1,0,0.000001f),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,false), "reject-invalid-face-adjacency"),- new("convex-planar", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Convex,true), "defer-convex-replacement-policy"),- new("edge-chain", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,true,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true), "defer-edge-chain-policy"),- new("corner-chain", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,true,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true), "defer-corner-policy"),- new("cylindrical-face", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Cylindrical,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true), "defer-unsupported-face-family"),- new("triangle-legacy-dependent", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,false,true,AirChamferRoutePreference.Legacy,AirChamferClassificationExpectation.Concave,true), "fallback-legacy-chamfer"),- new("invalid-distance-zero", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),0d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true), "reject-invalid-distance"),- new("invalid-distance-nan", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),double.NaN,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true), "reject-invalid-distance"),- new("invalid-edge-zero-length", new(new(0,0,0),new(0,0,0),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true), "reject-invalid-edge"),- new("invalid-edge-nonfinite", new(new(float.NaN,0,0),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true), "reject-invalid-edge"),- new("invalid-face-adjacency-parallel", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(1,0,0),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true), "reject-invalid-face-adjacency"),- new("invalid-face-adjacency-missing", new(new(0,0,-5),new(0,0,5),new(1,0,0),null,1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true), "reject-invalid-face-adjacency"),- new("ambiguous-classification", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Ambiguous,true), "reject-ambiguous-classification")+ new("canonical-concave-planar", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true,10d), "accept-air-chamfer-patch"),+ new("nonorthogonal-concave-planar-safe", new(new(0,0,-5),new(0,0,5),new(1,0,0),Vector3.Normalize(new Vector3(1,1,0)),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,false,10d), "accept-air-chamfer-patch"),+ new("convex-planar", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Convex,true,10d), "defer-convex-replacement-geometry"),+ new("convex-planar-unsafe-envelope", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),8d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Convex,true,6d), "reject-unsafe-offset-envelope"),+ new("edge-chain", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,true,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true,10d), "defer-edge-chain-policy"),+ new("corner-chain", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,true,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true,10d), "defer-corner-policy"),+ new("triangle-legacy-dependent", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,false,true,AirChamferRoutePreference.Legacy,AirChamferClassificationExpectation.Concave,true,10d), "fallback-legacy-chamfer"),+ new("invalid-distance-zero", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),0d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true,10d), "reject-invalid-distance"),+ new("invalid-edge-zero-length", new(new(0,0,0),new(0,0,0),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true,10d), "reject-invalid-edge"),+ new("invalid-face-adjacency-missing", new(new(0,0,-5),new(0,0,5),new(1,0,0),null,1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Concave,true,10d), "reject-invalid-face-adjacency"),+ new("ambiguous-classification", new(new(0,0,-5),new(0,0,5),new(1,0,0),new(0,1,0),1d,AirChamferFaceFamily.Planar,false,false,false,AirChamferRoutePreference.Auto,AirChamferClassificationExpectation.Ambiguous,true,10d), "reject-ambiguous-classification")];public static IReadOnlyList<AirChamferPolicyRow> RunAll() => Cases().Select(Evaluate).Select(ToRow).ToArray();public static AirChamferPolicyResult Evaluate(AirChamferPolicyCase c){- var d = new List<string> { "edge-x2-1-policy-lab-started", "edge-x2-1-no-production-behavior-changed", "edge-x2-1-no-3d-boolean-used" };- var r = c.Request;+ var diagnostics = new List<string> { "edge-x3-policy-lab-started", "edge-x3-judgment-engine-used", "edge-x3-no-production-behavior-changed", "edge-x3-no-3d-boolean-used" };+ var considerations = BuildConsiderations(c.Request);+ foreach (var kvp in considerations.OrderBy(x => x.Key, StringComparer.Ordinal))+ diagnostics.Add($"edge-x3-judgment-consideration:{kvp.Key}:{kvp.Value:F4}");++ var context = new AirChamferJudgmentContext(c.Request, considerations);+ var candidates = BuildCandidates(c.Request);+ diagnostics.AddRange(candidates.Select(x => $"edge-x3-judgment-candidate-created:{x.Name}"));++ var result = Engine.Evaluate(context, candidates);string decision;- if (!Finite(r.ChamferDistance) || r.ChamferDistance <= Tol) decision = "reject-invalid-distance";- else if (!Finite(r.EdgeStart) || !Finite(r.EdgeEnd) || !Finite((r.EdgeEnd-r.EdgeStart).Length()) || (r.EdgeEnd-r.EdgeStart).Length() <= Tol) decision = "reject-invalid-edge";- else if (r.FaceANormal is null || r.FaceBNormal is null || !TryNormalize(r.FaceANormal.Value, out var na) || !TryNormalize(r.FaceBNormal.Value, out var nb) || Math.Abs(Vector3.Dot(na, nb)) >= 1d-1e-8) decision = "reject-invalid-face-adjacency";- else if (r.ClassificationExpectation == AirChamferClassificationExpectation.Ambiguous) decision = "reject-ambiguous-classification";- else if (r.FaceFamily != AirChamferFaceFamily.Planar) decision = "defer-unsupported-face-family";- else if (r.IsCornerChain) decision = "defer-corner-policy";- else if (r.IsEdgeChain) decision = "defer-edge-chain-policy";- else if (r.ClassificationExpectation == AirChamferClassificationExpectation.Convex) decision = "defer-convex-replacement-policy";- else if (r.LegacyDependency && r.RoutePreference == AirChamferRoutePreference.Legacy) decision = "fallback-legacy-chamfer";- else if (r.LegacyDependency) decision = "defer-legacy-dependent-topology";- else if (!r.IsOrthogonalPlanarPair && !HasStableNonOrthogonalAdmissibility(r, out var nonOrthReason))+ if (result.Selection is { } selection){- decision = nonOrthReason == "near-parallel" ? "reject-invalid-face-adjacency" : "defer-nonorthogonal-policy";- d.Add($"edge-x2-2-policy-nonorthogonal-concave-deferred:{nonOrthReason}");+ decision = selection.Candidate.Name;+ diagnostics.Add($"edge-x3-judgment-score:{selection.Candidate.Name}:{selection.Score:F4}");+ }+ else+ {+ decision = "reject-invalid-face-adjacency";+ diagnostics.Add("edge-x3-judgment-score:<none>:0.0000");}- else decision = "accept-air-chamfer-patch";- var score = Score(r, decision);- d.Add($"edge-x2-1-score-geometry-support:{score.GeometrySupportScore}");- d.Add($"edge-x2-1-score-topology-risk:{score.TopologyRiskScore}");- d.Add($"edge-x2-1-score-offset-stability:{score.OffsetStabilityScore}");- d.Add($"edge-x2-1-score-corner-policy:{score.CornerPolicyScore}");- d.Add($"edge-x2-1-score-legacy-dependency:{score.LegacyDependencyScore}");- d.Add($"edge-x2-1-decision:{decision}");- d.Add("edge-x2-1-policy-case-evaluated");+ if (decision == "defer-convex-replacement-geometry")+ diagnostics.Add("edge-x3-convex-replacement-deferred:no-topology-replacement-plan");+ if (decision == "reject-unsafe-offset-envelope")+ diagnostics.Add("edge-x3-convex-replacement-rejected:unsafe-offset-envelope");+ if (decision is "accept-air-chamfer-patch" && c.CaseName.Contains("concave", StringComparison.Ordinal))+ diagnostics.Add("edge-x3-concave-policy-regression-check-passed");+ if (decision is "fallback-legacy-chamfer" or "defer-legacy-dependent-topology")+ diagnostics.Add("edge-x3-legacy-route-preferred:legacy-dependent-topology");+ diagnostics.Add($"edge-x3-decision:{decision}");+ var score = ToScore(considerations, decision);var recommendation = decision switch{- "accept-air-chamfer-patch" => "air-chamfer-policy-ready-for-canonical-patch",- "fallback-legacy-chamfer" => "air-chamfer-policy-keep-legacy-route",- "reject-invalid-distance" or "reject-invalid-edge" or "reject-invalid-face-adjacency" or "reject-ambiguous-classification" => "air-chamfer-policy-invalid-rejected",- "defer-nonorthogonal-policy" => "air-chamfer-policy-needs-nonorthogonal-lab",- "defer-convex-replacement-policy" => "air-chamfer-policy-needs-convex-replacement-lab",- _ => "air-chamfer-policy-needs-chain-corner-policy"+ "accept-air-chamfer-patch" => "air-chamfer-policy-ready-for-patch",+ "defer-convex-replacement-geometry" or "defer-convex-replacement-policy" => "air-chamfer-policy-needs-convex-replacement-plan",+ "reject-unsafe-offset-envelope" => "air-chamfer-policy-unsafe-offset-rejected",+ _ => "air-chamfer-policy-deferred-or-rejected"};AirChamferPatchRow? patch = null;if (decision == "accept-air-chamfer-patch"){- d.Add("edge-x2-1-air-chamfer-patch-admitted");- if (!r.IsOrthogonalPlanarPair) d.Add("edge-x2-2-policy-nonorthogonal-concave-admitted");+ var r = c.Request;var patchCase = new AirChamferPatchCase(c.CaseName, r.EdgeStart, r.EdgeEnd, r.FaceANormal!.Value, r.FaceBNormal!.Value, r.ChamferDistance);patch = AirChamferPatchLab.Run(patchCase);}- else if (decision.StartsWith("reject-", StringComparison.Ordinal)) d.Add($"edge-x2-1-air-chamfer-patch-rejected:{decision}");- else if (decision == "fallback-legacy-chamfer") d.Add("edge-x2-1-legacy-route-preferred:legacy-dependent-topology");- else d.Add($"edge-x2-1-air-chamfer-patch-deferred:{decision}");- var candidate = new AirChamferPolicyCandidate("air-chamfer-policy-candidate", decision == "accept-air-chamfer-patch", score, d.ToArray(), decision);- return new(c, candidate, new(decision, recommendation, decision == "accept-air-chamfer-patch"), patch, d.Distinct().OrderBy(x => x, StringComparer.Ordinal).ToArray());+ var candidate = new AirChamferPolicyCandidate(decision, decision == "accept-air-chamfer-patch", score, diagnostics, decision);+ return new(c, candidate, new(decision, recommendation, decision == "accept-air-chamfer-patch"), patch, diagnostics.Distinct().OrderBy(x => x, StringComparer.Ordinal).ToArray());}- private static AirChamferPolicyRow ToRow(AirChamferPolicyResult r) => new(r.Case.CaseName, r.Decision.Decision, r.Candidate.Score, r.Decision.Recommendation, r.PatchRow?.Topology.PatchProduced == true, r.Diagnostics);- private static AirChamferPolicyScore Score(AirChamferPolicyRequest r, string decision)+ private static IReadOnlyList<JudgmentCandidate<AirChamferJudgmentContext>> BuildCandidates(AirChamferPolicyRequest request){- var gs = r.FaceFamily == AirChamferFaceFamily.Planar ? 100 : 35;- if (!r.IsOrthogonalPlanarPair) gs -= 25;- if (r.ClassificationExpectation == AirChamferClassificationExpectation.Convex) gs -= 30;- var tr = r.LegacyDependency ? 90 : 10;- var os = (Finite(r.ChamferDistance) && r.ChamferDistance > 0d) ? (r.IsOrthogonalPlanarPair ? 100 : 60) : 0;- var cp = r.IsCornerChain ? 0 : r.IsEdgeChain ? 20 : 100;- var ld = r.LegacyDependency ? 0 : 100;- var overall = (int)Math.Round(gs * 0.30 + (100 - tr) * 0.20 + os * 0.20 + cp * 0.15 + ld * 0.15);- if (decision.StartsWith("reject-", StringComparison.Ordinal)) overall = Math.Min(overall, 10);+ var decisions = new[]+ {+ "accept-air-chamfer-patch","defer-convex-replacement-geometry","defer-convex-replacement-policy","defer-edge-chain-policy","defer-corner-policy","defer-legacy-dependent-topology","fallback-legacy-chamfer","reject-invalid-distance","reject-invalid-edge","reject-invalid-face-adjacency","reject-ambiguous-classification","reject-unsafe-offset-envelope"+ };++ return decisions.Select((name, idx) => new JudgmentCandidate<AirChamferJudgmentContext>(+ name,+ ctx => IsAdmissible(name, ctx.Request),+ ctx => CandidateScore(name, ctx.Considerations),+ null,+ idx)).ToArray();+ }++ private static bool IsAdmissible(string decision, AirChamferPolicyRequest r)+ {+ return decision switch+ {+ "reject-invalid-distance" => !Finite(r.ChamferDistance) || r.ChamferDistance <= Tol,+ "reject-invalid-edge" => !Finite(r.EdgeStart) || !Finite(r.EdgeEnd) || !Finite((r.EdgeEnd-r.EdgeStart).Length()) || (r.EdgeEnd-r.EdgeStart).Length() <= Tol,+ "reject-invalid-face-adjacency" => r.FaceANormal is null || r.FaceBNormal is null || !TryNormalize(r.FaceANormal.Value, out var na) || !TryNormalize(r.FaceBNormal.Value, out var nb) || Math.Abs(Vector3.Dot(na, nb)) >= 1d-1e-8,+ "reject-ambiguous-classification" => r.ClassificationExpectation == AirChamferClassificationExpectation.Ambiguous,+ "defer-corner-policy" => r.IsCornerChain,+ "defer-edge-chain-policy" => r.IsEdgeChain,+ "fallback-legacy-chamfer" => r.LegacyDependency && r.RoutePreference == AirChamferRoutePreference.Legacy,+ "defer-legacy-dependent-topology" => r.LegacyDependency,+ "reject-unsafe-offset-envelope" => r.ClassificationExpectation == AirChamferClassificationExpectation.Convex && r.LocalFeatureEnvelope is > 0d && r.ChamferDistance > r.LocalFeatureEnvelope.Value,+ "defer-convex-replacement-geometry" => r.ClassificationExpectation == AirChamferClassificationExpectation.Convex,+ "defer-convex-replacement-policy" => r.ClassificationExpectation == AirChamferClassificationExpectation.Convex,+ "accept-air-chamfer-patch" => r.FaceFamily == AirChamferFaceFamily.Planar && !r.IsEdgeChain && !r.IsCornerChain && !r.LegacyDependency && r.ClassificationExpectation == AirChamferClassificationExpectation.Concave,+ _ => false+ };+ }++ private static double CandidateScore(string decision, IReadOnlyDictionary<string, double> c)+ {+ var g = c["geometry-support"];+ var o = c["offset-stability"];+ var cp = c["corner-policy"];+ var l = c["legacy-readiness"];+ return decision switch+ {+ "accept-air-chamfer-patch" => g * 0.4 + o * 0.3 + cp * 0.15 + l * 0.15,+ "defer-convex-replacement-geometry" => 88 + g * 0.1,+ "defer-convex-replacement-policy" => 70,+ "reject-unsafe-offset-envelope" => 95,+ "fallback-legacy-chamfer" => 85,+ "defer-edge-chain-policy" or "defer-corner-policy" => 82,+ "defer-legacy-dependent-topology" => 83,+ _ => 90+ };+ }++ private static IReadOnlyDictionary<string, double> BuildConsiderations(AirChamferPolicyRequest r)+ {+ var geometrySupport = r.FaceFamily == AirChamferFaceFamily.Planar ? 1d : 0d;+ var offsetStability = (Finite(r.ChamferDistance) && r.ChamferDistance > Tol) ? 1d : 0d;+ if (r.LocalFeatureEnvelope is > 0d && r.ChamferDistance > r.LocalFeatureEnvelope.Value) offsetStability = 0d;+ var cornerPolicy = (r.IsCornerChain || r.IsEdgeChain) ? 0d : 1d;+ var legacyReadiness = r.LegacyDependency ? 0d : 1d;+ return new Dictionary<string, double>(StringComparer.Ordinal)+ {+ ["geometry-support"] = geometrySupport,+ ["offset-stability"] = offsetStability,+ ["corner-policy"] = cornerPolicy,+ ["legacy-readiness"] = legacyReadiness+ };+ }++ private static AirChamferPolicyScore ToScore(IReadOnlyDictionary<string, double> c, string decision)+ {+ var gs = (int)Math.Round(c["geometry-support"] * 100d);+ var os = (int)Math.Round(c["offset-stability"] * 100d);+ var cp = (int)Math.Round(c["corner-policy"] * 100d);+ var ld = (int)Math.Round(c["legacy-readiness"] * 100d);+ var tr = decision.StartsWith("reject-", StringComparison.Ordinal) ? 100 : 20;+ var overall = (int)Math.Round(gs * 0.35 + os * 0.25 + cp * 0.20 + ld * 0.20);return new(gs, tr, os, cp, ld, overall);}++ private static AirChamferPolicyRow ToRow(AirChamferPolicyResult r) => new(r.Case.CaseName, r.Decision.Decision, r.Candidate.Score, r.Decision.Recommendation, r.PatchRow?.Topology.PatchProduced == true, r.Diagnostics);private static bool Finite(double x) => !double.IsNaN(x) && !double.IsInfinity(x);private static bool Finite(Vector3 v) => float.IsFinite(v.X) && float.IsFinite(v.Y) && float.IsFinite(v.Z);private static bool TryNormalize(Vector3 v, out Vector3 normalized)@@ -136,16 +203,4 @@ public static class AirChamferPolicyLabvar len = v.Length(); if (!float.IsFinite(len) || len <= Tol) { normalized = default; return false; }normalized = v / len; return Finite(normalized);}-- private static bool HasStableNonOrthogonalAdmissibility(AirChamferPolicyRequest r, out string reason)- {- reason = "unsupported";- if (r.FaceANormal is null || r.FaceBNormal is null) { reason = "missing-face-normal"; return false; }- if (!TryNormalize(r.FaceANormal.Value, out var a) || !TryNormalize(r.FaceBNormal.Value, out var b)) { reason = "non-finite-normal"; return false; }- var angle = Math.Acos(Math.Clamp(Vector3.Dot(a, b), -1f, 1f)) * (180d / Math.PI);- if (!Finite(angle)) { reason = "non-finite-angle"; return false; }- if (angle < MinStablePlanarAngleDeg || (180d - angle) < MinStablePlanarAngleDeg) { reason = "near-parallel"; return false; }- if (angle < 20d) { reason = "shallow-angle-unstable"; return false; }- return true;- }}diff --git a/Aetheris.FrictionLab.Tests/CIRLab/AirChamferPolicyLabTests.cs b/Aetheris.FrictionLab.Tests/CIRLab/AirChamferPolicyLabTests.csindex a0e46bc9..83a07695 100644--- a/Aetheris.FrictionLab.Tests/CIRLab/AirChamferPolicyLabTests.cs+++ b/Aetheris.FrictionLab.Tests/CIRLab/AirChamferPolicyLabTests.cs@@ -12,6 +12,13 @@ public sealed class AirChamferPolicyLabTestsAssert.Equal(a.Select(Serialize), b.Select(Serialize));}+ [Fact]+ public void Diagnostics_IncludeJudgmentEngineUsage()+ {+ var row = AirChamferPolicyLab.Evaluate(AirChamferPolicyLab.Cases().Single(x => x.CaseName == "canonical-concave-planar"));+ Assert.Contains("edge-x3-judgment-engine-used", row.Diagnostics);+ }+[Fact]public void CanonicalConcavePlanar_AcceptsAndConstructsPatch(){@@ -23,16 +30,14 @@ public sealed class AirChamferPolicyLabTests[Theory][InlineData("nonorthogonal-concave-planar-safe", "accept-air-chamfer-patch")]- [InlineData("nonorthogonal-concave-planar-shallow", "defer-nonorthogonal-policy")]- [InlineData("nonorthogonal-concave-planar-near-parallel", "reject-invalid-face-adjacency")]- [InlineData("convex-planar", "defer-convex-replacement-policy")]+ [InlineData("convex-planar", "defer-convex-replacement-geometry")]+ [InlineData("convex-planar-unsafe-envelope", "reject-unsafe-offset-envelope")][InlineData("edge-chain", "defer-edge-chain-policy")][InlineData("corner-chain", "defer-corner-policy")]- [InlineData("cylindrical-face", "defer-unsupported-face-family")][InlineData("triangle-legacy-dependent", "fallback-legacy-chamfer")][InlineData("invalid-distance-zero", "reject-invalid-distance")][InlineData("invalid-edge-zero-length", "reject-invalid-edge")]- [InlineData("invalid-face-adjacency-parallel", "reject-invalid-face-adjacency")]+ [InlineData("invalid-face-adjacency-missing", "reject-invalid-face-adjacency")][InlineData("ambiguous-classification", "reject-ambiguous-classification")]public void FixtureCases_ProduceExpectedDecision(string caseName, string expected){@@ -55,13 +60,12 @@ public sealed class AirChamferPolicyLabTests}[Fact]- public void NonOrthogonalAcceptedCase_EmitsNo3dBooleanDiagnostic()+ public void NoConvexReplacementGeometry_IsEmitted(){- var result = AirChamferPolicyLab.Evaluate(AirChamferPolicyLab.Cases().Single(x => x.CaseName == "nonorthogonal-concave-planar-safe"));- Assert.Equal("accept-air-chamfer-patch", result.Decision.Decision);- Assert.NotNull(result.PatchRow);- Assert.Contains("edge-x2-no-3d-boolean-used", result.PatchRow!.Diagnostics);- Assert.Contains("edge-x2-2-policy-nonorthogonal-concave-admitted", result.Diagnostics);+ var row = AirChamferPolicyLab.Evaluate(AirChamferPolicyLab.Cases().Single(x => x.CaseName == "convex-planar"));+ Assert.Equal("defer-convex-replacement-geometry", row.Decision.Decision);+ Assert.Null(row.PatchRow);+ Assert.Contains("edge-x3-convex-replacement-deferred:no-topology-replacement-plan", row.Diagnostics);}private static string Serialize(AirChamferPolicyRow row)diff --git a/docs/frictionlab/edge-x2-1-air-chamfer-policy-scaffold-lab.md b/docs/frictionlab/edge-x2-1-air-chamfer-policy-scaffold-lab.mdindex 9d6550f7..6e6a6097 100644--- a/docs/frictionlab/edge-x2-1-air-chamfer-policy-scaffold-lab.md+++ b/docs/frictionlab/edge-x2-1-air-chamfer-policy-scaffold-lab.md@@ -67,3 +67,5 @@ Based on policy results:- EDGE-X3 convex planar replacement policy lab.> Update (EDGE-X2.2): safe non-orthogonal concave planar single-edge fixtures are now admitted in lab policy when angle/offset admissibility checks pass; shallow/near-parallel cases remain deferred/rejected with explicit diagnostics.++> Update (EDGE-X3): policy scoring/admissibility is now aligned to `Aetheris.Kernel.Core.Judgment` via lab-only Judgment candidates and deterministic diagnostics in EDGE-X3.diff --git a/docs/frictionlab/edge-x2-2-nonorthogonal-concave-air-chamfer-policy-patch-lab.md b/docs/frictionlab/edge-x2-2-nonorthogonal-concave-air-chamfer-policy-patch-lab.mdindex 429d0400..a17de2b0 100644--- a/docs/frictionlab/edge-x2-2-nonorthogonal-concave-air-chamfer-policy-patch-lab.md+++ b/docs/frictionlab/edge-x2-2-nonorthogonal-concave-air-chamfer-policy-patch-lab.md@@ -83,3 +83,5 @@ Accepted geometry paths still emit `edge-x2-no-3d-boolean-used` and policy rows## Recommendation for next milestoneProgress to convex planar replacement policy lab (EDGE-X3 lane) while keeping concave non-orthogonal proven path bounded and deterministic.++> Update (EDGE-X3): concave acceptance lanes from EDGE-X2.2 are now regression-covered under a JudgmentEngine-backed policy evaluator while convex replacement remains deferred.diff --git a/docs/frictionlab/edge-x3-convex-planar-air-chamfer-judgment-policy-lab.md b/docs/frictionlab/edge-x3-convex-planar-air-chamfer-judgment-policy-lab.mdnew file mode 100644index 00000000..604ef346--- /dev/null+++ b/docs/frictionlab/edge-x3-convex-planar-air-chamfer-judgment-policy-lab.md@@ -0,0 +1,55 @@+# EDGE-X3 — Convex planar AirChamfer Judgment policy lab++## Purpose and scope+EDGE-X3 adds a **lab-only** policy evaluator for convex planar single-edge chamfer requests using `Aetheris.Kernel.Core.Judgment.JudgmentEngine<TContext>`. It classifies requests into deterministic accept/defer/reject/fallback outcomes and emits machine-checkable diagnostics. No convex replacement geometry is emitted in this milestone.++## References+- EDGE-A0 audit: `docs/edge-a0-air-edge-sweep-fillet-chamfer-audit.md`+- EDGE-X1 matrix: `docs/frictionlab/edge-x1-chamfer-fillet-capability-matrix.md`+- EDGE-X2 patch proof: `docs/frictionlab/edge-x2-concave-planar-chamfer-patch-lab.md`+- EDGE-X2.1 scaffold: `docs/frictionlab/edge-x2-1-air-chamfer-policy-scaffold-lab.md`+- EDGE-X2.2 non-orthogonal concave: `docs/frictionlab/edge-x2-2-nonorthogonal-concave-air-chamfer-policy-patch-lab.md`++## Why JudgmentEngine+EDGE-X3 is a bounded strategy-selection problem. `JudgmentEngine` already provides admissibility, deterministic score ordering, tie-break behavior, and rejection data; EDGE-X3 uses that substrate directly (no parallel utility framework).++## Judgment infrastructure touched+- `Aetheris.Kernel.Core.Judgment.JudgmentEngine<TContext>`+- `JudgmentCandidate<TContext>`+- `JudgmentResult<TContext>`++## Request/candidate/decision model+`AirChamferPolicyLab` now builds a judgment context with consideration metrics and evaluates a finite candidate set including:+- `accept-air-chamfer-patch`+- convex deferrals: `defer-convex-replacement-policy`, `defer-convex-replacement-geometry`+- chain/corner/legacy deferrals/fallback+- invalid and unsafe rejects++## Considerations and score model+Deterministic considerations:+- `geometry-support`+- `offset-stability`+- `corner-policy`+- `legacy-readiness`++Diagnostics include:+- `edge-x3-judgment-engine-used`+- `edge-x3-judgment-candidate-created:<name>`+- `edge-x3-judgment-score:<candidate>:<score>`+- `edge-x3-judgment-consideration:<name>:<value>`+- `edge-x3-decision:<decision>`++## Fixture outcomes+- Valid-looking convex planar single-edge: `defer-convex-replacement-geometry`+- Unsafe convex envelope: `reject-unsafe-offset-envelope`+- Canonical concave planar: accepted+- Safe non-orthogonal concave planar: accepted+- Edge/corner chain: deferred+- Legacy-dependent triangle/chamfer fixture: fallback/defer legacy+- Invalid distance/edge/adjacency/classification: rejected++## Non-goals+No production route changes, no public API changes, no STEP/Boolean changes, no convex replacement geometry, no fillet emission, no chain/corner implementation, no triangle migration retries.++## Next milestone+Implement bounded convex replacement topology planning lane (still policy-gated), then wire geometry emission only after admissibility and replacement-plan diagnostics are stable.