Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using Aetheris.Geometry;
using Aetheris.Kernel.Core.Math;
using Aetheris.Surfacing;
var output=Path.GetFullPath(Path.Combine(AppContext.BaseDirectory,"..","..","..","..","..","artifacts", "local", "evidence", "geometry","reasoning-m3"));Directory.CreateDirectory(output);
var json=new JsonSerializerOptions{WriteIndented=true};json.Converters.Add(new JsonStringEnumConverter());
var a=Line("a",new(0,0,0),new(10,0,0));var noise=Line("noise",new(0,0,5e-7),new(10,0,5e-7));
var loose=ClosestPointQuery.Between(a,noise);var tight=ClosestPointQuery.Between(a,noise,new(){LinearTolerance=1e-8});
Write("floating-point-and-tolerance.json",new{rule="Raw distance is never rounded to zero and numerical proximity never earns Coincident.",loose,tight});
var same=Line("a",new(10,0,0),new(0,0,0));Write("structural-coincidence.json",ClosestPointQuery.Between(a,same));
var saddle=Patch("saddle",(u,v)=>new(u,v,u*u-v*v));var plane=Patch("plane",(u,v)=>new(u,v,0));var plane3=Patch("plane-3",(u,v)=>new(u,v,3));
var parabola=Curve("parabola",t=>new(t,t*t,2));var parabola4=Curve("parabola-4",t=>new(t,t*t,4));
Write("pair-family-evidence.json",new{
pointCurve=ClosestPointQuery.Between(new Point3D(12,3,0),a),
pointPatch=ClosestPointQuery.Between(new Point3D(0,0,2),saddle),
curveCurve=ClosestPointQuery.Between(parabola,parabola4),
curvePatch=ClosestPointQuery.Between(parabola,plane),
patchPatch=ClosestPointQuery.Between(plane,plane3)});
var panel=RuledCanopyPanelTemplate.Create("clearance-panel",10,4,0).Panel!;
Write("cad-panel-clearance.json",new{panel=panel.StableId,edgeA=panel["South"].StableId,edgeB=panel["North"].StableId,result=ClosestPointQuery.Between(panel["South"].AuthoredCurve,panel["North"].AuthoredCurve),signedSideComposition="SignedSide remains the separate side classifier; distance adds unsigned minimum clearance."});
Write("architecture-and-audit.json",new{
ownership="Aetheris.Geometry",policy=DistanceQueryPolicy.Default,
inventory=new[]{"Kernel.Core: B-rep picking, planar domain, STEP conic recovery, primitive spatial queries","Continuum: optimized support projection and sampled boundary-offset maps","Surfacing: public bounded Panel edge curves"},
intentionallyUnchanged="Specialized internal projection/maps remain in place; M3 adds shared semantics without repository-wide refactoring.",
algorithms=new{analytic=new[]{"point-line-segment","segment-segment"},generic="two deterministic whole-domain lattice resolutions plus bounded coordinate refinement",unknown="non-finite evaluation or failure to stabilize under budget"},
topologyBoundary="No intersection topology, contact order, collision response, or motion is authored."});
const int count=100;for(var i=0;i<5;i++)ClosestPointQuery.Between(plane,plane3);var watch=Stopwatch.StartNew();for(var i=0;i<count;i++)ClosestPointQuery.Between(plane,plane3);watch.Stop();
Write("performance.json",new{operation="patch-patch default policy",iterations=count,elapsedMilliseconds=watch.Elapsed.TotalMilliseconds,nanosecondsPerQuery=watch.Elapsed.TotalNanoseconds/count,candidatesPerQuery=ClosestPointQuery.Between(plane,plane3).Statistics.CandidateCount});
Write("validation.json",new{milestone="AETHERIS-GEOMETRY-REASONING-M3",restore="passed",build=new{status="passed",warnings=0,errors=0},tests=new{status="passed",fullSolutionPassed=2731,postFinalGeometryPassed=35,failed=0,projectsWithTests=12,frictionLabDiscoverableTests=0},cli="dotnet run --project Aetheris.CLI -- --help passed",gitDiffCheck="passed"});
var files=Directory.GetFiles(output,"*.json").Where(path=>Path.GetFileName(path) is not "deterministic-hashes.json" and not "performance.json").Order(StringComparer.Ordinal).Select(path=>new{file=Path.GetFileName(path),sha256=Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(path))).ToLowerInvariant()}).ToArray();Write("deterministic-hashes.json",new{algorithm="SHA-256",excluded=new[]{"performance.json (wall-clock measurement)"},files});
Console.WriteLine(JsonSerializer.Serialize(new{output,files},json));
void Write(string name,object value)=>File.WriteAllText(Path.Combine(output,name),JsonSerializer.Serialize(value,json)+Environment.NewLine,new UTF8Encoding(false));
BoundedParametricCurve3 Line(string id,Point3D p,Point3D q)=>BoundedParametricCurve3.LineSegment(id,p,q,"M3 evidence");
BoundedParametricCurve3 Curve(string id,Func<double,Point3D> f)=>BoundedParametricCurve3.Procedural(id,new(-1,1),t=>(f(t),new Vector3D(1,2*t,0)),"M3 evidence");
BoundedParametricPatch3 Patch(string id,Func<double,double,Point3D> f)=>BoundedParametricPatch3.Procedural(id,new(new(-1,1),new(-1,1)),(u,v)=>new(f(u,v),new(1,0,2*u),new(0,1,-2*v),null,false),"M3 evidence");