Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Implement direct two-edge junction chamfer export
Yuechen Li2fd3c4a1794a
diff --git a/Aetheris.CLI.Tests/LocalizedPlanarSingleEdgeChamferPipelineTests.cs b/Aetheris.CLI.Tests/LocalizedPlanarSingleEdgeChamferPipelineTests.csindex a23ade00..bfd28a19 100644--- a/Aetheris.CLI.Tests/LocalizedPlanarSingleEdgeChamferPipelineTests.cs+++ b/Aetheris.CLI.Tests/LocalizedPlanarSingleEdgeChamferPipelineTests.cs@@ -74,7 +74,7 @@ public sealed class LocalizedPlanarSingleEdgeChamferPipelineTests}[Fact]- public void LocalizedPlanarReplacement_TwoEdgeJunction_RequiresExplicitConstructionWitness()+ public void LocalizedPlanarReplacement_TwoEdgeJunction_ExportsOneAuthoritativeMiterPlan(){var run = Run("""Model Localized mm@@ -84,8 +84,23 @@ public sealed class LocalizedPlanarSingleEdgeChamferPipelineTestsEdgeFinish Second { Face: +Y Target: SharedEdgePlusZ Kind: Chamfer Distance: 1mm }}""");- Assert.Equal(1, run.Exit);- Assert.Contains("localized-chamfer-construction-witness-required:two-edge-junction", run.Output, StringComparison.Ordinal);+ Assert.Equal(0, run.Exit);+ using var json = JsonDocument.Parse(run.Output);+ var junction = json.RootElement.GetProperty("air").GetProperty("localizedEdgeJunction");+ Assert.Equal("Direct", junction.GetProperty("selectionMode").GetString());+ Assert.Equal("MiteredReplacementBoundary", junction.GetProperty("cornerPatch").GetString());+ Assert.Equal(2, junction.GetProperty("replacementFaces").GetInt32());+ Assert.Equal(0, junction.GetProperty("junctionFaces").GetInt32());+ Assert.Equal(1, junction.GetProperty("candidatePlans").GetInt32());+ Assert.Equal(1, junction.GetProperty("hardValidPlans").GetInt32());+ Assert.True(junction.GetProperty("bRepPlan").GetProperty("authoritative").GetBoolean());+ Assert.Equal("valid", junction.GetProperty("preflight").GetString());+ Assert.False(junction.GetProperty("legacyFallback").GetBoolean());+ var imported = Step242Importer.ImportBody(File.ReadAllText(json.RootElement.GetProperty("outputPath").GetString()!));+ Assert.True(imported.IsSuccess);+ Assert.Equal(11, imported.Value!.Topology.Vertices.Count());+ Assert.Equal(17, imported.Value.Topology.Edges.Count());+ Assert.Equal(8, imported.Value.Topology.Faces.Count());}private static (int Exit, string Output) Run(string source)diff --git a/Aetheris.CLI.Tests/LocalizedTangentBlendFilletPipelineTests.cs b/Aetheris.CLI.Tests/LocalizedTangentBlendFilletPipelineTests.csindex f9f39b83..38be44a4 100644--- a/Aetheris.CLI.Tests/LocalizedTangentBlendFilletPipelineTests.cs+++ b/Aetheris.CLI.Tests/LocalizedTangentBlendFilletPipelineTests.cs@@ -88,7 +88,7 @@ public sealed class LocalizedTangentBlendFilletPipelineTests}""");Assert.Equal(1, run.Exit);- Assert.Contains("localized-fillet-construction-witness-required:two-edge-junction", run.Output, StringComparison.Ordinal);+ Assert.Contains("localized-junction-unsupported-finish-combination:fillet-shared-patch-surface-required", run.Output, StringComparison.Ordinal);}private static (int Exit, string Output) Run(string source)diff --git a/Aetheris.Kernel.Core.Tests/Air/LocalizedEdgeJunctionChamferTests.cs b/Aetheris.Kernel.Core.Tests/Air/LocalizedEdgeJunctionChamferTests.csnew file mode 100644index 00000000..efb5e037--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Air/LocalizedEdgeJunctionChamferTests.cs@@ -0,0 +1,69 @@+using Aetheris.Kernel.Core.Air;+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Geometry;+using Aetheris.Kernel.Core.Step242;++namespace Aetheris.Kernel.Core.Tests.Air;++public sealed class LocalizedEdgeJunctionChamferTests+{+ [Theory]+ [InlineData(10d, 8d, 6d, 1d)]+ [InlineData(10d, 8d, 6d, 2d)]+ [InlineData(12d, 5d, 7d, 1d)]+ public void EqualDistanceTwoEdgeJunction_BuildsOneExactDirectMiterPlan(double width, double depth, double height, double distance)+ {+ var result = AirLocalizedEdgeJunctionChamferCompiler.Compile(Request(width, depth, height, distance, distance));++ Assert.True(result.Succeeded, result.Error?.Code);+ var construction = Assert.IsType<LocalizedEdgeJunctionConstruction>(result.Construction);+ var plan = Assert.IsType<Aetheris.Kernel.Core.Air.BRepPlan.AirBRepPlan>(result.BRepPlan);+ var body = Assert.IsType<BrepBody>(result.Body);+ Assert.True(plan.IsAuthoritative);+ Assert.NotNull(plan.LocalizedEdgeJunctionRealizationPlan);+ Assert.Equal("MiteredReplacementBoundary", construction.CornerPatch.Kind);+ Assert.Equal(2, construction.CornerPatch.Boundary.Count);+ Assert.Equal(11, body.Topology.Vertices.Count());+ Assert.Equal(17, body.Topology.Edges.Count());+ Assert.Equal(8, body.Topology.Faces.Count());+ Assert.Equal(8, body.Geometry.Surfaces.Count(surface => surface.Value.Kind == SurfaceGeometryKind.Plane));+ Assert.True(BrepExportPreflight.Validate(body).IsValid);++ var p = construction.CornerPatch.Boundary[0];+ var q = construction.CornerPatch.Boundary[1];+ Assert.Equal(width / 2d, p.X, 9);+ Assert.Equal(height / 2d - distance, p.Z, 9);+ Assert.Equal(width / 2d - distance, q.X, 9);+ Assert.Equal(depth / 2d - distance, q.Y, 9);+ Assert.Equal(height / 2d, q.Z, 9);+ Assert.Equal(width * depth * height - distance * distance * (width + depth) / 2d + distance * distance * distance / 3d,+ AnalyticVolume(width, depth, height, distance), 9);++ var step = Step242Exporter.ExportBody(body, new Step242ExportOptions { BrepExportPreflightMode = BrepExportPreflightMode.Enforce });+ Assert.True(step.IsSuccess, string.Join(Environment.NewLine, step.Diagnostics.Select(d => d.Message)));+ var imported = Step242Importer.ImportBody(step.Value!);+ Assert.True(imported.IsSuccess, string.Join(Environment.NewLine, imported.Diagnostics.Select(d => d.Message)));+ Assert.Equal(11, imported.Value!.Topology.Vertices.Count());+ Assert.Equal(17, imported.Value.Topology.Edges.Count());+ Assert.Equal(8, imported.Value.Topology.Faces.Count());+ }++ [Theory]+ [InlineData(1d, 2d, "localized-junction-parameter-mismatch")]+ [InlineData(0d, 0d, "localized-junction-distance-must-be-positive")]+ [InlineData(6d, 6d, "localized-junction-distance-too-large")]+ public void JunctionAdmission_RejectsUnsupportedParametersBeforeEmission(double first, double second, string code)+ {+ var result = AirLocalizedEdgeJunctionChamferCompiler.Compile(Request(10, 8, 6, first, second));+ Assert.False(result.Succeeded);+ Assert.Null(result.Body);+ Assert.Equal(code, result.Error?.Code);+ }++ private static AirLocalizedEdgeJunctionChamferCompileRequest Request(double width, double depth, double height, double first, double second) => new(+ "Base", "Base.First.Second", "First+Second", width, depth, height,+ "+X", "SharedEdgePlusZ", "+Y", "SharedEdgePlusZ", first, second, new AirSourceSpan(0, 1, "test"));++ private static double AnalyticVolume(double width, double depth, double height, double distance) =>+ width * depth * height - distance * distance * (width + depth) / 2d + distance * distance * distance / 3d;+}diff --git a/Aetheris.Kernel.Core/Air/AirBRepPlan.cs b/Aetheris.Kernel.Core/Air/AirBRepPlan.csindex 56823106..d678e76d 100644--- a/Aetheris.Kernel.Core/Air/AirBRepPlan.cs+++ b/Aetheris.Kernel.Core/Air/AirBRepPlan.cs@@ -3,9 +3,9 @@ using Aetheris.Kernel.Core.Brep.Prismatic;namespace Aetheris.Kernel.Core.Air.BRepPlan;-internal enum AirBRepPlanKind { PrismaticSectionTransition, RevolvedProfile, LocalizedPlanarReplacement, LocalizedTangentBlend, Unsupported }+internal enum AirBRepPlanKind { PrismaticSectionTransition, RevolvedProfile, LocalizedPlanarReplacement, LocalizedTangentBlend, LocalizedEdgeJunction, Unsupported }internal enum AirBRepPlanElementKind { Vertex, Curve, Edge, Coedge, Loop, Surface, Face, Shell, Body }-internal enum AirBRepPlanRole { Unknown, SectionVertex, SectionEdge, VerticalTransitionEdge, SectionLoop, ProfileVertex, ProfileSegment, CircularRim, SeamEdge, CapFace, SideFace, CylindricalFace, ConicalTransitionFace, TransitionFace, PrismaticTransitionFace, ChamferFace, FilletFace, ReplacementFace, ReplacementBoundaryA, ReplacementBoundaryB, RetainedSupportFaceA, RetainedSupportFaceB, EndpointTransitionStart, EndpointTransitionEnd, UnaffectedFace, BodyShell, Body }+internal enum AirBRepPlanRole { Unknown, SectionVertex, SectionEdge, VerticalTransitionEdge, SectionLoop, ProfileVertex, ProfileSegment, CircularRim, SeamEdge, CapFace, SideFace, CylindricalFace, ConicalTransitionFace, TransitionFace, PrismaticTransitionFace, ChamferFace, FilletFace, ReplacementFace, ReplacementFaceA, ReplacementFaceB, ReplacementBoundaryA, ReplacementBoundaryB, SharedJunction, CornerPatch, RetainedSupportFaceA, RetainedSupportFaceB, EndpointTransitionStart, EndpointTransitionEnd, RemoteEndpointA, RemoteEndpointB, UnaffectedFace, BodyShell, Body }internal readonly record struct AirBRepPlanId(string Value){@@ -79,9 +79,10 @@ internal sealed record AirBRepPlan(RevolvedProfileTopologyPlan? RevolvedRealizationPlan = null,AirLocalizedPlanarReplacementTopologyPlan? LocalizedPlanarReplacementRealizationPlan = null,AirLocalizedTangentBlendTopologyPlan? LocalizedTangentBlendRealizationPlan = null,- LocalizedEdgeReplacementTopologyPlan? LocalizedEdgeReplacementRealizationPlan = null)+ LocalizedEdgeReplacementTopologyPlan? LocalizedEdgeReplacementRealizationPlan = null,+ LocalizedEdgeJunctionTopologyPlan? LocalizedEdgeJunctionRealizationPlan = null){- public bool IsAuthoritative => RealizationPlan is not null || RevolvedRealizationPlan is not null || LocalizedPlanarReplacementRealizationPlan is not null || LocalizedTangentBlendRealizationPlan is not null || LocalizedEdgeReplacementRealizationPlan is not null;+ public bool IsAuthoritative => RealizationPlan is not null || RevolvedRealizationPlan is not null || LocalizedPlanarReplacementRealizationPlan is not null || LocalizedTangentBlendRealizationPlan is not null || LocalizedEdgeReplacementRealizationPlan is not null || LocalizedEdgeJunctionRealizationPlan is not null;}internal sealed record AirBRepPlanResult(AirBRepPlan? Plan, AirBRepPlanValidationResult Validation)diff --git a/Aetheris.Kernel.Core/Air/AirLocalizedEdgeJunctionChamferCompiler.cs b/Aetheris.Kernel.Core/Air/AirLocalizedEdgeJunctionChamferCompiler.csnew file mode 100644index 00000000..9f21823c--- /dev/null+++ b/Aetheris.Kernel.Core/Air/AirLocalizedEdgeJunctionChamferCompiler.cs@@ -0,0 +1,171 @@+using System.Security.Cryptography;+using System.Text;+using Aetheris.Kernel.Core.Air.BRepPlan;+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Geometry;+using Aetheris.Kernel.Core.Math;++namespace Aetheris.Kernel.Core.Air;++/// <summary>+/// Bounded M3 construction for the only admitted junction: the +X/+Z and +Y/+Z+/// convex box edges, with equal-distance planar chamfers. The two cut planes meet+/// in one owned miter edge; therefore an additional corner face would overlap the+/// replacement region and is not admissible.+/// </summary>+internal sealed record AirLocalizedEdgeJunctionChamferCompileRequest(+ string BodyId, string FeatureId, string FeatureName, double Width, double Depth, double Height,+ string FaceA, string TargetA, string FaceB, string TargetB, double DistanceA, double DistanceB,+ AirSourceSpan SourceSpan, bool HistoryKnown = true);++internal sealed record LocalizedEdgeJunctionReplacement(+ string SemanticEdge, AirEdgeFinishFeature Feature, IReadOnlyList<Point3D> Boundary,+ IReadOnlyList<Point3D> RemoteEndpointBoundary, string SurfaceFamily);++/// <summary>The exact zero-area closure is materialized as an owned miter boundary, not metadata.</summary>+internal sealed record LocalizedEdgeJunctionCornerPatch(+ string Kind, IReadOnlyList<Point3D> Boundary, string Closure, string SurfaceFamily);++internal sealed record LocalizedEdgeJunctionTopologyPlan(+ IReadOnlyList<Point3D> Vertices, IReadOnlyList<IReadOnlyList<int>> FaceLoops,+ IReadOnlyList<string> FaceRoles, string DeterministicSignature)+{+ public int ExpectedVertexCount => Vertices.Count;+ public int ExpectedFaceCount => FaceLoops.Count;+ public int ExpectedEdgeCount => FaceLoops.Sum(loop => loop.Count) / 2;+ public int ExpectedLoopCount => ExpectedFaceCount;+ public int ExpectedCoedgeCount => FaceLoops.Sum(loop => loop.Count);+}++/// <summary>Construction AIR owns both replacement regions and their shared miter closure.</summary>+internal sealed record LocalizedEdgeJunctionConstruction(+ string ConstructionId, LocalizedEdgeJunctionReplacement ReplacementA,+ LocalizedEdgeJunctionReplacement ReplacementB, Point3D SharedEndpoint,+ Point3D RemoteEndpointA, Point3D RemoteEndpointB, LocalizedEdgeJunctionCornerPatch CornerPatch,+ IReadOnlyList<IReadOnlyList<Point3D>> RetainedRegions, string MaterialSide,+ string BoundaryOwnership, LocalizedEdgeJunctionTopologyPlan TopologyPlan, string Provenance);++internal sealed record AirLocalizedEdgeJunctionChamferCompileResult(+ bool Succeeded, LocalizedEdgeJunctionConstruction? Construction, AirBRepPlan? BRepPlan,+ BrepBody? Body, ChamferLoweringError? Error, IReadOnlyList<string> Diagnostics)+{+ public const string ProductionRoute = "AirLocalizedEdgeJunctionChamferM3";+}++internal static class AirLocalizedEdgeJunctionChamferCompiler+{+ private const double Tol = 1e-9;++ public static AirLocalizedEdgeJunctionChamferCompileResult Compile(AirLocalizedEdgeJunctionChamferCompileRequest input)+ {+ var lowered = Lower(input);+ if (!lowered.IsSuccess)+ return new(false, null, null, null, lowered.Error, [lowered.Error!.Code]);++ var construction = lowered.Value!;+ var plan = BuildPlan(input, construction);+ var emitted = LocalizedEdgeReplacementCompilerModel.EmitPlanarPolyhedron(construction.TopologyPlan.Vertices, construction.TopologyPlan.FaceLoops);+ if (!emitted.Succeeded || emitted.Body is null)+ return Failure(construction, plan, ChamferLoweringErrorKind.BackendMaterializationDefect, "localized-junction-chamfer-materialization-failed", "The authoritative junction plan did not materialize.", emitted.Diagnostics);++ var body = emitted.Body;+ if (body.Topology.Vertices.Count() != construction.TopologyPlan.ExpectedVertexCount ||+ body.Topology.Edges.Count() != construction.TopologyPlan.ExpectedEdgeCount ||+ body.Topology.Faces.Count() != construction.TopologyPlan.ExpectedFaceCount ||+ body.Geometry.Surfaces.Count(surface => surface.Value.Kind == SurfaceGeometryKind.Plane) != 8)+ return Failure(construction, plan, ChamferLoweringErrorKind.VerificationFailure, "localized-junction-chamfer-analytic-topology-verification-failed", "The mitered junction must contain 11 vertices, 17 edges, and eight planar faces.");++ return new(true, construction, plan, body, null,+ ["localized-junction-chamfer-feature-admitted", "localized-junction-chamfer-candidate-plans=1", "localized-junction-chamfer-hard-valid-plans=1", "localized-junction-chamfer-direct-miter", "localized-junction-chamfer-authoritative-brep-plan-consumed", "localized-junction-chamfer-no-legacy-fallback"]);+ }++ public static ChamferLoweringResult<LocalizedEdgeJunctionConstruction> Lower(AirLocalizedEdgeJunctionChamferCompileRequest input)+ {+ ChamferLoweringResult<LocalizedEdgeJunctionConstruction> Fail(ChamferLoweringErrorKind kind, string code, string message) =>+ ChamferLoweringResult<LocalizedEdgeJunctionConstruction>.Err(new(kind, code, message, "FeatureAIR->ConstructionAIR"));+ if (!input.HistoryKnown) return Fail(ChamferLoweringErrorKind.UnsupportedHistory, "localized-junction-unsupported-history", "Localized junctions require known axis-aligned box history.");+ if (!FinitePositive(input.Width) || !FinitePositive(input.Depth) || !FinitePositive(input.Height)) return Fail(ChamferLoweringErrorKind.InvalidAuthoredInput, "localized-junction-invalid-box-dimensions", "Box dimensions must be finite and positive.");+ if (!Matches(input.FaceA, input.TargetA, "+X", "SharedEdgePlusZ") || !Matches(input.FaceB, input.TargetB, "+Y", "SharedEdgePlusZ"))+ return Fail(ChamferLoweringErrorKind.UnsupportedSelection, "localized-junction-edges-do-not-share-canonical-endpoint", "M3 admits SharedEdge(+X,+Z) and SharedEdge(+Y,+Z) only, in that order.");+ if (!FinitePositive(input.DistanceA) || !FinitePositive(input.DistanceB)) return Fail(ChamferLoweringErrorKind.InvalidAuthoredInput, "localized-junction-distance-must-be-positive", "Both chamfer distances must be finite and positive.");+ if (double.Abs(input.DistanceA - input.DistanceB) > Tol) return Fail(ChamferLoweringErrorKind.ConstructionWitnessRequired, "localized-junction-parameter-mismatch", "The admitted miter construction requires equal chamfer distances.");+ var d = input.DistanceA;+ if (d >= input.Width - Tol || d >= input.Depth - Tol || d >= input.Height - Tol)+ return Fail(ChamferLoweringErrorKind.DistanceTooLarge, "localized-junction-distance-too-large", "The equal distance must remain within all three incident box extents.");++ var hx = input.Width / 2d; var hy = input.Depth / 2d; var hz = input.Height / 2d;+ var featureA = Feature(input, "A", "+X", "SharedEdge(+X,+Z)", d);+ var featureB = Feature(input, "B", "+Y", "SharedEdge(+Y,+Z)", d);+ var shared = new Point3D(hx, hy, hz);+ var remoteA = new Point3D(hx, -hy, hz);+ var remoteB = new Point3D(-hx, hy, hz);+ var p = new Point3D(hx, hy, hz - d);+ var q = new Point3D(hx - d, hy - d, hz);+ var vertices = new[]+ {+ new Point3D(-hx, -hy, -hz), new Point3D(hx, -hy, -hz), new Point3D(hx, hy, -hz), new Point3D(-hx, hy, -hz),+ new Point3D(-hx, -hy, hz), new Point3D(hx, -hy, hz - d), new Point3D(hx - d, -hy, hz),+ new Point3D(-hx, hy, hz - d), new Point3D(-hx, hy - d, hz), p, q+ };+ IReadOnlyList<int>[] loops =+ [+ [0, 3, 2, 1], // -Z+ [0, 4, 8, 7, 3], // -X / remote B transition+ [0, 1, 5, 6, 4], // -Y / remote A transition+ [1, 2, 9, 5], // +X+ [3, 7, 9, 2], // +Y+ [4, 6, 10, 8], // +Z+ [5, 9, 10, 6], // replacement A+ [7, 8, 10, 9], // replacement B; owns the opposite miter coedge+ ];+ var signature = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(FormattableString.Invariant($"localized-edge-junction:Chamfer:+X,+Z:+Y,+Z:{input.Width:R}:{input.Depth:R}:{input.Height:R}:{d:R}:direct-miter"))));+ var topology = new LocalizedEdgeJunctionTopologyPlan(vertices, loops,+ ["UnaffectedFace(-Z)", "RemoteEndpointB(-X)", "RemoteEndpointA(-Y)", "RetainedSupportFace(+X)", "RetainedSupportFace(+Y)", "RetainedSupportFace(+Z)", "ReplacementA(PlanarChamfer)", "ReplacementB(PlanarChamfer)"], signature);+ var replacementA = new LocalizedEdgeJunctionReplacement("SharedEdge(+X,+Z)", featureA, [vertices[5], vertices[6], q, p], [vertices[5], vertices[6]], "PlanarChamfer");+ var replacementB = new LocalizedEdgeJunctionReplacement("SharedEdge(+Y,+Z)", featureB, [vertices[7], vertices[8], q, p], [vertices[7], vertices[8]], "PlanarChamfer");+ var patch = new LocalizedEdgeJunctionCornerPatch("MiteredReplacementBoundary", [p, q], "replacementA/replacementB share one opposite-oriented exact coedge; no additional face is admissible", "Line3");+ return ChamferLoweringResult<LocalizedEdgeJunctionConstruction>.Ok(new(+ $"construction:{input.FeatureId}:junction", replacementA, replacementB, shared, remoteA, remoteB, patch,+ [[vertices[1], vertices[2], p, vertices[5]], [vertices[3], vertices[7], p, vertices[2]], [vertices[4], vertices[6], q, vertices[8]]],+ "inside:x<=max,y<=max,z<=max,x+z<=maxX+maxZ-distance,y+z<=maxY+maxZ-distance",+ "SharedMiterEdge(opposite coedges); RemoteEndpointA(-Y); RemoteEndpointB(-X)", topology,+ "history-known-axis-aligned-rectangular-box; equal-distance-planar-miter"));+ }++ private static AirLocalizedEdgeJunctionChamferCompileResult Failure(LocalizedEdgeJunctionConstruction construction, AirBRepPlan plan, ChamferLoweringErrorKind kind, string code, string message, IReadOnlyList<string>? evidence = null) =>+ new(false, construction, plan, null, new(kind, code, message, "BRep", evidence), [code, .. (evidence ?? [])]);++ private static AirEdgeFinishFeature Feature(AirLocalizedEdgeJunctionChamferCompileRequest input, string suffix, string face, string edge, double distance) => new(+ $"{input.FeatureId}.{suffix}", $"{input.FeatureName}.{suffix}", input.BodyId, new AirFaceBoundarySelection(face, edge, false), AirLocalizedEdgeFinishKind.Chamfer,+ new AirEqualDistanceEdgeFinishRule(distance), input.SourceSpan, "generated/history-known-axis-aligned-rectangular-prism", AirFeatureAdmissionStatus.Admitted, "localized-junction-direct-single-miter-candidate");++ private static AirBRepPlan BuildPlan(AirLocalizedEdgeJunctionChamferCompileRequest input, LocalizedEdgeJunctionConstruction construction)+ {+ var provenance = new AirProvenance("AIR-EDGE-FINISH-JUNCTION-M3", "Localized two-edge planar miter", "shared-edge(+X,+Z)/shared-edge(+Y,+Z)", input.FeatureId,+ nameof(AirLocalizedEdgeJunctionChamferCompiler), AirSelectionClass.None, AirRuleKind.UniformChamfer, construction.Provenance, true,+ ["One hard-valid construction.", "Direct miter owns the shared boundary.", "No legacy direct-BRep stitching."]);+ var elements = new List<AirBRepPlanElement>();+ for (var i = 0; i < construction.TopologyPlan.ExpectedVertexCount; i++)+ elements.Add(new(new($"vertex:{i}"), AirBRepPlanElementKind.Vertex, i is 9 or 10 ? AirBRepPlanRole.SharedJunction : i is 5 or 6 ? AirBRepPlanRole.RemoteEndpointA : i is 7 or 8 ? AirBRepPlanRole.RemoteEndpointB : AirBRepPlanRole.SectionVertex, input.FeatureId, provenance));+ for (var i = 0; i < construction.TopologyPlan.ExpectedFaceCount; i++)+ {+ var role = i == 6 ? AirBRepPlanRole.ReplacementFaceA : i == 7 ? AirBRepPlanRole.ReplacementFaceB : i == 1 ? AirBRepPlanRole.RemoteEndpointB : i == 2 ? AirBRepPlanRole.RemoteEndpointA : i is 3 or 4 or 5 ? AirBRepPlanRole.RetainedSupportFaceA : AirBRepPlanRole.UnaffectedFace;+ elements.Add(new(new($"loop:{i}"), AirBRepPlanElementKind.Loop, role, input.FeatureId, provenance));+ for (var c = 0; c < construction.TopologyPlan.FaceLoops[i].Count; c++) elements.Add(new(new($"coedge:{i}:{c}"), AirBRepPlanElementKind.Coedge, role, input.FeatureId, provenance));+ elements.Add(new(new($"face:{i}"), AirBRepPlanElementKind.Face, role, input.FeatureId, provenance, FaceRole: construction.TopologyPlan.FaceRoles[i], SemanticRoles: i is 6 or 7 ? [role, AirBRepPlanRole.ReplacementFace, AirBRepPlanRole.ChamferFace] : [role]));+ }+ for (var i = 0; i < construction.TopologyPlan.ExpectedEdgeCount; i++) elements.Add(new(new($"edge:{i}"), AirBRepPlanElementKind.Edge, i == construction.TopologyPlan.ExpectedEdgeCount - 1 ? AirBRepPlanRole.SharedJunction : AirBRepPlanRole.SectionEdge, input.FeatureId, provenance));+ for (var i = 0; i < construction.TopologyPlan.ExpectedFaceCount; i++) elements.Add(new(new($"surface:{i}"), AirBRepPlanElementKind.Surface, i == 6 ? AirBRepPlanRole.ReplacementFaceA : i == 7 ? AirBRepPlanRole.ReplacementFaceB : AirBRepPlanRole.RetainedSupportFaceA, input.FeatureId, provenance));+ elements.Add(new(new("corner-patch:miter:0"), AirBRepPlanElementKind.Curve, AirBRepPlanRole.CornerPatch, input.FeatureId, provenance, SemanticRoles: [AirBRepPlanRole.CornerPatch, AirBRepPlanRole.SharedJunction]));+ elements.Add(new(new("shell:0"), AirBRepPlanElementKind.Shell, AirBRepPlanRole.BodyShell, input.FeatureId, provenance));+ elements.Add(new(new("body:0"), AirBRepPlanElementKind.Body, AirBRepPlanRole.Body, input.FeatureId, provenance));+ var p = construction.TopologyPlan;+ var summary = new AirBRepPlanSummary(AirBRepPlanKind.LocalizedEdgeJunction, input.FeatureId, p.ExpectedVertexCount, p.ExpectedEdgeCount, p.ExpectedEdgeCount, p.ExpectedCoedgeCount, p.ExpectedLoopCount, p.ExpectedFaceCount, p.ExpectedFaceCount, 1, 1, 0, 3, 2, 2,+ $"localized-edge-junction=Chamfer;signature={p.DeterministicSignature}", construction.BoundaryOwnership, [], ["authoritative combined junction topology", "direct single hard-valid miter candidate", "no legacy fallback"],+ new(AirNodeKind.Unsupported, AirRouteKind.Unsupported, AirSelectionClass.None, AirRuleKind.UniformChamfer, construction.Provenance, "Direct", ["SharedEdge(+X,+Z)", "SharedEdge(+Y,+Z)"]));+ return new($"brep-plan:localized-edge-junction:{input.FeatureId}", AirBRepPlanKind.LocalizedEdgeJunction, input.FeatureId, provenance, elements, summary, [], summary.Guarantees, summary.FeatureContext, LocalizedEdgeJunctionRealizationPlan: p);+ }++ private static bool FinitePositive(double value) => double.IsFinite(value) && value > Tol;+ private static bool Matches(string face, string target, string expectedFace, string expectedTarget) => string.Equals(face, expectedFace, StringComparison.Ordinal) && string.Equals(target, expectedTarget, StringComparison.Ordinal);+}diff --git a/Aetheris.Kernel.Core/Air/LocalizedEdgeReplacement.cs b/Aetheris.Kernel.Core/Air/LocalizedEdgeReplacement.csindex 44d5cb8c..4c917b69 100644--- a/Aetheris.Kernel.Core/Air/LocalizedEdgeReplacement.cs+++ b/Aetheris.Kernel.Core/Air/LocalizedEdgeReplacement.cs@@ -161,6 +161,72 @@ internal static class LocalizedEdgeReplacementCompilerModelreturn check.IsSuccess ? new(true, body, ["localized-edge-replacement-plan-emitted"]) : new(false, null, check.Diagnostics.Select(d => d.Message).ToArray());}+ /// <summary>+ /// Shared plan-consuming emitter for finite planar replacement realizations. Junction+ /// compilers give it complete ordered loops; it never discovers or stitches topology.+ /// </summary>+ internal static AirLocalizedEdgeReplacementEmissionResult EmitPlanarPolyhedron(+ IReadOnlyList<Point3D> points, IReadOnlyList<IReadOnlyList<int>> faceLoops)+ {+ if (points.Count < 4 || faceLoops.Count < 4 || faceLoops.Any(loop => loop.Count < 3 || loop.Any(index => index < 0 || index >= points.Count)))+ return new(false, null, ["localized-edge-replacement-invalid-planar-polyhedron-plan"]);++ var builder = new TopologyBuilder();+ var vertices = points.Select(_ => builder.AddVertex()).ToArray();+ var edges = new Dictionary<(int A, int B), EdgeId>();+ var edgeDirection = new Dictionary<(int A, int B), (int Start, int End)>();+ var faces = new List<FaceId>();+ foreach (var indices in faceLoops)+ {+ var uses = new Use[indices.Count];+ for (var i = 0; i < indices.Count; i++)+ {+ var start = indices[i]; var end = indices[(i + 1) % indices.Count];+ var key = start < end ? (start, end) : (end, start);+ if (!edges.TryGetValue(key, out var edge))+ {+ edge = builder.AddEdge(vertices[start], vertices[end]);+ edges[key] = edge;+ edgeDirection[key] = (start, end);+ }+ var direction = edgeDirection[key];+ uses[i] = direction.Start == start && direction.End == end ? Use.F(edge) : Use.R(edge);+ }+ faces.Add(AddFace(builder, uses));+ }+ var shell = builder.AddShell(faces); builder.AddBody([shell]);+ var geometry = new BrepGeometryStore(); var bindings = new BrepBindingModel(); var curveNumber = 1;+ foreach (var pair in edges.OrderBy(pair => pair.Value.Value))+ {+ var direction = edgeDirection[pair.Key];+ var a = points[direction.Start]; var b = points[direction.End];+ var curveId = new CurveGeometryId(curveNumber++);+ geometry.AddCurve(curveId, CurveGeometry.FromLine(new Line3Curve(a, Direction3D.Create(b - a))));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(pair.Value, curveId, new ParameterInterval(0, (b - a).Length)));+ }+ var surfaceNumber = 1;+ for (var i = 0; i < faces.Count; i++)+ {+ var loop = faceLoops[i];+ var origin = points[loop[0]];+ var u = points[loop[1]] - origin;+ Vector3D? normal = null;+ for (var j = 2; j < loop.Count; j++)+ {+ var candidate = u.Cross(points[loop[j]] - origin);+ if (candidate.Length > Tolerance) { normal = candidate; break; }+ }+ if (normal is null) return new(false, null, ["localized-edge-replacement-degenerate-planar-face"]);+ var surfaceId = new SurfaceGeometryId(surfaceNumber++);+ geometry.AddSurface(surfaceId, SurfaceGeometry.FromPlane(new PlaneSurface(origin, Direction3D.Create(normal.Value), Direction3D.Create(u))));+ bindings.AddFaceBinding(new FaceGeometryBinding(faces[i], surfaceId));+ }+ var vertexPoints = vertices.Select((vertex, index) => new KeyValuePair<VertexId, Point3D>(vertex, points[index])).ToDictionary();+ var body = new BrepBody(builder.Model, geometry, bindings, vertexPoints);+ var check = BrepBindingValidator.Validate(body, true);+ return check.IsSuccess ? new(true, body, ["localized-edge-replacement-plan-emitted"]) : new(false, null, check.Diagnostics.Select(d => d.Message).ToArray());+ }+private static AirBRepPlanRole Role(string faceRole, int faceIndex) =>faceRole.StartsWith("RetainedSupportFaceA", StringComparison.Ordinal) ? AirBRepPlanRole.RetainedSupportFaceA :faceRole.StartsWith("RetainedSupportFaceB", StringComparison.Ordinal) ? AirBRepPlanRole.RetainedSupportFaceB :diff --git a/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs b/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.csindex 5f8b2118..1d42382e 100644--- a/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs+++ b/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs@@ -158,10 +158,21 @@ public static class FirmamentBuildAndExport{var finishes = (document.ModifyBlocks ?? []).SelectMany(m => (m.EdgeFinishes ?? []).Select(f => (Modify: m, Finish: f))).ToArray();if (finishes.Length == 0) return null;- if (finishes.Length == 2 && finishes.All(x => string.Equals(x.Finish.Kind, "Fillet", StringComparison.Ordinal)))- return AirChamferFailure("localized-fillet-construction-witness-required:two-edge-junction");if (finishes.Length == 2 && finishes.All(x => string.Equals(x.Finish.Kind, "Chamfer", StringComparison.Ordinal)))- return AirChamferFailure("localized-chamfer-construction-witness-required:two-edge-junction");+ {+ if (document.Solids.Count != 1 || document.ModifyBlocks!.Count != 1 || document.ModifyBlocks[0].Regions.Count != 0 || document.ModifyBlocks[0].SemanticHoles.Count != 0)+ return AirChamferFailure("localized-junction-production-route-requires-one-box-and-one-modify-block");+ var junctionSolid = document.Solids.SingleOrDefault(s => s.Name == finishes[0].Modify.TargetSolid);+ if (junctionSolid?.Primitive is not FirmamentV2BoxRecord junctionBox || junctionBox.Size.Count != 3)+ return AirChamferFailure("localized-junction-unsupported-history:expected-history-known-box");+ return ExportV2LocalizedEdgeJunctionChamfer(document, junctionSolid, finishes[0].Finish, finishes[1].Finish, junctionBox);+ }+ if (finishes.Length == 2 && finishes.All(x => string.Equals(x.Finish.Kind, "Fillet", StringComparison.Ordinal)))+ return AirChamferFailure("localized-junction-unsupported-finish-combination:fillet-shared-patch-surface-required");+ if (finishes.Length == 2)+ return AirChamferFailure("localized-junction-unsupported-finish-combination:mixed-families");+ if (finishes.Length > 2)+ return AirChamferFailure("localized-junction-unsupported-valence:two-selected-edges-maximum");if (finishes.Length != 1 || document.Solids.Count != 1 || document.ModifyBlocks!.Count != 1|| document.ModifyBlocks[0].Regions.Count != 0 || document.ModifyBlocks[0].SemanticHoles.Count != 0)return AirChamferFailure("air-chamfer-production-route-requires-one-box-and-one-edge-finish");@@ -278,6 +289,53 @@ public static class FirmamentBuildAndExportreturn KernelResult<FirmamentStepExportResult>.Success(new FirmamentStepExportResult(step.Value, compiled.Feature.FeatureId, 0, "air-chamfer", "localized-planar-single-edge-chamfer", Air: report, ConceptIr: document.ConceptIr));}+ private static KernelResult<FirmamentStepExportResult> ExportV2LocalizedEdgeJunctionChamfer(+ FirmamentV2Document document,+ FirmamentV2SolidBinding solid,+ FirmamentV2EdgeFinishDecl first,+ FirmamentV2EdgeFinishDecl second,+ FirmamentV2BoxRecord box)+ {+ var compiled = AirLocalizedEdgeJunctionChamferCompiler.Compile(new(+ solid.Name, $"{solid.Name}.{first.Name}.{second.Name}", $"{first.Name}+{second.Name}", box.Size[0], box.Size[1], box.Size[2],+ first.FaceAxis, first.Target, second.FaceAxis, second.Target, first.Distance, second.Distance,+ new AirSourceSpan(first.SourceSpan.Start, first.SourceSpan.Length + second.SourceSpan.Length, document.ModelName)));+ if (!compiled.Succeeded || compiled.Body is null || compiled.Construction is null || compiled.BRepPlan?.LocalizedEdgeJunctionRealizationPlan is null)+ return AirChamferFailure(compiled.Error?.Code ?? "localized-junction-construction-witness-required", compiled.Diagnostics);++ var body = compiled.Body;+ var preflight = BrepExportPreflight.Validate(body);+ if (!preflight.IsValid) return AirChamferFailure("localized-junction-chamfer-preflight-verification-failed", preflight.Diagnostics.Select(d => d.Code));+ if (!FirmamentManifoldChecker.IsManifold(body)) return AirChamferFailure("localized-junction-chamfer-emitted-body-is-not-manifold");+ var step = Step242Exporter.ExportBody(body, new Step242ExportOptions+ {+ ProductName = compiled.Construction.ConstructionId,+ ApplicationName = AirLocalizedEdgeJunctionChamferCompileResult.ProductionRoute,+ BrepExportPreflightMode = BrepExportPreflightMode.Enforce,+ BrepExportPreflightPolicy = BrepExportPreflightPolicy.TrustedProductionRoute,+ });+ if (!step.IsSuccess || step.Value is null) return KernelResult<FirmamentStepExportResult>.Failure(step.Diagnostics);+ var reimport = Step242Importer.ImportBody(step.Value);+ if (!reimport.IsSuccess || reimport.Value is null || !FirmamentManifoldChecker.IsManifold(reimport.Value))+ return AirChamferFailure("localized-junction-chamfer-step-reimport-verification-failed");++ var topology = compiled.Construction.TopologyPlan;+ var planes = body.Geometry.Surfaces.Count(surface => surface.Value.Kind == SurfaceGeometryKind.Plane);+ var report = new FirmamentAirChamferReport(+ new("Chamfer", solid.Name, $"{solid.Name}.{first.Name}.{second.Name}", $"{first.Name}+{second.Name}", "SharedEdge(+X,+Z),SharedEdge(+Y,+Z)", first.Distance, "mm",+ $"{first.SourceSpan.Start}:{first.SourceSpan.Length}|{second.SourceSpan.Start}:{second.SourceSpan.Length}", "Admitted", "localized-junction-direct-single-miter-candidate",+ new Dictionary<string, string> { ["Selection"] = "semantic Face(+X),Face(+Z); Face(+Y),Face(+Z)", ["MaterialSide"] = compiled.Construction.MaterialSide }),+ new("LocalizedEdgeJunction", 0, [], "ordered-explicit-loops", "SharedMiterEdge",+ $"replacementFaces=2;junctionFaces=0;cornerPatch={compiled.Construction.CornerPatch.Kind};boundaryOwnership={compiled.Construction.BoundaryOwnership}", true),+ new(true, topology.ExpectedVertexCount, topology.ExpectedEdgeCount, topology.ExpectedFaceCount, topology.ExpectedLoopCount, topology.ExpectedCoedgeCount, 2,+ "SharedMiterEdge", topology.DeterministicSignature, "LocalizedEdgeJunction"),+ new(AirLocalizedEdgeJunctionChamferCompileResult.ProductionRoute, false, true, body.Topology.Vertices.Count(), body.Topology.Edges.Count(), body.Topology.Faces.Count(), Bounds(body), first.Distance, first.Distance, 0, 0, planes),+ new("AP242", Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(step.Value))), true, reimport.Value.Topology.Vertices.Count(), reimport.Value.Topology.Edges.Count(), reimport.Value.Topology.Faces.Count(), Bounds(reimport.Value), true),+ LocalizedEdgeJunction: new(["SharedEdge(+X,+Z)", "SharedEdge(+Y,+Z)"], "Chamfer", "EqualDistance", first.Distance, "Direct", "LocalizedEdgeJunction", compiled.Construction.CornerPatch.Kind, 2, 0,+ new(true, topology.DeterministicSignature), "valid", false, 1, 1));+ return KernelResult<FirmamentStepExportResult>.Success(new FirmamentStepExportResult(step.Value, $"{solid.Name}.{first.Name}.{second.Name}", 0, "air-chamfer", "localized-edge-junction-chamfer", Air: report, ConceptIr: document.ConceptIr));+ }+private static KernelResult<FirmamentStepExportResult> ExportV2LocalizedTangentBlendSingleEdgeFillet(FirmamentV2Document document,FirmamentV2SolidBinding solid,diff --git a/Aetheris.Kernel.Firmament/FirmamentStepExportResult.cs b/Aetheris.Kernel.Firmament/FirmamentStepExportResult.csindex 988797ef..d72b2a73 100644--- a/Aetheris.Kernel.Firmament/FirmamentStepExportResult.cs+++ b/Aetheris.Kernel.Firmament/FirmamentStepExportResult.cs@@ -47,7 +47,25 @@ public sealed record FirmamentAirChamferReport(FirmamentAirChamferStepReport Step,FirmamentLocalizedChamferTrace? LocalizedChamfer = null,FirmamentLocalizedFilletTrace? LocalizedFillet = null,- FirmamentLocalizedEdgeFinishTrace? LocalizedEdgeFinish = null);+ FirmamentLocalizedEdgeFinishTrace? LocalizedEdgeFinish = null,+ FirmamentLocalizedEdgeJunctionTrace? LocalizedEdgeJunction = null);++/// <summary>Evidence for the combined two-edge realization; both replacements share one plan.</summary>+public sealed record FirmamentLocalizedEdgeJunctionTrace(+ IReadOnlyList<string> Edges,+ string FinishKind,+ string Rule,+ double Value,+ string SelectionMode,+ string Construction,+ string CornerPatch,+ int ReplacementFaces,+ int JunctionFaces,+ FirmamentLocalizedChamferPlanTrace BRepPlan,+ string Preflight,+ bool LegacyFallback,+ int CandidatePlans,+ int HardValidPlans);/// <summary>Authoritative shared semantic evidence for localized edge replacement routes.</summary>public sealed record FirmamentLocalizedEdgeFinishTrace(diff --git a/docs/air/air-edge-finish-junction-m3.md b/docs/air/air-edge-finish-junction-m3.mdnew file mode 100644index 00000000..2f0df9fe--- /dev/null+++ b/docs/air/air-edge-finish-junction-m3.md@@ -0,0 +1,89 @@+# AIR-EDGE-FINISH-JUNCTION-M3++## Scope and result++M3 admits exactly one two-edge junction: a history-known axis-aligned rectangular box with+`SharedEdge(+X,+Z)` and `SharedEdge(+Y,+Z)`, which meet at `(+X,+Y,+Z)`, and two equal-distance+planar chamfers. The compiler lowers the two Feature AIR intents to one `LocalizedEdgeJunctionConstruction`,+then emits one authoritative `LocalizedEdgeJunction` BRep plan. It does not stitch two independently emitted bodies.++The canonical construction is **Direct**. One candidate was materialized and one is hard-valid; there is no+utility scoring.++## Exact corner construction++For half-extents `(hx, hy, hz)` and equal distance `d`, the replacement planes are:++```text+x + z = hx + hz - d+y + z = hy + hz - d+```++Their valid common boundary is the line segment from `(hx, hy, hz-d)` to+`(hx-d, hy-d, hz)`. It is the only closure of the two finite planar replacement regions.+It is recorded as `MiteredReplacementBoundary`: one exact owned shared edge with opposite coedges in+the two chamfer loops. It is not a planar triangular face. Adding a triangular corner face would overlap+the material already bounded by the two planes, so it is not an alternative valid policy.++The Construction AIR owns both replacement boundaries, the removed shared endpoint, both remote endpoint+transitions, retained `+X`, `+Y`, and `+Z` regions, material side, the miter boundary, and provenance.++## Authoritative topology plan++The combined plan contains 11 vertices, 17 edges, 8 loops/coedges faces, and 34 coedges:++- 3 retained incident supports (`+X`, `+Y`, `+Z`), each exactly trimmed;+- 2 remote-endpoint transition supports (`-Y` for edge A and `-X` for edge B);+- 1 unaffected `-Z` support;+- 2 planar replacement faces, with a shared miter edge;+- one shell and body.++Every edge is a line and all eight face supports are planes. `EmitPlanarPolyhedron` is the shared+plan-consuming localized-edge emitter; it receives ordered plan loops and does not infer or repair topology.++## Admission and deferral++Hard admission requires known box history, the ordered canonical pair, finite positive equal distances,+and a distance below all three incident extents. Failures occur before emission:++- unequal parameters: `localized-junction-parameter-mismatch`;+- zero/invalid or oversized distance;+- noncanonical/nonsharing selection;+- more than two selected edges;+- mixed finish families;+- two fillets: `localized-junction-unsupported-finish-combination:fillet-shared-patch-surface-required`.++The last is deliberate. A two-fillet corner needs an independently derived bounded blend support and+tangency proof; M3 does not guess a spherical or toroidal patch. Concave, imported/no-history, curved,+non-orthogonal, chain, loop, and three-edge cases remain outside this route.++## Fixture evidence++| Fixture | Result | STEP SHA-256 | Reimport/topology |+| --- | --- | --- | --- |+| `10 x 8 x 6`, `d=1` | Direct miter | `7B5A9289D7741F56C3EBF90056C0520463E869DF9248D01CC46847A5DF7C026F` | 11V / 17E / 8F, enclosed manifold |+| `10 x 8 x 6`, `d=2` | Direct miter | `D6D0431E95C3547B7F8E80A7F41008F6E0AC48CD2517E92CF420DA52B650A6CF` | 11V / 17E / 8F, enclosed manifold |+| `12 x 5 x 7`, `d=1` | Direct miter | `597EDDF4D44848698B57CA7714D0967A28E5867633AA699C2DA95B603B0487BB` | 11V / 17E / 8F, enclosed manifold |++The exact retained volume is `W*D*H - d^2*(W+D)/2 + d^3/3`; the final term restores the overlap of+the two independent prism removals. Tests also verify both miter endpoints lie on their intended replacement+and support planes, bounds remain unchanged, and all supports are planar.++Both artifacts were opened in CAD Assistant in this environment. CAD Assistant reported import completion+for `m3-junction.step` and `m3-junction-variation.step`; the displayed solids had a clean changed corner,+without a reader error, missing face, or visible gap. This evidence is independent of Aetheris STEP reimport.++## Preflight and legacy evidence++The production export uses `BrepExportPreflightMode.Enforce`; direct preflight, STEP export, and Aetheris+reimport all pass. The older two- and three-edge direct-BRep experiments remain negative evidence only:+they are not routed here and do not acquire this Construction AIR, combined authoritative plan, or CAD+Assistant acceptance by association.++## Future seam++The seam is reusable: individual replacements provide exact boundaries, the junction construction resolves+their shared closure, and one plan owns topology. It is suitable for a future exact fillet junction once a+bounded tangent patch primitive is proven; it can also host cove, roundover, ogee/profile-sweep, and trim+work without changing Feature AIR ownership. M4 should derive and validate the equal-radius fillet corner+surface before admitting it. General chains and valence-three corners remain deferred.