Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Add profile inspection and stitch extrusion topology

Yuechen Lib00b4ea42025
diff --git a/Aetheris.CLI/CliRunner.cs b/Aetheris.CLI/CliRunner.cs
index a7096330..4c1d6c32 100644
--- a/Aetheris.CLI/CliRunner.cs
+++ b/Aetheris.CLI/CliRunner.cs
@@ -7,6 +7,7 @@ using Aetheris.Kernel.Core.Step242;
using Aetheris.Kernel.Firmament;
using Aetheris.Kernel.Firmament.Assembly;
using Aetheris.Kernel.Firmament.FirmamentV2;
+using Aetheris.Kernel.Firmament.Materializer;
using Aetheris.Firmament.FrictionLab.CIRLab;
namespace Aetheris.CLI;
@@ -111,9 +112,10 @@ public static class CliRunner
string? Error,
string? Classification = null,
int? RigidRootCount = null);
- private const string TopLevelUsage = "Usage: aetheris <build|validate|analyze|verify|match|trace|canon|asm|experimental> <path> [options]";
+ private const string TopLevelUsage = "Usage: aetheris <build|validate|inspect-profile|analyze|verify|match|trace|canon|asm|experimental> <path> [options]";
private const string BuildUsage = "Usage: aetheris build <file.firmament> [--out <path>] [--json]";
private const string ValidateUsage = "Usage: aetheris validate <file.firmament|file.firmfixture> [--forge-pack <path>] [--json]";
+ private const string InspectProfileUsage = "Usage: aetheris inspect-profile <file.firmament> [--json]";
private const string AnalyzeUsage = "Usage: aetheris analyze <file.step> [--face <id>] [--edge <id>] [--vertex <id>] [--json]";
private const string AnalyzeMapUsage = "Usage: aetheris analyze map <file.step> (--plane <xy|xz|yz> --direction <+x|-x|+y|-y|+z|-z> | --views six --llm) --resolution <NxM> [--point <u,v>] [--rank-probes|--evidence-bundle] --json";
private const string AnalyzeSectionUsage = "Usage: aetheris analyze section <file.step> (--xy|--xz|--yz) --offset <value> --json";
@@ -170,6 +172,7 @@ public static class CliRunner
{
"build" => RunBuild(args.Skip(1).ToArray(), stdout, stderr),
"validate" => RunValidate(args.Skip(1).ToArray(), stdout, stderr),
+ "inspect-profile" => RunInspectProfile(args.Skip(1).ToArray(), stdout, stderr),
"analyze" => RunAnalyze(args.Skip(1).ToArray(), stdout, stderr),
"verify" => RunVerify(args.Skip(1).ToArray(), stdout, stderr),
"match" => RunMatch(args.Skip(1).ToArray(), stdout, stderr),
@@ -399,6 +402,30 @@ public static class CliRunner
}
+ private static int RunInspectProfile(string[] args, TextWriter stdout, TextWriter stderr)
+ {
+ if (args.Length == 0 || IsHelpFlag(args[0])) { stdout.WriteLine(InspectProfileUsage); return args.Length == 0 ? 1 : 0; }
+ var json = args.Skip(1).All(x => x == "--json");
+ if (!json) { stderr.WriteLine(InspectProfileUsage); return 1; }
+ if (!File.Exists(args[0])) { stderr.WriteLine($"Profile source was not found: {args[0]}"); return 1; }
+ var parsed = ProfileAuthoringParser.Parse(File.ReadAllText(args[0]));
+ if (parsed.Profile is null) { stderr.WriteLine(string.Join(Environment.NewLine, parsed.Diagnostics)); return 1; }
+ var validation = ResolvedProfile2DValidator.Validate(parsed.Profile);
+ var report = new
+ {
+ profile = new
+ {
+ parsed.Profile.Name, parsed.Profile.PlaneFrame,
+ loops = parsed.Profile.Loops.Count,
+ segments = parsed.Profile.Loops.SelectMany(x => x.Segments).Select(x => new { x.Name, guide = x.Provenance.ConceptStableId, stableId = x.Provenance.StableId, derivation = x.Provenance.Derivation, geometry = x.Geometry.GetType().Name }),
+ validation.IsValid, validation.SignedArea, validation.Diagnostics,
+ extrusionHeight = parsed.Height
+ }
+ };
+ if (json) stdout.WriteLine(JsonSerializer.Serialize(report, JsonOptions)); else stdout.WriteLine($"Profile {parsed.Profile.Name}: {(validation.IsValid ? "valid" : "invalid")}");
+ return validation.IsValid ? 0 : 1;
+ }
+
private static int RunValidate(string[] args, TextWriter stdout, TextWriter stderr)
{
if (args.Length == 0)
@@ -2400,6 +2427,7 @@ public static class CliRunner
stdout.WriteLine("Commands:");
stdout.WriteLine(" build Build a .firmament source file into STEP.");
stdout.WriteLine(" validate Validate Firmament V2 manufacturing intent and emit report JSON.");
+ stdout.WriteLine(" inspect-profile Resolve and validate a scaffold-referenced Profile.");
stdout.WriteLine(" analyze Analyze STEP topology, geometry, map, and sections.");
stdout.WriteLine(" verify Reimport STEP and emit independent B-rep/external-display evidence.");
stdout.WriteLine(" match Match a compile-time Concept Struct against observed STEP geometry.");
@@ -2415,6 +2443,7 @@ public static class CliRunner
stdout.WriteLine("Examples:");
stdout.WriteLine(" aetheris build model.firmament --out model.step");
stdout.WriteLine(" aetheris validate fixtures/FirmamentV2/Language/valid/v2-phase1-validation-report.valid.firmfixture --json");
+ stdout.WriteLine(" aetheris inspect-profile fixtures/FirmamentV2/Profile/valid/scaffold-rectangle.firmament --json");
stdout.WriteLine(" aetheris analyze model.step");
stdout.WriteLine(" aetheris analyze model.step --json");
stdout.WriteLine(" aetheris match model.step concept.firmament --json");
diff --git a/Aetheris.Kernel.Firmament.Tests/Integration/LineArcProfileExtrudeEmitterTests.cs b/Aetheris.Kernel.Firmament.Tests/Integration/LineArcProfileExtrudeEmitterTests.cs
index bb38b179..0d831978 100644
--- a/Aetheris.Kernel.Firmament.Tests/Integration/LineArcProfileExtrudeEmitterTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/Integration/LineArcProfileExtrudeEmitterTests.cs
@@ -34,6 +34,18 @@ public class LineArcProfileExtrudeEmitterTests
Assert.Contains(result.Diagnostics, x => x.Contains("invalid height", StringComparison.Ordinal));
}
+ [Fact]
+ public void StitchesAdjacentProfileSegmentsIntoSharedTopology()
+ {
+ var result = LineArcProfileExtrudeEmitter.TryEmit(new LineArcProfileExtrudeRequest([RectOuter(20, 10)], 5));
+ var body = Assert.IsType<Aetheris.Kernel.Core.Brep.BrepBody>(result.Body);
+
+ // Four profile vertices at each cap, and one vertical edge at each profile vertex.
+ // The former emitter allocated an independent vertex pair for each segment.
+ Assert.Equal(8, body.Topology.Vertices.Count());
+ Assert.Equal(12, body.Topology.Edges.Count());
+ }
+
public static IEnumerable<object[]> ValidCases()
{
yield return ["rectangle", new LineArcProfileExtrudeRequest([RectOuter(20, 10)], 5), 6, 0];
diff --git a/Aetheris.Kernel.Firmament.Tests/Integration/ResolvedProfile2DTests.cs b/Aetheris.Kernel.Firmament.Tests/Integration/ResolvedProfile2DTests.cs
new file mode 100644
index 00000000..509872af
--- /dev/null
+++ b/Aetheris.Kernel.Firmament.Tests/Integration/ResolvedProfile2DTests.cs
@@ -0,0 +1,32 @@
+using Aetheris.Kernel.Firmament.Materializer;
+
+namespace Aetheris.Kernel.Firmament.Tests.Integration;
+
+public sealed class ResolvedProfile2DTests
+{
+ [Fact]
+ public void ValidatesNamedCounterClockwiseRectangleAndExtrudesThroughExistingEmitter()
+ {
+ var profile = Profile("Plate", [(-1d,-1d),(1d,-1d),(1d,1d),(-1d,1d)]);
+ var validation = ResolvedProfile2DValidator.Validate(profile);
+ Assert.True(validation.IsValid, string.Join("; ", validation.Diagnostics));
+ Assert.Equal(4d, validation.SignedArea);
+ Assert.Equal(LineArcProfileExtrudeStatus.Succeeded, ResolvedProfile2DValidator.Extrude(profile, 2).Status);
+ }
+
+ [Fact]
+ public void RejectsSelfIntersectingNamedLoopBeforeEmission()
+ {
+ var profile = Profile("BowTie", [(-1d,-1d),(1d,1d),(-1d,1d),(1d,-1d)]);
+ var validation = ResolvedProfile2DValidator.Validate(profile);
+ Assert.False(validation.IsValid);
+ Assert.Contains(validation.Diagnostics, d => d.Contains("self-intersection", StringComparison.Ordinal));
+ Assert.Equal(LineArcProfileExtrudeStatus.Rejected, ResolvedProfile2DValidator.Extrude(profile, 2).Status);
+ }
+
+ private static ResolvedProfile2D Profile(string name, IReadOnlyList<(double X,double Y)> points)
+ {
+ var segments = points.Select((p,i) => new ResolvedProfileSegment2D($"S{i}", new LineArcLineSegment2D(p, points[(i+1)%points.Count]), new ProfileSegmentProvenance($"profile:{name}.Outer.S{i}", "concept:fixture.Guide", "fixture", "literal-test", "XY"))).ToArray();
+ return new ResolvedProfile2D(name, "XY", [new ResolvedProfileLoop2D("Outer", true, segments)]);
+ }
+}
diff --git a/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs b/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs
index b97867da..59a73af1 100644
--- a/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs
@@ -49,6 +49,15 @@ public static class FirmamentBuildAndExport
private static KernelResult<FirmamentStepExportResult> ExportSource(string sourceText, string? sourceDirectory = null)
{
+ if (ProfileAuthoringParser.IsProfileSource(sourceText))
+ {
+ var parsed = ProfileAuthoringParser.Parse(sourceText);
+ if (parsed.Profile is null) return KernelResult<FirmamentStepExportResult>.Failure(parsed.Diagnostics.Select(x => new Kernel.Core.Diagnostics.KernelDiagnostic(Kernel.Core.Diagnostics.KernelDiagnosticCode.ValidationFailed, Kernel.Core.Diagnostics.KernelDiagnosticSeverity.Error, x, "FirmamentV2.Profile")).ToArray());
+ var emitted = ResolvedProfile2DValidator.Extrude(parsed.Profile, parsed.Height);
+ if (emitted.Status != LineArcProfileExtrudeStatus.Succeeded || emitted.Body is null) return KernelResult<FirmamentStepExportResult>.Failure(emitted.Diagnostics.Select(x => new Kernel.Core.Diagnostics.KernelDiagnostic(Kernel.Core.Diagnostics.KernelDiagnosticCode.ValidationFailed, Kernel.Core.Diagnostics.KernelDiagnosticSeverity.Error, x, "FirmamentV2.Profile")).ToArray());
+ var step = Step242Exporter.ExportBody(emitted.Body); if (!step.IsSuccess) return KernelResult<FirmamentStepExportResult>.Failure(step.Diagnostics);
+ return KernelResult<FirmamentStepExportResult>.Success(new FirmamentStepExportResult(step.Value, parsed.Profile.Name, 0, "profile-extrude", "line-arc-profile"));
+ }
var v2Parse = FirmamentV2Parser.Parse(sourceText, sourceDirectory);
if (v2Parse.IsSuccess && v2Parse.Document is not null)
{
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs
new file mode 100644
index 00000000..883c2006
--- /dev/null
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs
@@ -0,0 +1,37 @@
+using System.Globalization;
+using System.Text.RegularExpressions;
+using Aetheris.Kernel.Firmament.Materializer;
+
+namespace Aetheris.Kernel.Firmament.FirmamentV2;
+
+/// <summary>Bounded parser for the first scaffold-referenced profile source route.</summary>
+public static class ProfileAuthoringParser
+{
+ private static readonly Regex Point = new(@"\bPoint2\s+(?<n>\w+)\s*\{\s*Position\s*:\s*\[(?<x>[-+.\d]+)mm\s*,\s*(?<y>[-+.\d]+)mm\]", RegexOptions.Singleline);
+ private static readonly Regex Line = new(@"\bLine2\s+(?<n>\w+)\s*\{\s*From\s*:\s*(?<a>\w+)\s*;?\s*To\s*:\s*(?<b>\w+)", RegexOptions.Singleline);
+ private static readonly Regex Circle = new(@"\bCircle2\s+(?<n>\w+)\s*\{\s*Center\s*:\s*(?<c>\w+)\s*;?\s*Radius\s*:\s*(?<r>[-+.\d]+)mm", RegexOptions.Singleline);
+ private static readonly Regex Header = new(@"\bProfile\s+(?<n>\w+)\s+Using\s+(?<layout>\w+)\s*\{(?<body>[\s\S]*)", RegexOptions.CultureInvariant);
+ private static readonly Regex Segment = new(@"\bSegment\s+(?<n>\w+)\s*\{\s*Trace\s*:\s*(?<trace>\w+)\s*;?\s*From\s*:\s*(?<from>\w+)\s*;?\s*To\s*:\s*(?<to>\w+)(?:\s*;?\s*Sweep\s*:\s*(?<sweep>Clockwise|CounterClockwise))?", RegexOptions.Singleline);
+ private static readonly Regex Extrude = new(@"\bExtrude\s+\w+\s*\{\s*Profile\s*:\s*(?<p>\w+)\s*;?\s*From\s*:\s*(?<a>[-+.\d]+)mm\s*;?\s*To\s*:\s*(?<b>[-+.\d]+)mm", RegexOptions.Singleline);
+
+ public static bool IsProfileSource(string source) => Header.IsMatch(source);
+ public static (ResolvedProfile2D? Profile, double Height, IReadOnlyList<string> Diagnostics) Parse(string source)
+ {
+ var d=new List<string>(); var h=Header.Match(source); if(!h.Success)return(null,0,["profile-source-missing-profile"]);
+ var pts=new Dictionary<string,(double X,double Y)>(StringComparer.Ordinal);
+ foreach(Match m in Point.Matches(source))pts[m.Groups["n"].Value]=(N(m,"x"),N(m,"y"));
+ var lines=new Dictionary<string,LineArcLineSegment2D>(StringComparer.Ordinal);
+ foreach(Match m in Line.Matches(source)){if(!pts.TryGetValue(m.Groups["a"].Value,out var a)||!pts.TryGetValue(m.Groups["b"].Value,out var b))d.Add($"profile-layout-unresolved-line:{m.Groups["n"].Value}");else lines[m.Groups["n"].Value]=new(a,b);}
+ var circles=new Dictionary<string,((double X,double Y) C,double R)>(StringComparer.Ordinal);
+ foreach(Match m in Circle.Matches(source)){if(!pts.TryGetValue(m.Groups["c"].Value,out var c))d.Add($"profile-layout-unresolved-circle:{m.Groups["n"].Value}");else circles[m.Groups["n"].Value]=(c,N(m,"r"));}
+ var segments=new List<ResolvedProfileSegment2D>();
+ foreach(Match m in Segment.Matches(h.Groups["body"].Value))
+ { var n=m.Groups["n"].Value; if(!pts.TryGetValue(m.Groups["from"].Value,out var a)||!pts.TryGetValue(m.Groups["to"].Value,out var b)){d.Add($"profile-segment-unresolved:{n}");continue;} var trace=m.Groups["trace"].Value; LineArcProfileCurve2D? g=null;
+ if(lines.TryGetValue(trace,out var line)){if(!OnLine(a,line)||!OnLine(b,line))d.Add($"profile-endpoint-not-on-guide:{n}:{trace}"); g=new LineArcLineSegment2D(a,b);}
+ else if(circles.TryGetValue(trace,out var circle)){if(!OnCircle(a,circle)||!OnCircle(b,circle)||!m.Groups["sweep"].Success){d.Add($"profile-arc-invalid:{n}:{trace}");continue;}var sa=Math.Atan2(a.Y-circle.C.Y,a.X-circle.C.X);var sw=Math.Atan2(b.Y-circle.C.Y,b.X-circle.C.X)-sa;var ccw=m.Groups["sweep"].Value=="CounterClockwise";while(ccw&&sw<=0)sw+=2*Math.PI;while(!ccw&&sw>=0)sw-=2*Math.PI;g=new LineArcCircularArc2D(circle.C,circle.R,sa,sw);}
+ else {d.Add($"profile-guide-missing:{n}:{trace}");continue;} segments.Add(new(n,g,new($"profile:{h.Groups["n"].Value}.Outer.{n}",$"concept:{h.Groups["layout"].Value}.{trace}","source",$"Trace({trace})","XY"))); }
+ var e=Extrude.Match(source);var height=e.Success?Math.Abs(N(e,"b")-N(e,"a")):0;if(!e.Success||e.Groups["p"].Value!=h.Groups["n"].Value)d.Add("profile-extrude-missing-or-mismatched");
+ return d.Count>0?(null,height,d):(new ResolvedProfile2D(h.Groups["n"].Value,"XY",[new ResolvedProfileLoop2D("Outer",true,segments)]),height,d);
+ }
+ private static double N(Match m,string n)=>double.Parse(m.Groups[n].Value,CultureInfo.InvariantCulture); private static bool OnLine((double X,double Y)p,LineArcLineSegment2D l)=>Math.Abs((l.End.X-l.Start.X)*(p.Y-l.Start.Y)-(l.End.Y-l.Start.Y)*(p.X-l.Start.X))<1e-7; private static bool OnCircle((double X,double Y)p,((double X,double Y)C,double R)c)=>Math.Abs(Math.Sqrt((p.X-c.C.X)*(p.X-c.C.X)+(p.Y-c.C.Y)*(p.Y-c.C.Y))-c.R)<1e-7;
+}
diff --git a/Aetheris.Kernel.Firmament/Materializer/LineArcProfileExtrudeEmitter.cs b/Aetheris.Kernel.Firmament/Materializer/LineArcProfileExtrudeEmitter.cs
index 0c8e3c90..abbab5b4 100644
--- a/Aetheris.Kernel.Firmament/Materializer/LineArcProfileExtrudeEmitter.cs
+++ b/Aetheris.Kernel.Firmament/Materializer/LineArcProfileExtrudeEmitter.cs
@@ -7,16 +7,16 @@ using Aetheris.Kernel.Core.Topology;
namespace Aetheris.Kernel.Firmament.Materializer;
-internal abstract record LineArcProfileCurve2D;
-internal sealed record LineArcLineSegment2D((double X, double Y) Start, (double X, double Y) End) : LineArcProfileCurve2D;
-internal sealed record LineArcCircularArc2D((double X, double Y) Center, double Radius, double StartAngleRadians, double SweepAngleRadians) : LineArcProfileCurve2D;
-internal sealed record LineArcFullCircle2D((double X, double Y) Center, double Radius) : LineArcProfileCurve2D;
-internal sealed record LineArcProfileLoop2D(IReadOnlyList<LineArcProfileCurve2D> Curves, bool IsHole);
-internal sealed record LineArcProfileExtrudeRequest(IReadOnlyList<LineArcProfileLoop2D> Loops, double Height);
-internal enum LineArcProfileExtrudeStatus { Succeeded, Rejected, Deferred, Failed }
-internal sealed record LineArcProfileExtrudeResult(LineArcProfileExtrudeStatus Status, BrepBody? Body, IReadOnlyList<string> Diagnostics);
+public abstract record LineArcProfileCurve2D;
+public sealed record LineArcLineSegment2D((double X, double Y) Start, (double X, double Y) End) : LineArcProfileCurve2D;
+public sealed record LineArcCircularArc2D((double X, double Y) Center, double Radius, double StartAngleRadians, double SweepAngleRadians) : LineArcProfileCurve2D;
+public sealed record LineArcFullCircle2D((double X, double Y) Center, double Radius) : LineArcProfileCurve2D;
+public sealed record LineArcProfileLoop2D(IReadOnlyList<LineArcProfileCurve2D> Curves, bool IsHole);
+public sealed record LineArcProfileExtrudeRequest(IReadOnlyList<LineArcProfileLoop2D> Loops, double Height);
+public enum LineArcProfileExtrudeStatus { Succeeded, Rejected, Deferred, Failed }
+public sealed record LineArcProfileExtrudeResult(LineArcProfileExtrudeStatus Status, BrepBody? Body, IReadOnlyList<string> Diagnostics);
-internal static class LineArcProfileExtrudeEmitter
+public static class LineArcProfileExtrudeEmitter
{
private const double Tol = 1e-6;
@@ -63,6 +63,27 @@ internal static class LineArcProfileExtrudeEmitter
var sideFaces = new List<(LoopId Loop, SurfaceGeometry Surface, string Diag)>();
var points = new Dictionary<VertexId, Point3D>();
var edgeCurves = new Dictionary<EdgeId, CurveGeometry>();
+ // A profile loop owns its vertices. Adjacent curves that meet at the same
+ // resolved point must reuse the same top/bottom vertices and vertical edge;
+ // geometric coincidence is not an authoritative topology connection.
+ var bottomVertices = new Dictionary<(long X, long Y), VertexId>();
+ var topVertices = new Dictionary<(long X, long Y), VertexId>();
+ var verticalEdges = new Dictionary<(long X, long Y), EdgeId>();
+ (long X, long Y) Key((double X, double Y) p) => ((long)Math.Round(p.X / Tol), (long)Math.Round(p.Y / Tol));
+ VertexId Vertex((double X, double Y) p, double z, Dictionary<(long X, long Y), VertexId> cache)
+ {
+ var key = Key(p);
+ if (cache.TryGetValue(key, out var existing)) return existing;
+ var created = b.AddVertex(); points[created] = new Point3D(p.X, p.Y, z); cache.Add(key, created); return created;
+ }
+ EdgeId Vertical((double X, double Y) p, VertexId bottom, VertexId top)
+ {
+ var key = Key(p);
+ if (verticalEdges.TryGetValue(key, out var existing)) return existing;
+ var created = b.AddEdge(bottom, top);
+ edgeCurves[created] = CurveGeometry.FromLine(new Line3Curve(points[bottom], Direction3D.Create(points[top] - points[bottom])));
+ verticalEdges.Add(key, created); return created;
+ }
foreach (var loop in profile.Loops)
{
@@ -73,15 +94,11 @@ internal static class LineArcProfileExtrudeEmitter
{
case LineArcLineSegment2D line:
{
- var vb0 = b.AddVertex(); var vb1 = b.AddVertex(); var vt0 = b.AddVertex(); var vt1 = b.AddVertex();
- points[vb0] = new(line.Start.X, line.Start.Y, z0); points[vb1] = new(line.End.X, line.End.Y, z0);
- points[vt0] = new(line.Start.X, line.Start.Y, z1); points[vt1] = new(line.End.X, line.End.Y, z1);
- var eb = b.AddEdge(vb0, vb1); var et = b.AddEdge(vt0, vt1); var es0 = b.AddEdge(vb0, vt0); var es1 = b.AddEdge(vb1, vt1);
+ var vb0 = Vertex(line.Start, z0, bottomVertices); var vb1 = Vertex(line.End, z0, bottomVertices); var vt0 = Vertex(line.Start, z1, topVertices); var vt1 = Vertex(line.End, z1, topVertices);
+ var eb = b.AddEdge(vb0, vb1); var et = b.AddEdge(vt0, vt1); var es0 = Vertical(line.Start, vb0, vt0); var es1 = Vertical(line.End, vb1, vt1);
edgeCurves[eb] = CurveGeometry.FromLine(new Line3Curve(points[vb0], Direction3D.Create(points[vb1] - points[vb0])));
edgeCurves[et] = CurveGeometry.FromLine(new Line3Curve(points[vt0], Direction3D.Create(points[vt1] - points[vt0])));
- edgeCurves[es0] = CurveGeometry.FromLine(new Line3Curve(points[vb0], Direction3D.Create(points[vt0] - points[vb0])));
- edgeCurves[es1] = CurveGeometry.FromLine(new Line3Curve(points[vb1], Direction3D.Create(points[vt1] - points[vb1])));
- bottomUses.Add(loop.IsHole ? Use.R(eb) : Use.F(eb)); topUses.Add(loop.IsHole ? Use.F(et) : Use.R(et));
+ bottomUses.Add(loop.IsHole ? Use.R(eb) : Use.F(eb)); topUses.Add(loop.IsHole ? Use.R(et) : Use.F(et));
var loopId = AddLoop(b, [Use.F(eb), Use.F(es1), Use.R(et), Use.R(es0)]);
var dx = line.End.X - line.Start.X; var dy = line.End.Y - line.Start.Y; var nx = loop.IsHole ? -dy : dy; var ny = loop.IsHole ? dx : -dx;
sideFaces.Add((loopId, SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(line.Start.X, line.Start.Y, z0), Direction3D.Create(new Vector3D(nx, ny, 0)), Direction3D.Create(new Vector3D(0, 0, 1)))), "v2-v4-line-edge-side-face-emitted"));
@@ -91,12 +108,11 @@ internal static class LineArcProfileExtrudeEmitter
{
var s = (arc.Center.X + arc.Radius * Math.Cos(arc.StartAngleRadians), arc.Center.Y + arc.Radius * Math.Sin(arc.StartAngleRadians));
var e = (arc.Center.X + arc.Radius * Math.Cos(arc.StartAngleRadians + arc.SweepAngleRadians), arc.Center.Y + arc.Radius * Math.Sin(arc.StartAngleRadians + arc.SweepAngleRadians));
- var vb0=b.AddVertex();var vb1=b.AddVertex();var vt0=b.AddVertex();var vt1=b.AddVertex(); points[vb0]=new(s.Item1,s.Item2,z0); points[vb1]=new(e.Item1,e.Item2,z0); points[vt0]=new(s.Item1,s.Item2,z1); points[vt1]=new(e.Item1,e.Item2,z1);
- var eb=b.AddEdge(vb0,vb1); var et=b.AddEdge(vt0,vt1); var es0=b.AddEdge(vb0,vt0); var es1=b.AddEdge(vb1,vt1);
+ var vb0=Vertex(s,z0,bottomVertices);var vb1=Vertex(e,z0,bottomVertices);var vt0=Vertex(s,z1,topVertices);var vt1=Vertex(e,z1,topVertices);
+ var eb=b.AddEdge(vb0,vb1); var et=b.AddEdge(vt0,vt1); var es0=Vertical(s,vb0,vt0); var es1=Vertical(e,vb1,vt1);
edgeCurves[eb]=CurveGeometry.FromCircle(new Circle3Curve(new Point3D(arc.Center.X,arc.Center.Y,z0),Direction3D.Create(new Vector3D(0,0,1)),arc.Radius,Direction3D.Create(new Vector3D(1,0,0))));
edgeCurves[et]=CurveGeometry.FromCircle(new Circle3Curve(new Point3D(arc.Center.X,arc.Center.Y,z1),Direction3D.Create(new Vector3D(0,0,1)),arc.Radius,Direction3D.Create(new Vector3D(1,0,0))));
- edgeCurves[es0]=CurveGeometry.FromLine(new Line3Curve(points[vb0], Direction3D.Create(points[vt0]-points[vb0]))); edgeCurves[es1]=CurveGeometry.FromLine(new Line3Curve(points[vb1], Direction3D.Create(points[vt1]-points[vb1])));
- bottomUses.Add(loop.IsHole ? Use.R(eb) : Use.F(eb)); topUses.Add(loop.IsHole ? Use.F(et) : Use.R(et));
+ bottomUses.Add(loop.IsHole ? Use.R(eb) : Use.F(eb)); topUses.Add(loop.IsHole ? Use.R(et) : Use.F(et));
sideFaces.Add((AddLoop(b,[Use.F(eb),Use.F(es1),Use.R(et),Use.R(es0)]), SurfaceGeometry.FromCylinder(new CylinderSurface(new Point3D(arc.Center.X,arc.Center.Y,z0),Direction3D.Create(new Vector3D(0,0,1)),arc.Radius,Direction3D.Create(new Vector3D(1,0,0)))), "v2-v4-arc-edge-side-face-emitted"));
break;
}
@@ -107,7 +123,7 @@ internal static class LineArcProfileExtrudeEmitter
edgeCurves[eb]=CurveGeometry.FromCircle(new Circle3Curve(points[vb],Direction3D.Create(new Vector3D(0,0,1)),circle.Radius,Direction3D.Create(new Vector3D(1,0,0))));
edgeCurves[et]=CurveGeometry.FromCircle(new Circle3Curve(points[vt],Direction3D.Create(new Vector3D(0,0,1)),circle.Radius,Direction3D.Create(new Vector3D(1,0,0))));
edgeCurves[es]=CurveGeometry.FromLine(new Line3Curve(points[vb],Direction3D.Create(points[vt]-points[vb])));
- bottomUses.Add(loop.IsHole ? Use.R(eb) : Use.F(eb)); topUses.Add(loop.IsHole ? Use.F(et) : Use.R(et));
+ bottomUses.Add(loop.IsHole ? Use.R(eb) : Use.F(eb)); topUses.Add(loop.IsHole ? Use.R(et) : Use.F(et));
sideFaces.Add((AddLoop(b,[Use.F(eb),Use.F(es),Use.R(et),Use.R(es)]), SurfaceGeometry.FromCylinder(new CylinderSurface(points[vb],Direction3D.Create(new Vector3D(0,0,1)),circle.Radius,Direction3D.Create(new Vector3D(1,0,0)))), "v2-v4-full-circle-side-face-emitted"));
break;
}
diff --git a/Aetheris.Kernel.Firmament/Materializer/ResolvedProfile2D.cs b/Aetheris.Kernel.Firmament/Materializer/ResolvedProfile2D.cs
new file mode 100644
index 00000000..d68463ba
--- /dev/null
+++ b/Aetheris.Kernel.Firmament/Materializer/ResolvedProfile2D.cs
@@ -0,0 +1,49 @@
+namespace Aetheris.Kernel.Firmament.Materializer;
+
+/// <summary>Immutable, resolved material boundary. It is neither a sketch nor a constraint solver.</summary>
+public sealed record ProfileSegmentProvenance(string StableId, string ConceptStableId, string SourceSpan, string Derivation, string SourceFrame);
+public sealed record ResolvedProfileSegment2D(string Name, LineArcProfileCurve2D Geometry, ProfileSegmentProvenance Provenance);
+public sealed record ResolvedProfileLoop2D(string Name, bool IsOuter, IReadOnlyList<ResolvedProfileSegment2D> Segments);
+public sealed record ResolvedProfile2D(string Name, string PlaneFrame, IReadOnlyList<ResolvedProfileLoop2D> Loops);
+public sealed record ResolvedProfileValidationResult(bool IsValid, double SignedArea, IReadOnlyList<string> Diagnostics);
+
+public static class ResolvedProfile2DValidator
+{
+ private const double Tol = 1e-7;
+ public static ResolvedProfileValidationResult Validate(ResolvedProfile2D profile)
+ {
+ var d = new List<string>();
+ if (profile.Loops.Count != 1 || !profile.Loops[0].IsOuter) d.Add($"profile:{profile.Name}: exactly one declared outer loop is required");
+ var loop = profile.Loops.SingleOrDefault();
+ if (loop is null || loop.Segments.Count < 3) return new(false, 0, d.Append($"profile:{profile.Name}: outer loop requires at least three segments").ToArray());
+ var names = new HashSet<string>(StringComparer.Ordinal);
+ for (var i=0;i<loop.Segments.Count;i++)
+ {
+ var s=loop.Segments[i]; if(!names.Add(s.Name))d.Add($"profile:{profile.Name}: duplicate segment '{s.Name}'");
+ if(!Endpoints(s.Geometry,out var start,out var end)){d.Add($"profile:{profile.Name}: unsupported unbounded segment '{s.Name}'");continue;}
+ if(Distance(start,end)<=Tol)d.Add($"profile:{profile.Name}: zero-length segment '{s.Name}'");
+ var next=loop.Segments[(i+1)%loop.Segments.Count]; if(Endpoints(next.Geometry,out var ns,out _)&&Distance(end,ns)>Tol)d.Add($"profile:{profile.Name}: endpoint mismatch '{s.Name}' -> '{next.Name}'");
+ }
+ for (var i=0;i<loop.Segments.Count;i++) for (var j=i+1;j<loop.Segments.Count;j++)
+ {
+ var a=loop.Segments[i]; var b=loop.Segments[j];
+ if (SameLine(a.Geometry,b.Geometry)) d.Add($"profile:{profile.Name}: duplicate coincident segment '{a.Name}' / '{b.Name}'");
+ if (!Adjacent(i,j,loop.Segments.Count) && a.Geometry is LineArcLineSegment2D && b.Geometry is LineArcLineSegment2D && Endpoints(a.Geometry,out var as_,out var ae) && Endpoints(b.Geometry,out var bs,out var be) && ProperIntersection(as_,ae,bs,be)) d.Add($"profile:{profile.Name}: self-intersection '{a.Name}' / '{b.Name}'");
+ }
+ var area=loop.Segments.Sum(s=>Endpoints(s.Geometry,out var a,out var b)?a.X*b.Y-b.X*a.Y:0)/2d;
+ if(area<=Tol)d.Add($"profile:{profile.Name}: outer winding must be CounterClockwise with nonzero area");
+ return new(d.Count==0,area,d);
+ }
+ public static LineArcProfileExtrudeResult Extrude(ResolvedProfile2D profile,double height)
+ {
+ var validation=Validate(profile); if(!validation.IsValid)return new(LineArcProfileExtrudeStatus.Rejected,null,validation.Diagnostics);
+ return LineArcProfileExtrudeEmitter.TryEmit(new(profile.Loops.Select(l=>new LineArcProfileLoop2D(l.Segments.Select(s=>s.Geometry).ToArray(),!l.IsOuter)).ToArray(),height));
+ }
+ private static bool Endpoints(LineArcProfileCurve2D c,out (double X,double Y) a,out (double X,double Y) b){switch(c){case LineArcLineSegment2D l:a=l.Start;b=l.End;return true;case LineArcCircularArc2D x:a=(x.Center.X+x.Radius*Math.Cos(x.StartAngleRadians),x.Center.Y+x.Radius*Math.Sin(x.StartAngleRadians));b=(x.Center.X+x.Radius*Math.Cos(x.StartAngleRadians+x.SweepAngleRadians),x.Center.Y+x.Radius*Math.Sin(x.StartAngleRadians+x.SweepAngleRadians));return true;default:a=default;b=default;return false;}}
+ private static double Distance((double X,double Y)a,(double X,double Y)b)=>Math.Sqrt((a.X-b.X)*(a.X-b.X)+(a.Y-b.Y)*(a.Y-b.Y));
+ private static bool Adjacent(int i,int j,int count)=>j==i+1 || (i==0 && j==count-1);
+ private static bool SameLine(LineArcProfileCurve2D a,LineArcProfileCurve2D b)=>a is LineArcLineSegment2D x&&b is LineArcLineSegment2D y&&((Distance(x.Start,y.Start)<=Tol&&Distance(x.End,y.End)<=Tol)||(Distance(x.Start,y.End)<=Tol&&Distance(x.End,y.Start)<=Tol));
+ private static bool ProperIntersection((double X,double Y)a,(double X,double Y)b,(double X,double Y)c,(double X,double Y)d)
+ { var ab1=Orientation(a,b,c);var ab2=Orientation(a,b,d);var cd1=Orientation(c,d,a);var cd2=Orientation(c,d,b);return ab1*ab2 < -Tol && cd1*cd2 < -Tol; }
+ private static double Orientation((double X,double Y)a,(double X,double Y)b,(double X,double Y)c)=>(b.X-a.X)*(c.Y-a.Y)-(b.Y-a.Y)*(c.X-a.X);
+}
diff --git a/docs/v2-v4-line-arc-profile-extrude-production-evaluation.md b/docs/v2-v4-line-arc-profile-extrude-production-evaluation.md
index d0f1517a..4ac9e747 100644
--- a/docs/v2-v4-line-arc-profile-extrude-production-evaluation.md
+++ b/docs/v2-v4-line-arc-profile-extrude-production-evaluation.md
@@ -29,6 +29,16 @@ Introduces internal `LineArcProfileExtrudeEmitter` as a production-adjacent emit
- `BREP_WITH_VOIDS` is not used in covered cases.
- Diagnostic includes explicit `v2-v4-no-3d-boolean-used`.
+### Topology stitching repair
+
+The emitter now reuses the top and bottom vertex pair and vertical edge at every
+coincident resolved profile endpoint. A four-segment rectangle therefore has
+eight cap vertices and twelve edges, rather than independent vertices for each
+curve occurrence. This is a necessary prerequisite for a future authoritative
+named-profile route: adjacency is represented by topology, not merely by equal
+coordinates. It does not itself add parser syntax, Profile IR provenance, or a
+production route claim.
+
## Invalid/deferred behavior
Current implementation rejects invalid height, unsupported topology (not exactly one outer), and basic invalid curve dimensions before emission.
diff --git a/fixtures/FirmamentV2/Profile/valid/scaffold-rectangle.firmament b/fixtures/FirmamentV2/Profile/valid/scaffold-rectangle.firmament
new file mode 100644
index 00000000..532c4813
--- /dev/null
+++ b/fixtures/FirmamentV2/Profile/valid/scaffold-rectangle.firmament
@@ -0,0 +1,23 @@
+Concept Struct RectangleLayout On XY {
+ Point2 SouthWest { Position: [-10mm, -5mm] }
+ Point2 SouthEast { Position: [10mm, -5mm] }
+ Point2 NorthEast { Position: [10mm, 5mm] }
+ Point2 NorthWest { Position: [-10mm, 5mm] }
+ Line2 South { From: SouthWest; To: SouthEast }
+ Line2 East { From: SouthEast; To: NorthEast }
+ Line2 North { From: NorthEast; To: NorthWest }
+ Line2 West { From: NorthWest; To: SouthWest }
+}
+
+Profile MainPlate Using RectangleLayout {
+ Loop Outer {
+ Segment SouthEdge { Trace: South; From: SouthWest; To: SouthEast }
+ Segment EastEdge { Trace: East; From: SouthEast; To: NorthEast }
+ Segment NorthEdge { Trace: North; From: NorthEast; To: NorthWest }
+ Segment WestEdge { Trace: West; From: NorthWest; To: SouthWest }
+ }
+}
+
+Struct Plate {
+ Extrude MainPlate { Profile: MainPlate; From: -2mm; To: 0mm }
+}