Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Emit direct cylinder-intersection fillet junctions
Yuechen Li65f783d9faa5
diff --git a/Aetheris.CLI.Tests/LocalizedTangentBlendFilletPipelineTests.cs b/Aetheris.CLI.Tests/LocalizedTangentBlendFilletPipelineTests.csindex fe1c0226..92d0d310 100644--- a/Aetheris.CLI.Tests/LocalizedTangentBlendFilletPipelineTests.cs+++ b/Aetheris.CLI.Tests/LocalizedTangentBlendFilletPipelineTests.cs@@ -77,7 +77,7 @@ public sealed class LocalizedTangentBlendFilletPipelineTests}[Fact]- public void LocalizedTangentBlend_TwoEdgeJunction_RequiresExplicitConstructionWitness()+ public void LocalizedTangentBlend_TwoEdgeJunction_ExportsDirectCylinderIntersection(){var run = Run("""Model Localized mm@@ -87,8 +87,18 @@ public sealed class LocalizedTangentBlendFilletPipelineTestsEdgeFinish Second { Face: +Y Target: SharedEdgePlusZ Kind: Fillet Distance: 1mm }}""");- Assert.Equal(1, run.Exit);- Assert.Contains("localized-fillet-junction-corner-patch-surface-required", 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("Fillet", junction.GetProperty("finishKind").GetString());+ Assert.Equal("Direct", junction.GetProperty("selectionMode").GetString());+ Assert.Equal(2, junction.GetProperty("replacementFaces").GetInt32());+ Assert.Equal(0, junction.GetProperty("junctionFaces").GetInt32());+ var closure = junction.GetProperty("closure");+ Assert.Equal("DirectIntersection", closure.GetProperty("kind").GetString());+ Assert.Equal("Ellipse", closure.GetProperty("curveKind").GetString());+ Assert.True(closure.GetProperty("exact").GetBoolean());+ Assert.Equal(1, closure.GetProperty("sharedEdges").GetInt32());}private static (int Exit, string Output) Run(string source)diff --git a/Aetheris.Kernel.Core.Tests/Air/LocalizedEdgeJunctionFilletTests.cs b/Aetheris.Kernel.Core.Tests/Air/LocalizedEdgeJunctionFilletTests.csindex f3277cff..a82eecf0 100644--- a/Aetheris.Kernel.Core.Tests/Air/LocalizedEdgeJunctionFilletTests.cs+++ b/Aetheris.Kernel.Core.Tests/Air/LocalizedEdgeJunctionFilletTests.cs@@ -1,47 +1,89 @@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;-/// <summary>Proof-carrying admission tests for AIR-FILLET-JUNCTION-M4 investigation.</summary>public sealed class LocalizedEdgeJunctionFilletTests{[Theory][InlineData(10d, 8d, 6d, 1d)][InlineData(10d, 8d, 6d, 2d)][InlineData(12d, 5d, 7d, 1d)]- public void EqualRadiusTwoEdgeCandidate_RejectsSphereBecauseItForcesTheThirdFillet(double width, double depth, double height, double radius)+ public void EqualRadiusTwoEdgeJunction_BuildsOneExactDirectEllipsePlan(double width, double depth, double height, double radius){var result = AirLocalizedEdgeJunctionFilletCompiler.Compile(Request(width, depth, height, radius, radius));- Assert.False(result.Succeeded);- Assert.Equal(FilletJunctionErrorKind.CornerPatchSurfaceRequired, result.Error?.Kind);- Assert.Equal("localized-fillet-junction-corner-patch-surface-required", result.Error?.Code);+ Assert.True(result.Succeeded, result.Error?.Code);var construction = Assert.IsType<LocalizedFilletJunctionConstruction>(result.Construction);- var candidate = construction.Candidate;- Assert.Equal(radius, candidate.Radius, 9);- Assert.Equal(width / 2d - radius, candidate.Center.X, 9);- Assert.Equal(depth / 2d - radius, candidate.Center.Y, 9);- Assert.Equal(height / 2d - radius, candidate.Center.Z, 9);- Assert.Equal(0d, candidate.CylinderTangencyDeviation, 12);- Assert.Equal(System.Math.PI * radius / 2d, candidate.ThirdBoundaryLength, 9);- Assert.Equal(0d, candidate.ThirdBoundaryTrim.Start, 12);- Assert.Equal(System.Math.PI / 2d, candidate.ThirdBoundaryTrim.End, 12);- Assert.Equal("CylindricalFillet(SharedEdge(+X,+Y))", candidate.RequiredAdjacentSurface);- Assert.Contains(result.Diagnostics, d => d == "support-plane-intersections=three tangent points, not trim curves");+ var body = Assert.IsType<BrepBody>(result.Body);+ Assert.True(result.BRepPlan!.IsAuthoritative);+ Assert.Equal(0d, construction.Closure.SurfaceADeviation, 12);+ Assert.Equal(0d, construction.Closure.SurfaceBDeviation, 12);+ Assert.Equal(radius * System.Math.Sqrt(2d), construction.Closure.SharedCurve.MajorRadius, 9);+ Assert.Equal(radius, construction.Closure.SharedCurve.MinorRadius, 9);+ Assert.Equal(11, body.Topology.Vertices.Count());+ Assert.Equal(17, body.Topology.Edges.Count());+ Assert.Equal(8, body.Topology.Faces.Count());+ Assert.Equal(2, body.Geometry.Surfaces.Count(x => x.Value.Kind == SurfaceGeometryKind.Cylinder));+ Assert.Equal(1, body.Geometry.Curves.Count(x => x.Value.Kind == CurveGeometryKind.Ellipse3));+ Assert.True(BrepExportPreflight.Validate(body).IsValid);++ foreach (var edgeBinding in body.Bindings.EdgeBindings)+ {+ var edge = body.Topology.GetEdge(edgeBinding.EdgeId);+ var curve = body.Geometry.GetCurve(edgeBinding.CurveGeometryId);+ var start = curve.Kind switch+ {+ CurveGeometryKind.Line3 => curve.Line3!.Value.Evaluate(edgeBinding.TrimInterval!.Value.Start),+ CurveGeometryKind.Circle3 => curve.Circle3!.Value.Evaluate(edgeBinding.TrimInterval!.Value.Start),+ CurveGeometryKind.Ellipse3 => curve.Ellipse3!.Value.Evaluate(edgeBinding.TrimInterval!.Value.Start),+ _ => throw new InvalidOperationException(),+ };+ Assert.True(body.TryGetVertexPoint(edge.StartVertexId, out var expectedStart));+ Assert.InRange((start - expectedStart).Length, 0d, 1e-9);+ }++ var step = Step242Exporter.ExportBody(body, new Step242ExportOptions { BrepExportPreflightMode = BrepExportPreflightMode.Enforce });+ Assert.True(step.IsSuccess, string.Join(Environment.NewLine, step.Diagnostics.Select(x => x.Message)));+ Assert.Contains("ELLIPSE", step.Value!, StringComparison.Ordinal);+ var imported = Step242Importer.ImportBody(step.Value!);+ Assert.True(imported.IsSuccess, string.Join(Environment.NewLine, imported.Diagnostics.Select(x => x.Message)));+ Assert.Equal(2, imported.Value!.Geometry.Surfaces.Count(x => x.Value.Kind == SurfaceGeometryKind.Cylinder));+ Assert.Equal(1, imported.Value.Geometry.Curves.Count(x => x.Value.Kind == CurveGeometryKind.Ellipse3));}[Theory][InlineData(1d, 2d, "localized-fillet-junction-radius-mismatch")][InlineData(0d, 0d, "localized-fillet-junction-radius-must-be-positive")][InlineData(6d, 6d, "localized-fillet-junction-radius-too-large")]- public void JunctionAdmission_RejectsInvalidParametersBeforeAnyConstruction(double first, double second, string code)+ public void JunctionAdmission_RejectsInvalidParametersBeforeEmission(double first, double second, string code){var result = AirLocalizedEdgeJunctionFilletCompiler.Compile(Request(10, 8, 6, first, second));Assert.False(result.Succeeded);- Assert.Null(result.Construction);+ Assert.Null(result.Body);Assert.Equal(code, result.Error?.Code);}+ [Fact]+ public void DirectIntersectionOverlapVolume_AgreesWithIndependentNumericalIntegration()+ {+ const double r = 1d;+ var exactOverlap = r * r * r * (5d / 3d - System.Math.PI / 2d);+ const int intervals = 100_000;+ var step = r / intervals;+ var numerical = 0d;+ for (var i = 0; i <= intervals; i++)+ {+ var z = i * step;+ var area = System.Math.Pow(r - System.Math.Sqrt(r * r - z * z), 2d);+ numerical += area * (i is 0 or intervals ? .5d : 1d);+ }+ numerical *= step;+ Assert.InRange(numerical, exactOverlap - 3e-8, exactOverlap + 3e-8);+ }+private static AirLocalizedEdgeJunctionFilletCompileRequest 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"));diff --git a/Aetheris.Kernel.Core.Tests/Brep/BrepExportPreflightTests.cs b/Aetheris.Kernel.Core.Tests/Brep/BrepExportPreflightTests.csindex 48eff50f..761bc4ba 100644--- a/Aetheris.Kernel.Core.Tests/Brep/BrepExportPreflightTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/BrepExportPreflightTests.cs@@ -53,6 +53,23 @@ public sealed class BrepExportPreflightTestsAssert.Contains(export.Diagnostics, diagnostic => diagnostic.Message.Contains("brep-preflight-trim-off-surface", StringComparison.Ordinal));}+ [Fact]+ public void CurveTrimEndpointsThatDisagreeWithTopologyVertices_AreRejected()+ {+ var circle = new Circle3Curve(Point3D.Origin, Z, 2, X);+ var body = ClosedCircleBody(+ SurfaceGeometry.FromCylinder(new CylinderSurface(Point3D.Origin, Z, 2, X)),+ circle,+ new Point3D(0, 2, 0));++ var report = BrepExportPreflight.Validate(body);++ Assert.False(report.IsValid);+ Assert.Contains(report.Diagnostics, diagnostic =>+ diagnostic.Code == "brep-preflight-edge-curve-endpoint-mismatch" &&+ diagnostic.Classification == BrepExportPreflightFindingClassification.InvalidTopology);+ }+[Fact]public void DisconnectedLoop_IsClassifiedAsInvalidTopology(){@@ -63,7 +80,7 @@ public sealed class BrepExportPreflightTestsdiagnostic.Classification == BrepExportPreflightFindingClassification.InvalidTopology);}- private static BrepBody ClosedCircleBody(SurfaceGeometry surface, Circle3Curve circle)+ private static BrepBody ClosedCircleBody(SurfaceGeometry surface, Circle3Curve circle, Point3D? topologyVertexPoint = null){var topology = new TopologyModel();var vertex = new VertexId(1); var edge = new EdgeId(1); var coedge = new CoedgeId(1); var loop = new LoopId(1); var face = new FaceId(1); var shell = new ShellId(1);@@ -72,7 +89,7 @@ public sealed class BrepExportPreflightTeststopology.AddFace(new Face(face, [loop])); topology.AddShell(new Shell(shell, [face])); topology.AddBody(new Body(new BodyId(1), [shell]));var geometry = new BrepGeometryStore(); geometry.AddCurve(new CurveGeometryId(1), CurveGeometry.FromCircle(circle)); geometry.AddSurface(new SurfaceGeometryId(1), surface);var bindings = new BrepBindingModel(); bindings.AddEdgeBinding(new EdgeGeometryBinding(edge, new CurveGeometryId(1), new ParameterInterval(0, 2 * double.Pi))); bindings.AddFaceBinding(new FaceGeometryBinding(face, new SurfaceGeometryId(1)));- return new BrepBody(topology, geometry, bindings, new Dictionary<VertexId, Point3D> { [vertex] = circle.Evaluate(0) });+ return new BrepBody(topology, geometry, bindings, new Dictionary<VertexId, Point3D> { [vertex] = topologyVertexPoint ?? circle.Evaluate(0) });}private static BrepBody DisconnectedLoopBody()diff --git a/Aetheris.Kernel.Core/Air/AirBRepPlan.cs b/Aetheris.Kernel.Core/Air/AirBRepPlan.csindex d678e76d..e720418c 100644--- a/Aetheris.Kernel.Core/Air/AirBRepPlan.cs+++ b/Aetheris.Kernel.Core/Air/AirBRepPlan.cs@@ -5,7 +5,7 @@ namespace Aetheris.Kernel.Core.Air.BRepPlan;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, ReplacementFaceA, ReplacementFaceB, ReplacementBoundaryA, ReplacementBoundaryB, SharedJunction, CornerPatch, RetainedSupportFaceA, RetainedSupportFaceB, EndpointTransitionStart, EndpointTransitionEnd, RemoteEndpointA, RemoteEndpointB, 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, DirectJunctionBoundary, CornerPatch, RetainedSupportFaceA, RetainedSupportFaceB, EndpointTransitionStart, EndpointTransitionEnd, RemoteEndpointA, RemoteEndpointB, UnaffectedFace, BodyShell, Body }internal readonly record struct AirBRepPlanId(string Value){diff --git a/Aetheris.Kernel.Core/Air/AirLocalizedEdgeJunctionFilletCompiler.cs b/Aetheris.Kernel.Core/Air/AirLocalizedEdgeJunctionFilletCompiler.csindex c98ca0b3..2fcbf700 100644--- a/Aetheris.Kernel.Core/Air/AirLocalizedEdgeJunctionFilletCompiler.cs+++ b/Aetheris.Kernel.Core/Air/AirLocalizedEdgeJunctionFilletCompiler.cs@@ -1,15 +1,16 @@+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.Geometry.Curves;using Aetheris.Kernel.Core.Geometry.Surfaces;using Aetheris.Kernel.Core.Math;+using Aetheris.Kernel.Core.Topology;namespace Aetheris.Kernel.Core.Air;-/// <summary>-/// Bounded geometric investigation for two adjacent constant-radius fillet intents.-/// This is deliberately a Construction-AIR admission stage: it never emits topology-/// unless a patch closes against the selected replacements and retained supports.-/// </summary>+/// <summary>Bounded M4A request: two equal-radius convex box-edge fillets only.</summary>internal sealed record AirLocalizedEdgeJunctionFilletCompileRequest(string BodyId, string FeatureId, string FeatureName, double Width, double Depth, double Height,string FaceA, string TargetA, string FaceB, string TargetB, double RadiusA, double RadiusB,@@ -17,127 +18,184 @@ internal sealed record AirLocalizedEdgeJunctionFilletCompileRequest(internal enum FilletJunctionErrorKind{- EdgesDoNotShareEndpoint,- UnsupportedJunctionValence,- RadiusMismatch,- RadiusTooLarge,- UnsupportedSurfaceCombination,- CornerPatchSurfaceRequired,- CornerPatchConstructionFailed,- ConstructionWitnessRequired,+ EdgesDoNotShareEndpoint, RadiusMismatch, RadiusTooLarge, UnsupportedSurfaceCombination,+ DirectIntersectionMissing, DirectIntersectionAmbiguous, IntersectionBranchSelectionFailed,+ IntersectionCurveUnsupported, BoundaryOwnershipConflict, PatchRequired, VerificationFailure,}-internal sealed record FilletJunctionError(- FilletJunctionErrorKind Kind, string Code, string Message, string Stage,- IReadOnlyList<string> Evidence);+internal sealed record FilletJunctionError(FilletJunctionErrorKind Kind, string Code, string Message, string Stage, IReadOnlyList<string> Evidence);/// <summary>-/// Exact witness for the only simple analytic candidate. The third boundary is-/// retained as evidence because it proves why this candidate cannot be emitted as-/// a two-edge junction.+/// The exact selected branch of the two cylinder intersection. In local coordinates+/// u=x-cx=y-cy and w=z-cz, u²+w²=R². Embedded in 3-D that is a planar ellipse,+/// not a spherical patch and not an approximation./// </summary>-internal sealed record SphericalFilletCornerCandidateWitness(- Point3D Center,- double Radius,- SphereSurface Surface,- CylinderSurface ReplacementACylinder,- CylinderSurface ReplacementBCylinder,- Circle3Curve ThirdBoundary,- ParameterInterval ThirdBoundaryTrim,- Point3D SupportTangentOnPlusX,- Point3D SupportTangentOnPlusY,- Point3D SupportTangentOnPlusZ,- string RequiredAdjacentSurface,- double CylinderTangencyDeviation,- double ThirdBoundaryLength);+internal sealed record LocalizedEdgeJunctionDirectIntersectionClosure(+ CylinderSurface SurfaceA, CylinderSurface SurfaceB, Ellipse3Curve SharedCurve,+ ParameterInterval Trim, Point3D Start, Point3D End, string Branch, string MaterialSide,+ double SurfaceADeviation, double SurfaceBDeviation, string Provenance);internal sealed record LocalizedFilletJunctionConstruction(- string ConstructionId,- AirEdgeFinishFeature ReplacementA,- AirEdgeFinishFeature ReplacementB,- Point3D SharedEndpoint,- SphericalFilletCornerCandidateWitness Candidate,- string MaterialSide,- string Provenance);+ string ConstructionId, LocalizedEdgeJunctionReplacement ReplacementA,+ LocalizedEdgeJunctionReplacement ReplacementB, Point3D SharedEndpoint,+ Point3D RemoteEndpointA, Point3D RemoteEndpointB,+ LocalizedEdgeJunctionDirectIntersectionClosure Closure,+ IReadOnlyList<IReadOnlyList<Point3D>> RetainedRegions, string MaterialSide,+ string BoundaryOwnership, LocalizedEdgeJunctionTopologyPlan TopologyPlan, string Provenance);internal sealed record AirLocalizedEdgeJunctionFilletCompileResult(- bool Succeeded,- LocalizedFilletJunctionConstruction? Construction,- FilletJunctionError? Error,- IReadOnlyList<string> Diagnostics);+ bool Succeeded, LocalizedFilletJunctionConstruction? Construction, AirBRepPlan? BRepPlan,+ BrepBody? Body, FilletJunctionError? Error, IReadOnlyList<string> Diagnostics)+{+ public const string ProductionRoute = "AirLocalizedEdgeJunctionFilletM4A";+}+/// <summary>+/// Exact direct-intersection realization. It is intentionally not a rolling-ball+/// framework: only the positive orthogonal box corner and the positive branch are+/// admitted. The spherical construction is reserved for the separate three-edge case.+/// </summary>internal static class AirLocalizedEdgeJunctionFilletCompiler{private const double Tol = 1e-9;public static AirLocalizedEdgeJunctionFilletCompileResult Compile(AirLocalizedEdgeJunctionFilletCompileRequest input){- FilletJunctionError Fail(FilletJunctionErrorKind kind, string code, string message, params string[] evidence) =>- new(kind, code, message, "FeatureAIR->ConstructionAIR", evidence);-- if (!input.HistoryKnown)- return Rejected(Fail(FilletJunctionErrorKind.UnsupportedSurfaceCombination, "localized-fillet-junction-unsupported-history", "Localized fillet junctions require history-known axis-aligned box support planes.", "construction-history=imported/no-history"));- if (!FinitePositive(input.Width) || !FinitePositive(input.Depth) || !FinitePositive(input.Height))- return Rejected(Fail(FilletJunctionErrorKind.UnsupportedSurfaceCombination, "localized-fillet-junction-invalid-box-dimensions", "Box dimensions must be finite and positive."));- if (!Matches(input.FaceA, input.TargetA, "+X") || !Matches(input.FaceB, input.TargetB, "+Y"))- return Rejected(Fail(FilletJunctionErrorKind.EdgesDoNotShareEndpoint, "localized-fillet-junction-edges-do-not-share-canonical-endpoint", "M4 investigates SharedEdge(+X,+Z) and SharedEdge(+Y,+Z) only."));- if (!FinitePositive(input.RadiusA) || !FinitePositive(input.RadiusB))- return Rejected(Fail(FilletJunctionErrorKind.RadiusTooLarge, "localized-fillet-junction-radius-must-be-positive", "Both fillet radii must be finite and positive."));- if (double.Abs(input.RadiusA - input.RadiusB) > Tol)- return Rejected(Fail(FilletJunctionErrorKind.RadiusMismatch, "localized-fillet-junction-radius-mismatch", "The canonical candidate requires equal radii."));- if (input.RadiusA >= input.Width - Tol || input.RadiusA >= input.Depth - Tol || input.RadiusA >= input.Height - Tol)- return Rejected(Fail(FilletJunctionErrorKind.RadiusTooLarge, "localized-fillet-junction-radius-too-large", "The radius must remain within all three incident support extents."));-- var r = input.RadiusA;- var hx = input.Width / 2d;- var hy = input.Depth / 2d;- var hz = input.Height / 2d;- var center = new Point3D(hx - r, hy - r, hz - r);- var x = Direction3D.Create(new Vector3D(1, 0, 0));- var y = Direction3D.Create(new Vector3D(0, 1, 0));- var z = Direction3D.Create(new Vector3D(0, 0, 1));- var replacementA = new CylinderSurface(center, y, r, x);- var replacementB = new CylinderSurface(center, x, r, y);- var sphere = new SphereSurface(center, z, r, x);- // This circle is the forced third spherical boundary. It is exactly the- // radius-R cylinder about the +Z axis, i.e. a fillet of SharedEdge(+X,+Y).- var thirdBoundary = new Circle3Curve(center, z, r, x);- var tangentX = new Point3D(hx, hy - r, hz - r);- var tangentY = new Point3D(hx - r, hy, hz - r);- var tangentZ = new Point3D(hx - r, hy - r, hz);- var candidate = new SphericalFilletCornerCandidateWitness(- center, r, sphere, replacementA, replacementB, thirdBoundary, new ParameterInterval(0d, double.Pi / 2d), tangentX, tangentY, tangentZ,- "CylindricalFillet(SharedEdge(+X,+Y))", 0d, (double.Pi * r) / 2d);- var construction = new LocalizedFilletJunctionConstruction(- $"construction:{input.FeatureId}:fillet-junction",- Feature(input, "A", "+X", "SharedEdge(+X,+Z)"),- Feature(input, "B", "+Y", "SharedEdge(+Y,+Z)"),- new Point3D(hx, hy, hz), candidate,- "inside:x<=max,y<=max,z<=max; convex exterior removal",- "history-known-axis-aligned-rectangular-box; exact-spherical-candidate-derived");-- return Rejected(Fail(- FilletJunctionErrorKind.CornerPatchSurfaceRequired,- "localized-fillet-junction-corner-patch-surface-required",- "The exact spherical candidate is tangent to the two selected cylinders, but its remaining boundary requires the unselected +X/+Y cylindrical fillet; it cannot close against retained +X, +Y, or +Z support regions.",- $"sphere-center=({center.X:R},{center.Y:R},{center.Z:R});radius={r:R}",- "candidate-cylinder-tangency-deviation=0",- $"unowned-third-boundary-length={(double.Pi * r / 2d):R}",- "required-adjacent-surface=CylindricalFillet(SharedEdge(+X,+Y))",- "support-plane-intersections=three tangent points, not trim curves"), construction);+ var lowered = Lower(input);+ if (lowered.Error is not null) return new(false, null, null, null, lowered.Error, [lowered.Error.Code, .. lowered.Error.Evidence]);+ var construction = lowered.Construction!;+ var plan = BuildPlan(input, construction);+ var emitted = Emit(construction);+ if (!emitted.Succeeded || emitted.Body is null)+ return Failure(construction, plan, new(FilletJunctionErrorKind.VerificationFailure, "localized-fillet-junction-materialization-failed", "The authoritative direct-intersection plan did not materialize.", "BRep", emitted.Diagnostics));++ var body = emitted.Body;+ var cylinderCount = body.Geometry.Surfaces.Count(s => s.Value.Kind == SurfaceGeometryKind.Cylinder);+ var ellipseCount = body.Geometry.Curves.Count(c => c.Value.Kind == CurveGeometryKind.Ellipse3);+ var preflight = BrepExportPreflight.Validate(body);+ if (cylinderCount != 2 || ellipseCount != 1 || body.Topology.Faces.Count() != 8 || !preflight.IsValid)+ return Failure(construction, plan, new(FilletJunctionErrorKind.VerificationFailure, "localized-fillet-junction-analytic-verification-failed", "The direct junction requires two cylinders, one shared ellipse, eight faces, and valid analytic preflight.", "Verification", preflight.Diagnostics.Select(d => d.Code).ToArray()));++ return new(true, construction, plan, body, null,+ ["localized-fillet-junction-feature-admitted", "localized-fillet-junction-direct-intersection", "localized-fillet-junction-candidate-plans=1", "localized-fillet-junction-hard-valid-plans=1", "localized-fillet-junction-authoritative-brep-plan-consumed", "localized-fillet-junction-no-corner-patch", "localized-fillet-junction-no-legacy-fallback"]);}- private static AirLocalizedEdgeJunctionFilletCompileResult Rejected(FilletJunctionError error, LocalizedFilletJunctionConstruction? construction = null) =>- new(false, construction, error, [error.Code, .. error.Evidence]);+ private static (LocalizedFilletJunctionConstruction? Construction, FilletJunctionError? Error) Lower(AirLocalizedEdgeJunctionFilletCompileRequest input)+ {+ FilletJunctionError Fail(FilletJunctionErrorKind kind, string code, string message, params string[] evidence) => new(kind, code, message, "FeatureAIR->ConstructionAIR", evidence);+ if (!input.HistoryKnown) return (null, Fail(FilletJunctionErrorKind.UnsupportedSurfaceCombination, "localized-fillet-junction-unsupported-history", "Direct fillet junctions require history-known axis-aligned box support planes."));+ if (!FinitePositive(input.Width) || !FinitePositive(input.Depth) || !FinitePositive(input.Height)) return (null, Fail(FilletJunctionErrorKind.UnsupportedSurfaceCombination, "localized-fillet-junction-invalid-box-dimensions", "Box dimensions must be finite and positive."));+ if (!Matches(input.FaceA, input.TargetA, "+X") || !Matches(input.FaceB, input.TargetB, "+Y")) return (null, Fail(FilletJunctionErrorKind.EdgesDoNotShareEndpoint, "localized-fillet-junction-edges-do-not-share-canonical-endpoint", "M4A admits SharedEdge(+X,+Z) and SharedEdge(+Y,+Z) only."));+ if (!FinitePositive(input.RadiusA) || !FinitePositive(input.RadiusB)) return (null, Fail(FilletJunctionErrorKind.RadiusTooLarge, "localized-fillet-junction-radius-must-be-positive", "Both radii must be finite and positive."));+ if (double.Abs(input.RadiusA - input.RadiusB) > Tol) return (null, Fail(FilletJunctionErrorKind.RadiusMismatch, "localized-fillet-junction-radius-mismatch", "M4A requires equal radii."));+ if (input.RadiusA >= input.Width - Tol || input.RadiusA >= input.Depth - Tol || input.RadiusA >= input.Height - Tol) return (null, Fail(FilletJunctionErrorKind.RadiusTooLarge, "localized-fillet-junction-radius-too-large", "The radius must remain within every incident support extent."));++ var r = input.RadiusA; var hx = input.Width / 2d; var hy = input.Depth / 2d; var hz = input.Height / 2d;+ var cx = hx - r; var cy = hy - r; var cz = hz - r;+ var center = new Point3D(cx, cy, cz);+ var x = Direction3D.Create(new Vector3D(1, 0, 0)); var y = Direction3D.Create(new Vector3D(0, 1, 0)); var z = Direction3D.Create(new Vector3D(0, 0, 1));+ var cylinderA = new CylinderSurface(center, y, r, x);+ var cylinderB = new CylinderSurface(center, x, r, y);+ var diagonal = Direction3D.Create(new Vector3D(1, 1, 0));+ var planeNormal = Direction3D.Create(new Vector3D(1, -1, 0));+ var seam = new Ellipse3Curve(center, planeNormal, r * double.Sqrt(2d), r, diagonal);+ var p = new Point3D(hx, hy, cz); var q = new Point3D(cx, cy, hz);+ var trim = new ParameterInterval(0d, double.Pi / 2d);+ var closure = new LocalizedEdgeJunctionDirectIntersectionClosure(cylinderA, cylinderB, seam, trim, p, q, "positive: x-cx=y-cy>=0; z-cz>=0", "convex exterior removal", 0d, 0d, "exact ellipse: (x-cx)^2+(z-cz)^2=R^2=(y-cy)^2+(z-cz)^2");- private static AirEdgeFinishFeature Feature(AirLocalizedEdgeJunctionFilletCompileRequest input, string suffix, string face, string edge) => new(- $"{input.FeatureId}.{suffix}", $"{input.FeatureName}.{suffix}", input.BodyId,- new AirFaceBoundarySelection(face, edge, false), AirLocalizedEdgeFinishKind.Fillet,- new AirConstantRadiusEdgeFinishRule(input.RadiusA), input.SourceSpan,- "generated/history-known-axis-aligned-rectangular-prism", AirFeatureAdmissionStatus.Deferred,- "localized-fillet-junction-corner-patch-surface-required");+ 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, cz), new Point3D(cx, -hy, hz),+ new Point3D(-hx, hy, cz), new Point3D(-hx, cy, hz), p, q,+ };+ IReadOnlyList<int>[] loops =+ [+ [0, 3, 2, 1], [0, 4, 8, 7, 3], [0, 1, 5, 6, 4], [1, 2, 9, 5],+ [3, 7, 9, 2], [4, 6, 10, 8], [5, 9, 10, 6], [7, 8, 10, 9],+ ];+ var signature = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(FormattableString.Invariant($"localized-edge-junction:Fillet:+X,+Z:+Y,+Z:{input.Width:R}:{input.Depth:R}:{input.Height:R}:{r:R}:direct-ellipse"))));+ var topology = new LocalizedEdgeJunctionTopologyPlan(vertices, loops,+ ["UnaffectedFace(-Z)", "RemoteEndpointB(-X)", "RemoteEndpointA(-Y)", "RetainedSupportFace(+X)", "RetainedSupportFace(+Y)", "RetainedSupportFace(+Z)", "FilletReplacementA(Cylinder)", "FilletReplacementB(Cylinder)"], signature);+ var featureA = Feature(input, "A", "+X", "SharedEdge(+X,+Z)"); var featureB = Feature(input, "B", "+Y", "SharedEdge(+Y,+Z)");+ var replacementA = new LocalizedEdgeJunctionReplacement("SharedEdge(+X,+Z)", featureA, [vertices[5], vertices[9], vertices[10], vertices[6]], [vertices[5], vertices[6]], "CylindricalFillet");+ var replacementB = new LocalizedEdgeJunctionReplacement("SharedEdge(+Y,+Z)", featureB, [vertices[7], vertices[8], vertices[10], vertices[9]], [vertices[7], vertices[8]], "CylindricalFillet");+ return (new($"construction:{input.FeatureId}:fillet-junction", replacementA, replacementB, new Point3D(hx, hy, hz), new Point3D(hx, -hy, hz), new Point3D(-hx, hy, hz), closure,+ [[vertices[1], vertices[2], vertices[9], vertices[5]], [vertices[3], vertices[7], vertices[9], vertices[2]], [vertices[4], vertices[6], vertices[10], vertices[8]]],+ "inside:x<=max,y<=max,z<=max; convex exterior removal", "DirectIntersectionEllipse(opposite coedges); RemoteEndpointA(-Y); RemoteEndpointB(-X)", topology,+ "history-known-axis-aligned-rectangular-box; equal-radius-direct-cylinder-cylinder-intersection"), null);+ }++ private static AirLocalizedEdgeJunctionFilletCompileResult Failure(LocalizedFilletJunctionConstruction construction, AirBRepPlan plan, FilletJunctionError error) => new(false, construction, plan, null, error, [error.Code, .. error.Evidence]);++ private static AirEdgeFinishFeature Feature(AirLocalizedEdgeJunctionFilletCompileRequest input, string suffix, string face, string edge) => new($"{input.FeatureId}.{suffix}", $"{input.FeatureName}.{suffix}", input.BodyId, new AirFaceBoundarySelection(face, edge, false), AirLocalizedEdgeFinishKind.Fillet, new AirConstantRadiusEdgeFinishRule(input.RadiusA), input.SourceSpan, "generated/history-known-axis-aligned-rectangular-prism", AirFeatureAdmissionStatus.Admitted, "localized-fillet-junction-direct-intersection-candidate");++ private static AirBRepPlan BuildPlan(AirLocalizedEdgeJunctionFilletCompileRequest input, LocalizedFilletJunctionConstruction construction)+ {+ var provenance = new AirProvenance("AIR-FILLET-JUNCTION-M4A", "Localized two-edge direct cylinder intersection", "shared-edge(+X,+Z)/shared-edge(+Y,+Z)", input.FeatureId, nameof(AirLocalizedEdgeJunctionFilletCompiler), AirSelectionClass.None, AirRuleKind.ConstantRadiusFillet, construction.Provenance, true, ["One hard-valid direct-intersection construction.", "Shared ellipse is owned by opposite replacement coedges.", "No corner patch and no legacy surgery."]);+ var p = construction.TopologyPlan; var elements = new List<AirBRepPlanElement>();+ for (var i = 0; i < p.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 < p.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 < p.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: p.FaceRoles[i], SemanticRoles: i is 6 or 7 ? [role, AirBRepPlanRole.ReplacementFace, AirBRepPlanRole.FilletFace] : [role]));+ }+ for (var i = 0; i < p.ExpectedEdgeCount; i++) elements.Add(new(new($"edge:{i}"), AirBRepPlanElementKind.Edge, i == p.ExpectedEdgeCount - 1 ? AirBRepPlanRole.DirectJunctionBoundary : AirBRepPlanRole.SectionEdge, input.FeatureId, provenance));+ elements.Add(new(new("curve:direct-intersection:0"), AirBRepPlanElementKind.Curve, AirBRepPlanRole.DirectJunctionBoundary, input.FeatureId, provenance, SemanticRoles: [AirBRepPlanRole.DirectJunctionBoundary, 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 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, 0, $"localized-edge-junction=Fillet;closure=DirectIntersection;signature={p.DeterministicSignature}", construction.BoundaryOwnership, [], ["authoritative combined direct-intersection topology", "one hard-valid plan", "no corner patch", "no legacy fallback"], new(AirNodeKind.Unsupported, AirRouteKind.Unsupported, AirSelectionClass.None, AirRuleKind.ConstantRadiusFillet, 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 AirLocalizedEdgeReplacementEmissionResult Emit(LocalizedFilletJunctionConstruction construction)+ {+ var points = construction.TopologyPlan.Vertices; var loops = construction.TopologyPlan.FaceLoops;+ var builder = new TopologyBuilder(); var vertices = points.Select(_ => builder.AddVertex()).ToArray(); var edges = new Dictionary<(int, int), EdgeId>(); var directions = new Dictionary<(int, int), (int Start, int End)>(); var faces = new List<FaceId>();+ foreach (var loop in loops)+ {+ var uses = new Use[loop.Count];+ for (var i = 0; i < loop.Count; i++) { var a = loop[i]; var b = loop[(i + 1) % loop.Count]; var key = a < b ? (a, b) : (b, a); if (!edges.TryGetValue(key, out var edge)) { edge = builder.AddEdge(vertices[a], vertices[b]); edges[key] = edge; directions[key] = (a, b); } var d = directions[key]; uses[i] = d.Start == a && d.End == b ? 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(p => p.Value.Value))+ {+ var (a, b) = directions[pair.Key]; var cid = new CurveGeometryId(curveNumber++);+ if (pair.Key == (5, 6)) geometry.AddCurve(cid, CurveGeometry.FromCircle(new Circle3Curve(new Point3D(points[6].X, points[5].Y, points[5].Z), Direction3D.Create(new Vector3D(0, -1, 0)), construction.Closure.SurfaceA.Radius, Direction3D.Create(new Vector3D(1, 0, 0)))));+ else if (pair.Key == (7, 8))+ {+ // The -X retained face encounters this shared remote edge as 8→7.+ // Bind its circle in that same edge direction; otherwise the curve+ // endpoints disagree with topology and CAD consumers may fold the cap.+ var center = new Point3D(points[7].X, points[8].Y, points[7].Z);+ var arc = a == 8 && b == 7+ ? new Circle3Curve(center, Direction3D.Create(new Vector3D(-1, 0, 0)), construction.Closure.SurfaceB.Radius, Direction3D.Create(new Vector3D(0, 0, 1)))+ : new Circle3Curve(center, Direction3D.Create(new Vector3D(1, 0, 0)), construction.Closure.SurfaceB.Radius, Direction3D.Create(new Vector3D(0, 1, 0)));+ geometry.AddCurve(cid, CurveGeometry.FromCircle(arc));+ }+ else if (pair.Key == (9, 10)) geometry.AddCurve(cid, CurveGeometry.FromEllipse(construction.Closure.SharedCurve));+ else geometry.AddCurve(cid, CurveGeometry.FromLine(new Line3Curve(points[a], Direction3D.Create(points[b] - points[a]))));+ var trim = pair.Key is (5, 6) or (7, 8) or (9, 10) ? new ParameterInterval(0d, double.Pi / 2d) : new ParameterInterval(0d, (points[b] - points[a]).Length);+ bindings.AddEdgeBinding(new EdgeGeometryBinding(pair.Value, cid, trim));+ }+ var surfaceNumber = 1;+ for (var i = 0; i < faces.Count; i++)+ {+ var sid = new SurfaceGeometryId(surfaceNumber++);+ if (i == 6) geometry.AddSurface(sid, SurfaceGeometry.FromCylinder(construction.Closure.SurfaceA));+ else if (i == 7) geometry.AddSurface(sid, SurfaceGeometry.FromCylinder(construction.Closure.SurfaceB));+ else { var loop = loops[i]; var a = points[loop[0]]; var u = points[loop[1]] - a; Vector3D normal = default; for (var j = 2; j < loop.Count; j++) { normal = u.Cross(points[loop[j]] - a); if (normal.Length > Tol) break; } geometry.AddSurface(sid, SurfaceGeometry.FromPlane(new PlaneSurface(a, Direction3D.Create(normal), Direction3D.Create(u)))); }+ bindings.AddFaceBinding(new FaceGeometryBinding(faces[i], sid));+ }+ var vertexPoints = vertices.Select((v, i) => new KeyValuePair<VertexId, Point3D>(v, points[i])).ToDictionary(); var body = new BrepBody(builder.Model, geometry, bindings, vertexPoints); var check = BrepBindingValidator.Validate(body, true);+ return check.IsSuccess ? new(true, body, ["localized-fillet-junction-plan-emitted"]) : new(false, null, check.Diagnostics.Select(d => d.Message).ToArray());+ }+ private static FaceId AddFace(TopologyBuilder b, IReadOnlyList<Use> uses) { var loop = b.AllocateLoopId(); var ids = new CoedgeId[uses.Count]; for (var i = 0; i < ids.Length; i++) ids[i] = b.AllocateCoedgeId(); for (var i = 0; i < ids.Length; i++) b.AddCoedge(new Coedge(ids[i], uses[i].Id, loop, ids[(i + 1) % ids.Length], ids[(i + ids.Length - 1) % ids.Length], uses[i].Reverse)); b.AddLoop(new Loop(loop, ids)); return b.AddFace([loop]); }+ private readonly record struct Use(EdgeId Id, bool Reverse) { public static Use F(EdgeId id) => new(id, false); public static Use R(EdgeId id) => new(id, true); }private static bool FinitePositive(double value) => double.IsFinite(value) && value > Tol;- private static bool Matches(string face, string target, string expectedFace) =>- string.Equals(face, expectedFace, StringComparison.Ordinal) && string.Equals(target, "SharedEdgePlusZ", StringComparison.Ordinal);+ private static bool Matches(string face, string target, string expectedFace) => string.Equals(face, expectedFace, StringComparison.Ordinal) && string.Equals(target, "SharedEdgePlusZ", StringComparison.Ordinal);}diff --git a/Aetheris.Kernel.Core/Brep/BrepExportPreflight.cs b/Aetheris.Kernel.Core/Brep/BrepExportPreflight.csindex 9944d0fc..770bb061 100644--- a/Aetheris.Kernel.Core/Brep/BrepExportPreflight.cs+++ b/Aetheris.Kernel.Core/Brep/BrepExportPreflight.cs@@ -173,6 +173,17 @@ public static class BrepExportPreflightvar b = Evaluate(curve, binding.TrimInterval.Value.End);if (a is null || b is null || !Finite(a.Value) || !Finite(b.Value))AddError("brep-preflight-edge-degenerate", "edge", "Edge curve endpoint is non-finite or unsupported.", edgeId: edge.Id.Value);+ if (a is not null && b is not null+ && body.TryGetVertexPoint(edge.StartVertexId, out var startPoint)+ && body.TryGetVertexPoint(edge.EndVertexId, out var endPoint))+ {+ var expectedStart = binding.OrientedEdgeSense ? startPoint : endPoint;+ var expectedEnd = binding.OrientedEdgeSense ? endPoint : startPoint;+ var startDeviation = Distance(a.Value, expectedStart);+ var endDeviation = Distance(b.Value, expectedEnd);+ if (startDeviation > Tolerances.Linear || endDeviation > Tolerances.Linear)+ AddError("brep-preflight-edge-curve-endpoint-mismatch", "edge", "Edge curve trim endpoints do not match the topology edge endpoints.", edgeId: edge.Id.Value, deviation: double.Max(startDeviation, endDeviation));+ }if (a is not null && b is not null && curve.Kind is CurveGeometryKind.Line3 && Distance(a.Value, b.Value) <= Tolerances.Linear)AddError("brep-preflight-edge-degenerate", "edge", "Line edge has zero geometric length.", edgeId: edge.Id.Value, deviation: Distance(a.Value, b.Value));}diff --git a/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs b/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.csindex ba53c634..5deb11f8 100644--- a/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs+++ b/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs@@ -174,13 +174,7 @@ public static class FirmamentBuildAndExportvar 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-fillet-junction-unsupported-history:expected-history-known-box");- var filletInvestigation = AirLocalizedEdgeJunctionFilletCompiler.Compile(new(- junctionSolid.Name, $"{junctionSolid.Name}.{finishes[0].Finish.Name}.{finishes[1].Finish.Name}", $"{finishes[0].Finish.Name}+{finishes[1].Finish.Name}",- junctionBox.Size[0], junctionBox.Size[1], junctionBox.Size[2],- finishes[0].Finish.FaceAxis, finishes[0].Finish.Target, finishes[1].Finish.FaceAxis, finishes[1].Finish.Target,- finishes[0].Finish.Distance, finishes[1].Finish.Distance,- new AirSourceSpan(finishes[0].Finish.SourceSpan.Start, finishes[0].Finish.SourceSpan.Length + finishes[1].Finish.SourceSpan.Length, document.ModelName)));- return AirChamferFailure(filletInvestigation.Error?.Code ?? "localized-fillet-junction-construction-witness-required", filletInvestigation.Diagnostics);+ return ExportV2LocalizedEdgeJunctionFillet(document, junctionSolid, finishes[0].Finish, finishes[1].Finish, junctionBox);}if (finishes.Length == 2)return AirChamferFailure("localized-junction-unsupported-finish-combination:mixed-families");@@ -349,6 +343,55 @@ public static class FirmamentBuildAndExportreturn 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> ExportV2LocalizedEdgeJunctionFillet(+ FirmamentV2Document document,+ FirmamentV2SolidBinding solid,+ FirmamentV2EdgeFinishDecl first,+ FirmamentV2EdgeFinishDecl second,+ FirmamentV2BoxRecord box)+ {+ var compiled = AirLocalizedEdgeJunctionFilletCompiler.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-fillet-junction-direct-intersection-required", compiled.Diagnostics);++ var body = compiled.Body;+ var preflight = BrepExportPreflight.Validate(body);+ if (!preflight.IsValid) return AirChamferFailure("localized-fillet-junction-preflight-verification-failed", preflight.Diagnostics.Select(d => d.Code));+ if (!FirmamentManifoldChecker.IsManifold(body)) return AirChamferFailure("localized-fillet-junction-emitted-body-is-not-manifold");+ var step = Step242Exporter.ExportBody(body, new Step242ExportOptions+ {+ ProductName = compiled.Construction.ConstructionId,+ ApplicationName = AirLocalizedEdgeJunctionFilletCompileResult.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-fillet-junction-step-reimport-verification-failed");++ var topology = compiled.Construction.TopologyPlan;+ var cylinders = body.Geometry.Surfaces.Count(surface => surface.Value.Kind == SurfaceGeometryKind.Cylinder);+ var planes = body.Geometry.Surfaces.Count(surface => surface.Value.Kind == SurfaceGeometryKind.Plane);+ var report = new FirmamentAirChamferReport(+ new("Fillet", 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-fillet-junction-direct-intersection-candidate",+ new Dictionary<string, string> { ["Selection"] = "semantic Face(+X),Face(+Z); Face(+Y),Face(+Z)", ["MaterialSide"] = compiled.Construction.MaterialSide, ["Branch"] = compiled.Construction.Closure.Branch }),+ new("LocalizedEdgeJunction", 0, [], "ordered-explicit-loops", "DirectIntersectionEllipse",+ $"replacementFaces=2;junctionFaces=0;sharedEdges=1;curve=Ellipse;branch={compiled.Construction.Closure.Branch}", true),+ new(true, topology.ExpectedVertexCount, topology.ExpectedEdgeCount, topology.ExpectedFaceCount, topology.ExpectedLoopCount, topology.ExpectedCoedgeCount, 0,+ "DirectIntersectionEllipse", topology.DeterministicSignature, "LocalizedEdgeJunction"),+ new(AirLocalizedEdgeJunctionFilletCompileResult.ProductionRoute, false, true, body.Topology.Vertices.Count(), body.Topology.Edges.Count(), body.Topology.Faces.Count(), Bounds(body), first.Distance, first.Distance, cylinders, 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)"], "Fillet", "ConstantRadius", first.Distance, "Direct", "LocalizedEdgeJunction", "None(DirectIntersection)", 2, 0,+ new(true, topology.DeterministicSignature), "valid", false, 1, 1,+ new("DirectIntersection", "Cylinder", "Cylinder", "Ellipse", true, 1, compiled.Construction.Closure.Branch)));+ return KernelResult<FirmamentStepExportResult>.Success(new FirmamentStepExportResult(step.Value, $"{solid.Name}.{first.Name}.{second.Name}", 0, "air-fillet", "localized-edge-junction-fillet", 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 d72b2a73..02c6fc3c 100644--- a/Aetheris.Kernel.Firmament/FirmamentStepExportResult.cs+++ b/Aetheris.Kernel.Firmament/FirmamentStepExportResult.cs@@ -65,7 +65,17 @@ public sealed record FirmamentLocalizedEdgeJunctionTrace(string Preflight,bool LegacyFallback,int CandidatePlans,- int HardValidPlans);+ int HardValidPlans,+ FirmamentLocalizedJunctionClosureTrace? Closure = null);++public sealed record FirmamentLocalizedJunctionClosureTrace(+ string Kind,+ string SurfaceA,+ string SurfaceB,+ string CurveKind,+ bool Exact,+ int SharedEdges,+ string Branch);/// <summary>Authoritative shared semantic evidence for localized edge replacement routes.</summary>public sealed record FirmamentLocalizedEdgeFinishTrace(diff --git a/docs/air/air-fillet-junction-m4.md b/docs/air/air-fillet-junction-m4.mdindex 1d8d62b4..9538ce5d 100644--- a/docs/air/air-fillet-junction-m4.md+++ b/docs/air/air-fillet-junction-m4.md@@ -1,78 +1,102 @@-# AIR-FILLET-JUNCTION-M4 — two-edge equal-radius fillet investigation+# AIR-FILLET-DIRECT-JUNCTION-M4A-## Result+## Corrected conclusion-M4 does **not** admit a two-edge fillet STEP route yet. It closes the former-implicit rejection with a typed Construction AIR investigation and an exact-geometric witness. No BRep, STEP, or legacy fallback is emitted for this case.+The M4 spherical investigation was valuable negative evidence but its architectural+conclusion was too broad. A sphere is the three-edge corner candidate; it is not+required for two equal-radius fillets. The two selected replacement cylinders+close directly.-The investigated source domain is a history-known axis-aligned box with:+## Admitted construction++Only a history-known axis-aligned box with the convex positive corner is admitted:++```text+SharedEdge(+X,+Z), SharedEdge(+Y,+Z), constant equal radius R+```++Feature AIR owns two `AirEdgeFinishFeature` intents. Construction AIR owns the+two exact `CylinderSurface` replacements and one+`LocalizedEdgeJunctionDirectIntersectionClosure`. The closure is `Direct`, not+`Patch`; there is no spherical face and no legacy BRep surgery.++Let the positive box corner be `(hx, hy, hz)` and set:++```text+C = (hx-R, hy-R, hz-R)+A = cylinder through C, axis +Y, radius R+B = cylinder through C, axis +X, radius R+```++Their equations are:++```text+(x-cx)^2 + (z-cz)^2 = R^2+(y-cy)^2 + (z-cz)^2 = R^2+```++The material-side branch is `x-cx = y-cy >= 0`, `z-cz >= 0`. With parameter+`t in [0, pi/2]`, its exact finite seam is:```text-SharedEdge(+X,+Z), SharedEdge(+Y,+Z), equal constant radius R, convex +X/+Y/+Z corner+P(t) = C + (R cos(t), R cos(t), R sin(t))```-It validates `10 x 8 x 6, R=1`, `10 x 8 x 6, R=2`, and `12 x 5 x 7, R=1`-up to shared-patch admission. Zero, oversized, unequal, non-sharing, and-no-history inputs are rejected before topology emission.+This lies in `x-y = cx-cy` and is an exact planar ellipse: major radius+`sqrt(2) R`, minor radius `R`, plane normal `(1,-1,0)`, major direction+`(1,1,0)`. It runs from `(hx,hy,hz-R)` to `(hx-R,hy-R,hz)`. Substitution in+both cylinder equations gives zero containment deviation. The opposite-sign+branch is outside the selected convex replacement regions and is not admitted.-## Exact candidate derivation+Each cylinder is trimmed by its remote quarter-circle, two planar tangent+boundaries, and this shared ellipse. The result is a closed eight-face shell:+six retained/unaffected planes plus two cylinders, 11 vertices, 17 edges, and+one shared ellipse. No corner patch is present.-Let the box's positive corner be `(hx, hy, hz)`. The two single-edge cylinders-have common radius `R` and axes through+For an independent volume cross-check (not the signed-shell volume path), the+two single-edge removals overlap by```text-C = (hx-R, hy-R, hz-R)-axis A = +Y for SharedEdge(+X,+Z)-axis B = +X for SharedEdge(+Y,+Z)+R^3 (5/3 - pi/2) = integral[0,R] (R - sqrt(R^2-z^2))^2 dz.```-The only simple equal-radius spherical candidate tangent to both cylinders is-the sphere centered at `C` with radius `R`. Its two shared seams have zero-positional and tangent-plane deviation from the selected cylinders.--However, its remaining exact boundary is the quarter circle in `z = hz-R`-between `(hx, hy-R, hz-R)` and `(hx-R, hy, hz-R)`. This is precisely the seam-of the unselected radius-`R` cylinder about `+Z` — the fillet for-`SharedEdge(+X,+Y)`. The sphere meets each retained support plane only at its-one tangency point, so it has no non-degenerate trim curve on `+X`, `+Y`, or-`+Z` with which to close the two-edge shell.--Consequently a spherical/octant patch would covertly materialize a third fillet-and is rejected. A torus cannot supply the forced spherical tangent seams, and-no other exact supported surface family has been proven to meet the two-cylinders and retained planes with G0/G1 closure. M4 returns the typed-`CornerPatchSurfaceRequired` error with the sphere center, radius, zero cylinder-tangency deviation, missing third-boundary length `pi*R/2`, and required third-surface as evidence.--## Construction AIR and policy--The compiler constructs the two semantic `AirEdgeFinishFeature` fillet intents-and the immutable spherical candidate witness before rejecting it. It uses no-topology identifiers in Firmament and produces no BRepPlan because no-hard-valid plan exists. Candidate count is zero hard-valid plans; utility-scoring is deliberately dormant.--The existing two-edge chamfer remains the sole authoritative-`LocalizedEdgeJunction` BRepPlan route. It must not be repurposed for fillets.--## Continuity, preflight, STEP, and volume--The rejected sphere candidate has exact G0/G1 cylinder seams (`0` measured-deviation). The unowned third seam has length `pi*R/2`, so there is no closed,-manifold two-edge shell to preflight or export. Accordingly no STEP hash,-reimport, CAD Assistant session, or volume claim is produced for M4; exporting-an analytically invalid shell would be false evidence. Existing sphere and-cylinder containment checks in `BrepExportPreflight` already cover a future-valid analytic plan, but no patch-specific preflight is added until a closing-surface is proven.--## Deferred scope and next milestone--This result does not claim rolling-ball, chain, three-edge, mixed, variable--radius, concave, curved-support, or imported-body fillets. The next bounded-milestone should either admit the three equal-radius edges at this corner (where-the derived spherical patch has all three cylindrical seams), or derive and-prove a separate exact two-cylinder-to-support corner surface before adding a-two-edge emission path.+Thus the expected retained volume is+`W*D*H - R^2(1-pi/4)(W+D) + R^3(5/3-pi/2)`. The test suite checks this exact+overlap against a 100,000-interval independent trapezoidal integration.++## Plan, preflight, and STEP++One authoritative `LocalizedEdgeJunctionTopologyPlan` drives the emitter. Its+shared edge has `DirectJunctionBoundary` and `SharedJunction` roles. Export+preflight validates the ellipse on both cylinder faces (endpoints and midpoint)+and, additionally, verifies that every edge-curve trim endpoint agrees with its+topology edge endpoint in the binding's orientation. The latter check caught a+reversed remote-B circular cap binding: although its geometric locus was right,+its parameter direction disagreed with the BRep edge and CAD Assistant folded+the far-end closure. The cap now has the same direction as its topology edge;+the old binding fails Enforce preflight. STEP exports the analytic `ELLIPSE` and+two `CYLINDRICAL_SURFACE` supports; no spline or faceting is used.++The CLI report exposes `closure.kind=DirectIntersection`, `curveKind=Ellipse`,+`exact=true`, `sharedEdges=1`, `replacementFaces=2`, and `junctionFaces=0`.+There is one hard-valid plan, so selection is `Direct` and utility scoring remains+dormant.++CAD Assistant opened the regenerated canonical `R=1` and `R=2` AP242 artifacts+in shaded-with-edges mode. Both rendered as continuous rounded box corners with+no gap, inversion, fold, or extra face visible, including the previously bad+remote-B closure. The viewer does not visibly draw the analytic direct seam in+its default display; its exactness remains established by STEP reimport and+two-cylinder containment checks rather than raster appearance alone. Hashes:+`E2CF4D60A5A6CA99AB045CFCA5FABAA7EF933E7DD55866D8433F5FD49A429AEA` (R=1)+and `A4CCE35767C3BC296E0E24C39C3887EDC3B6FFFAF72990AF7D58D50F32770218` (R=2).++## Spherical negative evidence and scope++The former radius-R sphere centered at `C` has a third seam for the unselected+`SharedEdge(+X,+Y)` cylinder. That is exactly why it is the three-edge equal-+radius corner construction, not the two-edge direct chain construction.++Deferred: unequal/variable radii, mixed finishes, three selected edges, concave+or non-orthogonal/curved supports, imported bodies, long chains, and oversized+radii. The next separate milestone is the three-edge spherical corner.diff --git a/testdata/firmament/air-fillet-junction-m4a/canonical-r1.firmament b/testdata/firmament/air-fillet-junction-m4a/canonical-r1.firmamentnew file mode 100644index 00000000..e709b1fb--- /dev/null+++ b/testdata/firmament/air-fillet-junction-m4a/canonical-r1.firmament@@ -0,0 +1,6 @@+Model Localized mm+Box Base { Size: [10mm, 8mm, 6mm] }+Modify Base {+ EdgeFinish First { Face: +X Target: SharedEdgePlusZ Kind: Fillet Distance: 1mm }+ EdgeFinish Second { Face: +Y Target: SharedEdgePlusZ Kind: Fillet Distance: 1mm }+}diff --git a/testdata/firmament/air-fillet-junction-m4a/larger-r2.firmament b/testdata/firmament/air-fillet-junction-m4a/larger-r2.firmamentnew file mode 100644index 00000000..38046857--- /dev/null+++ b/testdata/firmament/air-fillet-junction-m4a/larger-r2.firmament@@ -0,0 +1,6 @@+Model Localized mm+Box Base { Size: [10mm, 8mm, 6mm] }+Modify Base {+ EdgeFinish First { Face: +X Target: SharedEdgePlusZ Kind: Fillet Distance: 2mm }+ EdgeFinish Second { Face: +Y Target: SharedEdgePlusZ Kind: Fillet Distance: 2mm }+}diff --git a/testdata/firmament/air-fillet-junction-m4a/nonsquare-r1.firmament b/testdata/firmament/air-fillet-junction-m4a/nonsquare-r1.firmamentnew file mode 100644index 00000000..61b3152e--- /dev/null+++ b/testdata/firmament/air-fillet-junction-m4a/nonsquare-r1.firmament@@ -0,0 +1,6 @@+Model Localized mm+Box Base { Size: [12mm, 5mm, 7mm] }+Modify Base {+ EdgeFinish First { Face: +X Target: SharedEdgePlusZ Kind: Fillet Distance: 1mm }+ EdgeFinish Second { Face: +Y Target: SharedEdgePlusZ Kind: Fillet Distance: 1mm }+}