Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Hollow: retire the bespoke primitive builders; Revolve<Hollow>

Claudeaca44ac3bb2c
diff --git a/Aetheris.Kernel.Core.Tests/Brep/MeridianHollowTests.cs b/Aetheris.Kernel.Core.Tests/Brep/MeridianHollowTests.cs
new file mode 100644
index 00000000..a8bedf3f
--- /dev/null
+++ b/Aetheris.Kernel.Core.Tests/Brep/MeridianHollowTests.cs
@@ -0,0 +1,66 @@
+using Aetheris.Kernel.Core.Brep;
+using Aetheris.Kernel.Core.Brep.Features;
+using Aetheris.Kernel.Core.Brep.Verification;
+using Aetheris.Kernel.Core.Geometry.Planar;
+using Aetheris.Kernel.Core.Step242;
+
+namespace Aetheris.Kernel.Core.Tests.Brep;
+
+public sealed class MeridianHollowTests
+{
+ private static PlanarLine L(double r0, double z0, double r1, double z1) => new((r0, z0), (r1, z1));
+ private static PlanarSpan[] Cylinder(double r, double h) => [L(0, 0, r, 0), L(r, 0, r, h), L(r, h, 0, h), L(0, h, 0, 0)];
+
+ [Theory]
+ [InlineData(true, false)]
+ [InlineData(false, true)]
+ [InlineData(true, true)]
+ public void CylinderWallsAreExactAtEveryOpening(bool top, bool bottom)
+ {
+ const double r = 20, h = 50, t = 2;
+ var wall = MeridianHollow.Wall(Cylinder(r, h), t, top, bottom);
+ Assert.True(wall.IsSuccess, string.Join("; ", wall.Diagnostics.Select(d => d.Message)));
+ var shell = BrepRevolvedShell.Build(wall.Value, RevolutionFrame.WorldZ);
+ Assert.True(shell.IsSuccess, string.Join("; ", shell.Diagnostics.Select(d => d.Message)));
+ var closedCaps = (top ? 0 : 1) + (bottom ? 0 : 1);
+ var expected = double.Pi * (r * r * h - (r - t) * (r - t) * (h - closedCaps * t));
+ AssertSolid(shell.Value.Body, expected);
+ // Outer wall, inner wall, one rim per opening, two faces per closed end.
+ Assert.Equal(2 + (top ? 1 : 2) + (bottom ? 1 : 2), shell.Value.Body.Topology.Faces.Count());
+ }
+
+ [Fact]
+ public void BlendedBottomBecomesConcentricTori()
+ {
+ PlanarSpan[] cup = [L(0, 0, 12, 0), new PlanarArc((12, 8), 8, -double.Pi / 2, double.Pi / 2), L(20, 8, 20, 40), L(20, 40, 0, 40), L(0, 40, 0, 0)];
+ var wall = MeridianHollow.Wall(cup, 2, openTop: true, openBottom: false);
+ Assert.True(wall.IsSuccess);
+ var arcs = wall.Value.OfType<PlanarArc>().OrderByDescending(a => a.Radius).ToArray();
+ Assert.Equal([8d, 6d], arcs.Select(a => a.Radius));
+ Assert.All(arcs, arc => Assert.Equal((12d, 8d), arc.Center));
+ var shell = BrepRevolvedShell.Build(wall.Value, RevolutionFrame.WorldZ);
+ Assert.True(shell.IsSuccess);
+ Assert.Equal(2, shell.Value.Body.Geometry.Surfaces.Count(s => s.Value.Kind == Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Torus));
+ }
+
+ [Fact]
+ public void ClosedVesselsAndApexesAreRefused()
+ {
+ Assert.Contains(MeridianHollow.Wall(Cylinder(20, 50), 2, false, false).Diagnostics, d => d.Message.StartsWith("hollow-closed-vessel-unsupported", StringComparison.Ordinal));
+ var cone = MeridianHollow.Wall([L(0, 0, 30, 40), L(30, 40, 0, 40), L(0, 40, 0, 0)], 1.5, true, false);
+ Assert.True(cone.IsSuccess);
+ Assert.Contains(BrepRevolvedShell.Build(cone.Value, RevolutionFrame.WorldZ).Diagnostics, d => d.Message.StartsWith("revolve-shell-apex-unsupported", StringComparison.Ordinal));
+ }
+
+ private static void AssertSolid(BrepBody body, double expectedVolume)
+ {
+ var step = Step242Exporter.ExportBody(body);
+ Assert.True(step.IsSuccess);
+ var imported = Step242Importer.ImportBody(step.Value);
+ Assert.True(imported.IsSuccess);
+ var enclosure = BrepMassProperties.EvaluateEnclosure(imported.Value);
+ Assert.True(enclosure.IsEnclosed && enclosure.IsOrientationConsistent, string.Join(" | ", enclosure.Diagnostics));
+ var volume = BrepMassProperties.Evaluate(imported.Value, new(0.01d, double.Pi / 180d, 1d, MaximumSegments: 512)).AbsoluteVolume;
+ Assert.InRange(volume, expectedVolume * (1 - 1e-3), expectedVolume * (1 + 1e-3));
+ }
+}
diff --git a/Aetheris.Kernel.Core.Tests/ThinWalledBodyBRepPlanTests.cs b/Aetheris.Kernel.Core.Tests/ThinWalledBodyBRepPlanTests.cs
index 34e29cd9..f396dbeb 100644
--- a/Aetheris.Kernel.Core.Tests/ThinWalledBodyBRepPlanTests.cs
+++ b/Aetheris.Kernel.Core.Tests/ThinWalledBodyBRepPlanTests.cs
@@ -6,23 +6,6 @@ namespace Aetheris.Kernel.Core.Tests;
public sealed class ThinWalledBodyBRepPlanTests
{
- [Fact]
- public void RoundedBoxHollow_UsesOneAuthoritativePairedBoundaryPlan()
- {
- var result = ThinWalledBodyBRepPlanner.CreateRoundedBox(120, 80, 24, 12, 2);
- Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics.Select(x => x.Message)));
- var value = result.Value;
- Assert.True(value.Plan.IsAuthoritative);
- Assert.Equal("ThinWalledBody", value.Plan.Kind);
- Assert.Equal("InsetRoundedProfile", value.Feature.Witness.Kind);
- Assert.Equal(26, value.Body.Topology.Faces.Count());
- Assert.Equal(8, value.Body.Geometry.Surfaces.Count(x => x.Value.Kind == SurfaceGeometryKind.Cylinder));
- Assert.Null(value.Body.SafeBooleanComposition);
- var step = Step242Exporter.ExportBody(value.Body, new Step242ExportOptions { BrepExportPreflightMode = BrepExportPreflightMode.Enforce });
- Assert.True(step.IsSuccess, string.Join(", ", step.Diagnostics.Select(x => x.Message)));
- Assert.True(Step242Importer.ImportBody(step.Value).IsSuccess);
- }
-
[Fact]
public void FrustumHollow_UsesParallelConicalOffsetRatherThanRadialShrink()
{
@@ -59,10 +42,4 @@ public sealed class ThinWalledBodyBRepPlanTests
[InlineData(56, 0.8, 0.8)]
public void CylinderHollow_RejectsCollapsedInnerBoundary(double radius, double height, double thickness)
=> Assert.False(ThinWalledBodyBRepPlanner.CreateCylinder(radius, height, thickness).IsSuccess);
-
- [Theory]
- [InlineData(120, 80, 24, 12)]
- [InlineData(120, 80, 2, 2)]
- public void RoundedBoxHollow_RejectsCollapsedInnerBoundary(double width, double depth, double height, double thickness)
- => Assert.False(ThinWalledBodyBRepPlanner.CreateRoundedBox(width, depth, height, 12, thickness).IsSuccess);
}
diff --git a/Aetheris.Kernel.Core/Brep/Features/BrepRevolvedShell.cs b/Aetheris.Kernel.Core/Brep/Features/BrepRevolvedShell.cs
new file mode 100644
index 00000000..e33d3344
--- /dev/null
+++ b/Aetheris.Kernel.Core/Brep/Features/BrepRevolvedShell.cs
@@ -0,0 +1,176 @@
+using Aetheris.Kernel.Core.Diagnostics;
+using Aetheris.Kernel.Core.Geometry;
+using Aetheris.Kernel.Core.Geometry.Curves;
+using Aetheris.Kernel.Core.Geometry.Planar;
+using Aetheris.Kernel.Core.Geometry.Surfaces;
+using Aetheris.Kernel.Core.Math;
+using Aetheris.Kernel.Core.Results;
+using Aetheris.Kernel.Core.Topology;
+
+namespace Aetheris.Kernel.Core.Brep.Features;
+
+/// <summary>The axis a meridian turns about: meridian x is the radius along <see cref="Radial"/>, y the position along <see cref="Axis"/>.</summary>
+public sealed record RevolutionFrame(Point3D Origin, Direction3D Axis, Direction3D Radial)
+{
+ public static RevolutionFrame WorldZ { get; } = new(Point3D.Origin, Direction3D.Create(new Vector3D(0, 0, 1)), Direction3D.Create(new Vector3D(1, 0, 0)));
+}
+
+/// <summary>The face a meridian span became, by its index in the loop.</summary>
+public sealed record BrepRevolvedShellResult(BrepBody Body, IReadOnlyDictionary<int, FaceId> SpanFaces);
+
+/// <summary>
+/// A full turn of one closed line/arc meridian loop. Each span becomes one face of revolution, bounded by the full
+/// circles its endpoints sweep: a radial line a planar disk or annulus, an axial line a cylinder, a sloped line a
+/// cone, an arc a torus (or a sphere when centred on the axis). Spans lying on the axis make no face. Only a radial
+/// span may meet the axis, so no face has an apex or pole. No seam edges are needed: every face is bounded by circles.
+/// </summary>
+public static class BrepRevolvedShell
+{
+ private const double Tol = 1e-9;
+
+ public static KernelResult<BrepRevolvedShellResult> Build(IReadOnlyList<PlanarSpan> meridian, RevolutionFrame frame)
+ {
+ if (meridian.Count < 2 || meridian.Any(s => s is not (PlanarLine or PlanarArc)))
+ return Failure("revolve-shell-meridian-invalid", "A revolved shell needs a closed loop of at least two lines and arcs.");
+ var loop = LineArcInset.SignedArea(meridian) > 0d ? meridian : LineArcInset.Reverse(meridian);
+ var points = loop.Select(LineArcInset.StartPoint).ToArray();
+ for (var i = 0; i < loop.Count; i++)
+ {
+ var end = LineArcInset.EndPoint(loop[i]);
+ var next = points[(i + 1) % loop.Count];
+ if (double.Hypot(end.X - next.X, end.Y - next.Y) > 1e-7)
+ return Failure("revolve-shell-meridian-open", $"Meridian span {i} does not end where span {(i + 1) % loop.Count} starts.");
+ }
+ if (points.Any(p => p.X < -Tol)) return Failure("revolve-shell-crosses-axis", "The meridian crosses the axis.");
+
+ var axis = frame.Axis.ToVector();
+ var radial = frame.Radial.ToVector();
+ // Adding +0 clears negative zeros, so points match those built from literal coordinates.
+ Point3D At(double r, double z) { var p = frame.Origin + axis * z + radial * r; return new Point3D(p.X + 0d, p.Y + 0d, p.Z + 0d); }
+ Direction3D Along(double sign) { var v = axis * sign; return Direction3D.Create(new Vector3D(v.X + 0d, v.Y + 0d, v.Z + 0d)); }
+ bool OnAxis((double X, double Y) p) => double.Abs(p.X) <= 1e-7;
+
+ var builder = new TopologyBuilder();
+ var geometry = new BrepGeometryStore();
+ var bindings = new BrepBindingModel();
+ var vertexPoints = new Dictionary<VertexId, Point3D>();
+ var circles = new EdgeId?[loop.Count];
+ var nextCurve = 1;
+ var nextSurface = 1;
+ for (var i = 0; i < loop.Count; i++)
+ {
+ if (OnAxis(points[i])) continue;
+ var vertex = builder.AddVertex();
+ vertexPoints[vertex] = At(points[i].X, points[i].Y);
+ var edge = builder.AddEdge(vertex, vertex);
+ var curveId = new CurveGeometryId(nextCurve++);
+ geometry.AddCurve(curveId, CurveGeometry.FromCircle(new Circle3Curve(frame.Origin + axis * points[i].Y, frame.Axis, points[i].X, frame.Radial)));
+ bindings.AddEdgeBinding(new EdgeGeometryBinding(edge, curveId, new ParameterInterval(0d, 2d * double.Pi)));
+ circles[i] = edge;
+ }
+
+ var faces = new List<FaceId>();
+ var spanFaces = new Dictionary<int, FaceId>();
+ for (var i = 0; i < loop.Count; i++)
+ {
+ var p = points[i];
+ var q = points[(i + 1) % loop.Count];
+ if (OnAxis(p) && OnAxis(q) && loop[i] is PlanarLine) continue;
+ // Outward in the meridian is right of travel for a counter-clockwise loop.
+ var (dr, dz) = MidTangent(loop[i]);
+ var (nr, nz) = (dz, -dr);
+ SurfaceGeometry surface;
+ bool sameSense;
+ switch (loop[i])
+ {
+ case PlanarLine when double.Abs(q.Y - p.Y) <= Tol:
+ surface = SurfaceGeometry.FromPlane(new PlaneSurface(At(0, p.Y), Along(double.Sign(nz)), frame.Radial));
+ sameSense = true;
+ break;
+ case PlanarLine when OnAxis(p) || OnAxis(q):
+ return Failure("revolve-shell-apex-unsupported", $"Meridian span {i} meets the axis at a point; only a flat (radial) span may meet the axis.");
+ case PlanarLine when double.Abs(q.X - p.X) <= Tol:
+ surface = SurfaceGeometry.FromCylinder(new CylinderSurface(At(0, p.Y), frame.Axis, p.X, frame.Radial));
+ sameSense = nr > 0d;
+ break;
+ case PlanarLine:
+ {
+ var k = (q.X - p.X) / (q.Y - p.Y);
+ var apexZ = p.Y - p.X / k;
+ var coneAxis = Along(double.Sign(k));
+ var cone = new ConeSurface(At(0, apexZ), coneAxis, double.Atan(double.Abs(k)), frame.Radial);
+ surface = SurfaceGeometry.FromCone(cone);
+ sameSense = cone.Normal(0d).ToVector().Dot(radial * nr + axis * nz) > 0d;
+ break;
+ }
+ case PlanarArc arc when OnAxis(p) || OnAxis(q):
+ return Failure("revolve-shell-pole-unsupported", $"Meridian arc {i} meets the axis; only a flat (radial) span may meet the axis.");
+ case PlanarArc arc when double.Abs(arc.Center.X) > 1e-7 && arc.Center.X <= arc.Radius + Tol:
+ return Failure("revolve-shell-spindle-unsupported", $"Meridian arc {i} is centred closer to the axis than its radius.");
+ case PlanarArc arc:
+ {
+ var mid = arc.StartAngle + arc.Sweep / 2d;
+ var (mr, mz) = (double.Cos(mid), double.Sin(mid));
+ // A sphere's or torus' own normal points away from the arc's centre.
+ sameSense = mr * nr + mz * nz > 0d;
+ surface = double.Abs(arc.Center.X) <= 1e-7
+ ? SurfaceGeometry.FromSphere(new SphereSurface(At(0, arc.Center.Y), frame.Axis, arc.Radius, frame.Radial))
+ : SurfaceGeometry.FromTorus(new TorusSurface(At(0, arc.Center.Y), frame.Axis, arc.Center.X, arc.Radius, frame.Radial));
+ break;
+ }
+ default:
+ return Failure("revolve-shell-meridian-invalid", $"Meridian span {i} is not a line or arc.");
+ }
+ // The circle at the span's start bounds the face counter-clockwise about its outward normal, the circle at
+ // its end clockwise. The stored sense is relative to the surface's own normal.
+ var loops = new List<LoopId>();
+ void AddLoop(EdgeId edge, bool reversedAboutOutward)
+ {
+ var loopId = builder.AllocateLoopId();
+ var coedge = builder.AllocateCoedgeId();
+ builder.AddCoedge(new Coedge(coedge, edge, loopId, coedge, coedge, reversedAboutOutward ^ !sameSense));
+ builder.AddLoop(new Loop(loopId, [coedge]));
+ loops.Add(loopId);
+ }
+ if (circles[i] is { } startCircle) AddLoop(startCircle, false);
+ if (circles[(i + 1) % loop.Count] is { } endCircle) AddLoop(endCircle, true);
+ if (loops.Count == 0) return Failure("revolve-shell-meridian-invalid", $"Meridian span {i} sweeps no area.");
+ var face = builder.AddFace(loops);
+ var surfaceId = new SurfaceGeometryId(nextSurface++);
+ geometry.AddSurface(surfaceId, surface);
+ bindings.AddFaceBinding(new FaceGeometryBinding(face, surfaceId, sameSense));
+ faces.Add(face);
+ spanFaces[i] = face;
+ }
+ var shell = builder.AddShell(faces);
+ builder.AddBody([shell]);
+ var body = new BrepBody(builder.Model, geometry, bindings, vertexPoints);
+ var preflight = BrepExportPreflight.Validate(body);
+ if (!preflight.IsValid)
+ return Failure("revolve-shell-preflight", string.Join("; ", preflight.Diagnostics.Where(d => d.Severity == BrepExportPreflightSeverity.Error).Take(6).Select(d => d.Code + ": " + d.Message)));
+ return KernelResult<BrepRevolvedShellResult>.Success(new(body, spanFaces));
+ }
+
+ private static (double R, double Z) MidTangent(PlanarSpan span)
+ {
+ switch (span)
+ {
+ case PlanarLine line:
+ {
+ var (dx, dy) = (line.End.X - line.Start.X, line.End.Y - line.Start.Y);
+ var l = double.Hypot(dx, dy);
+ return (dx / l, dy / l);
+ }
+ case PlanarArc arc:
+ {
+ var mid = arc.StartAngle + arc.Sweep / 2d;
+ var s = double.Sign(arc.Sweep);
+ return (-double.Sin(mid) * s, double.Cos(mid) * s);
+ }
+ default: throw new NotSupportedException();
+ }
+ }
+
+ private static KernelResult<BrepRevolvedShellResult> Failure(string code, string message) =>
+ KernelResult<BrepRevolvedShellResult>.Failure([new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, $"{code}: {message}", "BrepRevolvedShell")]);
+}
diff --git a/Aetheris.Kernel.Core/Brep/Features/MeridianHollow.cs b/Aetheris.Kernel.Core/Brep/Features/MeridianHollow.cs
new file mode 100644
index 00000000..42133cb5
--- /dev/null
+++ b/Aetheris.Kernel.Core/Brep/Features/MeridianHollow.cs
@@ -0,0 +1,210 @@
+using Aetheris.Kernel.Core.Diagnostics;
+using Aetheris.Kernel.Core.Geometry.Planar;
+using Aetheris.Kernel.Core.Results;
+
+namespace Aetheris.Kernel.Core.Brep.Features;
+
+/// <summary>
+/// The wall meridian of a hollow solid of revolution. A surface of revolution's normal lies in its meridian plane, so
+/// the 3D offset of the solid is the revolution of the 2D offset of its full axial section. The section is the
+/// meridian and its mirror across the axis; its exact inset (<see cref="LineArcInset"/>) is the cavity, which is cut
+/// back to the meridian half-plane. An open end cap is pushed outward before the inset, so the cavity runs through it,
+/// and the cavity is then cut at the cap's plane. The wall is the meridian less the cavity.
+/// </summary>
+public static class MeridianHollow
+{
+ private const double Tol = 1e-7;
+
+ /// <summary>
+ /// <paramref name="exterior"/> is a closed meridian (x = radius ≥ 0, y = axial position) with one span on the axis,
+ /// whose ends are flat caps where they are opened.
+ /// </summary>
+ public static KernelResult<IReadOnlyList<PlanarSpan>> Wall(IReadOnlyList<PlanarSpan> exterior, double wallThickness, bool openTop, bool openBottom)
+ {
+ var t = wallThickness;
+ if (!(t > 0d) || !double.IsFinite(t)) return Failure("hollow-wall-thickness-must-be-positive", "The wall must be positive.");
+ if (!openTop && !openBottom)
+ return Failure("hollow-closed-vessel-unsupported", "A closed hollow needs an inner void shell, which is not built yet; open Top or Bottom.");
+ var loop = LineArcInset.SignedArea(exterior) > 0d ? exterior.ToList() : LineArcInset.Reverse(exterior).ToList();
+ var axisSpans = Enumerable.Range(0, loop.Count).Where(i => loop[i] is PlanarLine line && OnAxis(line.Start) && OnAxis(line.End)).ToArray();
+ if (axisSpans.Length != 1)
+ return Failure("hollow-revolve-meridian-invalid", "The meridian must close along the axis with exactly one span.");
+ if (loop.Any(s => LineArcInset.StartPoint(s).X < -Tol))
+ return Failure("hollow-revolve-meridian-invalid", "The meridian crosses the axis.");
+ // Rotate so the chain runs from the bottom of the axis span, away from the axis, back to its top.
+ var chain = loop.Skip(axisSpans[0] + 1).Concat(loop.Take(axisSpans[0])).ToList();
+ var bottomZ = LineArcInset.StartPoint(chain[0]).Y;
+ var topZ = LineArcInset.EndPoint(chain[^1]).Y;
+ var allZ = chain.SelectMany(s => new[] { LineArcInset.StartPoint(s).Y, LineArcInset.EndPoint(s).Y }).ToArray();
+
+ var extended = chain.ToList();
+ var reach = 2d * t;
+ if (openTop)
+ {
+ if (!IsCap(chain[^1]) || allZ.Max() > topZ + Tol || chain.Count < 2 || chain[^2] is not PlanarLine side || side.End.Y - side.Start.Y <= Tol)
+ return Failure("hollow-opening-needs-flat-cap", "An open top must be a flat cap at the highest point, reached by a straight wall rising to it.");
+ var end = Along(side, topZ + reach);
+ extended[^2] = new PlanarLine(side.Start, end);
+ extended[^1] = new PlanarLine(end, (0d, topZ + reach));
+ }
+ if (openBottom)
+ {
+ if (!IsCap(chain[0]) || allZ.Min() < bottomZ - Tol || chain.Count < 2 || extended[1] is not PlanarLine side || side.End.Y - side.Start.Y <= Tol)
+ return Failure("hollow-opening-needs-flat-cap", "An open bottom must be a flat cap at the lowest point, left by a straight wall rising from it.");
+ var start = Along(side, bottomZ - reach);
+ extended[1] = new PlanarLine(start, side.End);
+ extended[0] = new PlanarLine((0d, bottomZ - reach), start);
+ }
+
+ // The full axial section: the meridian and its mirror, closed without the axis.
+ var mirrored = LineArcInset.Reverse(extended.Select(Mirror).ToArray());
+ var section = extended.Concat(mirrored).ToArray();
+ var diagnostics = new List<string>();
+ var cavity = LineArcInset.InsetLoop(section, t, outer: true, "revolve", diagnostics);
+ if (cavity is null)
+ return Failure("hollow-wall-offset-collapse", string.Join("; ", diagnostics));
+ var clips = new HashSet<PlanarSpan>(ReferenceEqualityComparer.Instance);
+ IReadOnlyList<PlanarSpan>? half = cavity;
+ if (openTop) half = Clip(half, vertical: false, topZ, keepBelow: true, clips);
+ if (half is not null && openBottom) half = Clip(half, vertical: false, bottomZ, keepBelow: false, clips);
+ if (half is not null) half = Clip(half, vertical: true, 0d, keepBelow: false, clips);
+ if (half is null)
+ return Failure("hollow-wall-offset-collapse", "The cavity does not meet the axis and the openings in one piece each.");
+
+ var inner = half.Where(s => !clips.Contains(s) && !(s is PlanarLine l && OnAxis(l.Start) && OnAxis(l.End))).ToList();
+ var outer = chain.ToList();
+ if (openTop) outer.RemoveAt(outer.Count - 1);
+ if (openBottom) outer.RemoveAt(0);
+ var ordered = Chain(inner);
+ if (ordered is null) return Failure("hollow-wall-offset-collapse", "The cavity wall is not one chain.");
+ var wall = new List<PlanarSpan>(outer);
+ AddLine(wall, LineArcInset.EndPoint(outer[^1]), LineArcInset.EndPoint(ordered[^1]));
+ wall.AddRange(LineArcInset.Reverse(ordered));
+ AddLine(wall, LineArcInset.StartPoint(ordered[0]), LineArcInset.StartPoint(outer[0]));
+ return KernelResult<IReadOnlyList<PlanarSpan>>.Success(wall);
+ }
+
+ private static bool OnAxis((double X, double Y) p) => double.Abs(p.X) <= Tol;
+
+ private static bool IsCap(PlanarSpan span) => span is PlanarLine line && double.Abs(line.Start.Y - line.End.Y) <= Tol
+ && (OnAxis(line.Start) || OnAxis(line.End));
+
+ private static (double X, double Y) Along(PlanarLine line, double y)
+ {
+ var s = (y - line.Start.Y) / (line.End.Y - line.Start.Y);
+ return (line.Start.X + (line.End.X - line.Start.X) * s, y);
+ }
+
+ private static PlanarSpan Mirror(PlanarSpan span) => span switch
+ {
+ PlanarLine line => new PlanarLine((-line.Start.X, line.Start.Y), (-line.End.X, line.End.Y)),
+ PlanarArc arc => new PlanarArc((-arc.Center.X, arc.Center.Y), arc.Radius, double.Pi - arc.StartAngle, -arc.Sweep),
+ _ => throw new NotSupportedException()
+ };
+
+ private static void AddLine(List<PlanarSpan> spans, (double X, double Y) from, (double X, double Y) to)
+ {
+ if (double.Hypot(to.X - from.X, to.Y - from.Y) > Tol) spans.Add(new PlanarLine(from, to));
+ }
+
+ private static List<PlanarSpan>? Chain(List<PlanarSpan> spans)
+ {
+ if (spans.Count == 0) return null;
+ var starts = spans.Where(s => !spans.Any(o => !ReferenceEquals(o, s) && Close(LineArcInset.EndPoint(o), LineArcInset.StartPoint(s)))).ToArray();
+ if (starts.Length != 1) return null;
+ var ordered = new List<PlanarSpan> { starts[0] };
+ while (ordered.Count < spans.Count)
+ {
+ var end = LineArcInset.EndPoint(ordered[^1]);
+ var next = spans.FirstOrDefault(s => !ordered.Contains(s) && Close(LineArcInset.StartPoint(s), end));
+ if (next is null) return null;
+ ordered.Add(next);
+ }
+ return ordered;
+ }
+
+ private static bool Close((double X, double Y) a, (double X, double Y) b) => double.Hypot(a.X - b.X, a.Y - b.Y) <= 1e-6;
+
+ /// <summary>
+ /// Keeps the part of a closed loop on one side of a vertical (x = value) or horizontal (y = value) line, closing it
+ /// along the line. The loop must cross the line exactly twice, or not at all on the kept side.
+ /// </summary>
+ private static IReadOnlyList<PlanarSpan>? Clip(IReadOnlyList<PlanarSpan> loop, bool vertical, double value, bool keepBelow, HashSet<PlanarSpan> clips)
+ {
+ double Coordinate((double X, double Y) p) => vertical ? p.X : p.Y;
+ bool Kept((double X, double Y) p) => keepBelow ? Coordinate(p) < value : Coordinate(p) > value;
+ var pieces = new List<PlanarSpan>();
+ foreach (var span in loop)
+ {
+ var split = Split(span, vertical, value).ToArray();
+ // Pieces of an earlier closing segment are closing segments too.
+ if (clips.Contains(span)) foreach (var piece in split) clips.Add(piece);
+ pieces.AddRange(split);
+ }
+ var keep = pieces.Select(p => Kept(Mid(p))).ToArray();
+ if (keep.All(k => k)) return loop;
+ if (!keep.Any(k => k)) return null;
+ // Rotate so the kept run starts the list; one run means exactly two crossings.
+ var first = Enumerable.Range(0, pieces.Count).First(i => keep[i] && !keep[(i + pieces.Count - 1) % pieces.Count]);
+ var rotated = pieces.Skip(first).Concat(pieces.Take(first)).ToArray();
+ var kept = rotated.Zip(keep.Skip(first).Concat(keep.Take(first))).ToArray();
+ var run = kept.TakeWhile(p => p.Second).Select(p => p.First).ToList();
+ if (kept.Skip(run.Count).Any(p => p.Second)) return null;
+ var closing = new PlanarLine(LineArcInset.EndPoint(run[^1]), LineArcInset.StartPoint(run[0]));
+ clips.Add(closing);
+ run.Add(closing);
+ return run;
+ }
+
+ private static (double X, double Y) Mid(PlanarSpan span) => span switch
+ {
+ PlanarLine line => ((line.Start.X + line.End.X) / 2d, (line.Start.Y + line.End.Y) / 2d),
+ PlanarArc arc => (arc.Center.X + arc.Radius * double.Cos(arc.StartAngle + arc.Sweep / 2d), arc.Center.Y + arc.Radius * double.Sin(arc.StartAngle + arc.Sweep / 2d)),
+ _ => throw new NotSupportedException()
+ };
+
+ private static IEnumerable<PlanarSpan> Split(PlanarSpan span, bool vertical, double value)
+ {
+ switch (span)
+ {
+ case PlanarLine line:
+ {
+ var a = vertical ? line.Start.X : line.Start.Y;
+ var b = vertical ? line.End.X : line.End.Y;
+ if ((a - value) * (b - value) < 0d && double.Abs(a - value) > Tol && double.Abs(b - value) > Tol)
+ {
+ var s = (value - a) / (b - a);
+ var p = (line.Start.X + (line.End.X - line.Start.X) * s, line.Start.Y + (line.End.Y - line.Start.Y) * s);
+ yield return new PlanarLine(line.Start, p);
+ yield return new PlanarLine(p, line.End);
+ }
+ else yield return line;
+ break;
+ }
+ case PlanarArc arc:
+ {
+ var c = vertical ? arc.Center.X : arc.Center.Y;
+ var ratio = (value - c) / arc.Radius;
+ var cuts = new List<double>();
+ if (double.Abs(ratio) < 1d)
+ {
+ var basis = vertical ? double.Acos(ratio) : double.Asin(ratio);
+ var candidates = vertical ? new[] { basis, -basis } : new[] { basis, double.Pi - basis };
+ foreach (var angle in candidates)
+ for (var k = -2; k <= 2; k++)
+ {
+ var offset = (angle + 2d * double.Pi * k - arc.StartAngle) / arc.Sweep;
+ if (offset > 1e-9 && offset < 1d - 1e-9) cuts.Add(offset);
+ }
+ }
+ var bounds = cuts.Distinct().Order().Prepend(0d).Append(1d).ToArray();
+ for (var i = 0; i + 1 < bounds.Length; i++)
+ yield return new PlanarArc(arc.Center, arc.Radius, arc.StartAngle + arc.Sweep * bounds[i], arc.Sweep * (bounds[i + 1] - bounds[i]));
+ break;
+ }
+ }
+ }
+
+ private static KernelResult<IReadOnlyList<PlanarSpan>> Failure(string code, string message) =>
+ KernelResult<IReadOnlyList<PlanarSpan>>.Failure([new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, $"{code}: {message}", "MeridianHollow")]);
+}
diff --git a/Aetheris.Kernel.Core/Brep/ThinWalledBodyBRepPlan.cs b/Aetheris.Kernel.Core/Brep/ThinWalledBodyBRepPlan.cs
index ea07aad0..3a2cea38 100644
--- a/Aetheris.Kernel.Core/Brep/ThinWalledBodyBRepPlan.cs
+++ b/Aetheris.Kernel.Core/Brep/ThinWalledBodyBRepPlan.cs
@@ -8,6 +8,8 @@ using Aetheris.Kernel.Core.Geometry.Surfaces;
using Aetheris.Kernel.Core.Math;
using Aetheris.Kernel.Core.Results;
using Aetheris.Kernel.Core.Topology;
+using Aetheris.Kernel.Core.Brep.Features;
+using Aetheris.Kernel.Core.Geometry.Planar;
namespace Aetheris.Kernel.Core.Brep;
@@ -44,31 +46,6 @@ public static class ThinWalledBodyBRepPlanner
private static readonly Direction3D PlusZ = Direction3D.Create(new Vector3D(0, 0, 1));
private static readonly Direction3D MinusZ = Direction3D.Create(new Vector3D(0, 0, -1));
- public static KernelResult<ThinWalledBodyRealization> CreateRoundedBox(double width, double depth, double height, double cornerRadius, double wallThickness)
- {
- if (!FinitePositive(width, depth, height, cornerRadius, wallThickness)) return Failure("RoundedBoxInnerBoundaryDegenerate");
- if (width <= 2d * wallThickness + Tol || depth <= 2d * wallThickness + Tol || height <= wallThickness + Tol) return Failure("WallThicknessTooLarge");
- if (cornerRadius <= wallThickness + Tol) return Failure("RoundedBoxInnerRadiusDegenerate");
- if (cornerRadius >= double.Min(width, depth) / 2d - Tol) return Failure("RoundedBoxRadiusTooLarge");
-
- var witness = new HollowConstructionWitness("InsetRoundedProfile", true,
- "innerWidth=outerWidth-2T; innerDepth=outerDepth-2T; innerRadius=outerRadius-T; innerBottom=outerBottom+T; innerTop=outerTop",
- ["OuterPlanarWall -> InnerPlanarWall", "OuterCornerCylinder -> InnerCornerCylinder", "OuterBottomPlane -> InnerBottomPlane"],
- ["T>0", "width>2T", "depth>2T", "height>T", "cornerRadius>T"]);
- var feature = new HollowBodyFeature("RoundedBox", new Dictionary<string, double> { ["Width"] = width, ["Depth"] = depth, ["Height"] = height, ["CornerRadius"] = cornerRadius }, wallThickness, ["Top"], "ConstantNormalThickness", witness, "Firmament Primitive<Hollow>");
- var thickness = new List<ThinWallThicknessWitness>();
- thickness.AddRange(Enumerable.Range(0, 4).Select(i => new ThinWallThicknessWitness($"PlanarWall({i})", "Plane", "Plane", wallThickness, "inward normal")));
- thickness.AddRange(Enumerable.Range(0, 4).Select(i => new ThinWallThicknessWitness($"CornerWall({i})", "Cylinder", "Cylinder", wallThickness, "coaxial radial inward")));
- thickness.Add(new ThinWallThicknessWitness("Bottom", "Plane", "Plane", wallThickness, "+Z"));
- var construction = new ThinWalledBodyConstruction(feature,
- ["OuterBottom", .. Enumerable.Range(0, 8).Select(i => $"OuterWall({i})")],
- ["InnerBottom", .. Enumerable.Range(0, 8).Select(i => $"InnerWall({i})")],
- Enumerable.Range(0, 8).Select(i => $"Rim({i})").ToArray(), ["OuterBottom", "InnerBottom"], thickness);
- var plan = MakePlan("RoundedBox", construction, 8, 8, 8, 2, $"{width:R}|{depth:R}|{height:R}|{cornerRadius:R}|{wallThickness:R}");
- var body = BuildRoundedBox(width, depth, height, cornerRadius, wallThickness);
- return Validate(feature, construction, plan, body);
- }
-
public static KernelResult<ThinWalledBodyRealization> CreateFrustum(double bottomRadius, double topRadius, double height, double wallThickness)
{
if (!FinitePositive(bottomRadius, topRadius, height, wallThickness) || double.Abs(topRadius - bottomRadius) <= Tol) return Failure("FrustumOffsetConeDegenerate");
@@ -92,8 +69,7 @@ public static class ThinWalledBodyBRepPlanner
};
var construction = new ThinWalledBodyConstruction(feature, ["OuterConicalWall", "OuterBottom"], ["InnerConicalWall", "InnerBottom"], ["TopAnnularRim"], ["OuterBottom", "InnerBottom"], thickness);
var plan = MakePlan("Frustum", construction, 2, 2, 1, 2, $"{bottomRadius:R}|{topRadius:R}|{height:R}|{wallThickness:R}|{innerBottom:R}|{innerTop:R}");
- var body = BuildFrustum(bottomRadius, topRadius, height, wallThickness, innerBottom, innerTop, k);
- return Validate(feature, construction, plan, body);
+ return Realize(feature, construction, plan, [Line(0, 0, bottomRadius, 0), Line(bottomRadius, 0, topRadius, height), Line(topRadius, height, 0, height), Line(0, height, 0, 0)], wallThickness);
}
public static KernelResult<ThinWalledBodyRealization> CreateCylinder(double radius, double height, double wallThickness, double bottomBlendRadius = 0)
@@ -123,139 +99,36 @@ public static class ThinWalledBodyBRepPlanner
blended ? ["InnerCylindricalWall", "InnerBottomBlend", "InnerBottom"] : ["InnerCylindricalWall", "InnerBottom"],
["TopAnnularRim"], ["OuterBottom", "InnerBottom"], thickness);
var plan = MakePlan("Cylinder", construction, blended ? 3 : 2, blended ? 3 : 2, 1, 2, $"{radius:R}|{height:R}|{wallThickness:R}|{bottomBlendRadius:R}");
- return Validate(feature, construction, plan, BuildCylinder(radius, height, wallThickness, bottomBlendRadius));
+ PlanarSpan[] meridian = blended
+ ? [Line(0, 0, radius - bottomBlendRadius, 0), new PlanarArc((radius - bottomBlendRadius, bottomBlendRadius), bottomBlendRadius, -double.Pi / 2d, double.Pi / 2d),
+ Line(radius, bottomBlendRadius, radius, height), Line(radius, height, 0, height), Line(0, height, 0, 0)]
+ : [Line(0, 0, radius, 0), Line(radius, 0, radius, height), Line(radius, height, 0, height), Line(0, height, 0, 0)];
+ return Realize(feature, construction, plan, meridian, wallThickness);
}
- private static KernelResult<ThinWalledBodyRealization> Validate(HollowBodyFeature feature, ThinWalledBodyConstruction construction, ThinWalledBodyBRepPlan plan, BrepBody body)
+ /// <summary>
+ /// The primitive's body is its exterior meridian hollowed and turned by the general routes: the primitive owns
+ /// only its admission and its witness, never its own topology.
+ /// </summary>
+ private static KernelResult<ThinWalledBodyRealization> Realize(HollowBodyFeature feature, ThinWalledBodyConstruction construction, ThinWalledBodyBRepPlan plan,
+ IReadOnlyList<PlanarSpan> exteriorMeridian, double wallThickness)
{
- var preflight = BrepExportPreflight.Validate(body);
- if (!preflight.IsValid) return KernelResult<ThinWalledBodyRealization>.Failure(preflight.Diagnostics.Where(d => d.Severity == BrepExportPreflightSeverity.Error).Select(d => new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, d.Code, d.Context)).ToArray());
- return KernelResult<ThinWalledBodyRealization>.Success(new ThinWalledBodyRealization(feature, construction, plan, body));
+ var wall = MeridianHollow.Wall(exteriorMeridian, wallThickness, openTop: true, openBottom: false);
+ if (!wall.IsSuccess) return KernelResult<ThinWalledBodyRealization>.Failure(wall.Diagnostics);
+ var shell = BrepRevolvedShell.Build(wall.Value, RevolutionFrame.WorldZ);
+ if (!shell.IsSuccess) return KernelResult<ThinWalledBodyRealization>.Failure(shell.Diagnostics);
+ return KernelResult<ThinWalledBodyRealization>.Success(new ThinWalledBodyRealization(feature, construction, plan, shell.Value.Body));
}
- private static ThinWalledBodyBRepPlan MakePlan(string primitive, ThinWalledBodyConstruction construction, int outer, int inner, int rim, int closed, string parameters)
+ private static PlanarLine Line(double r0, double z0, double r1, double z1) => new((r0, z0), (r1, z1));
+
+ public static ThinWalledBodyBRepPlan MakePlan(string primitive, ThinWalledBodyConstruction construction, int outer, int inner, int rim, int closed, string parameters)
{
var outerFaces = construction.OuterBoundaryRoles; var innerFaces = construction.InnerBoundaryRoles; var rimFaces = construction.RimRoles; var closedFaces = construction.ClosedRegionRoles;
var source = $"ThinWalledBody|{primitive}|{parameters}|{string.Join(';', outerFaces)}|{string.Join(';', innerFaces)}|{string.Join(';', rimFaces)}";
return new(primitive, outerFaces, innerFaces, rimFaces, closedFaces, ["Opening(Top)"], construction.ThicknessWitnesses, Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(source))).ToLowerInvariant());
}
- private static BrepBody BuildRoundedBox(double width, double depth, double height, double radius, double t)
- {
- var b = new TopologyBuilder(); var g = new BrepGeometryStore(); var bindings = new BrepBindingModel(); var points = new Dictionary<VertexId, Point3D>();
- var outer = ProfilePoints(width / 2d, depth / 2d, radius); var inner = ProfilePoints(width / 2d - t, depth / 2d - t, radius - t);
- var v = new VertexId[4, 8]; var profiles = new[] { outer, outer, inner, inner }; var zs = new[] { 0d, height, t, height };
- for (var ring = 0; ring < 4; ring++) for (var i = 0; i < 8; i++) { v[ring, i] = b.AddVertex(); points[v[ring, i]] = new Point3D(profiles[ring][i].X, profiles[ring][i].Y, zs[ring]); }
- var edges = new EdgeId[4, 8];
- for (var ring = 0; ring < 4; ring++) for (var i = 0; i < 8; i++) edges[ring, i] = AddProfileEdge(v[ring, i], v[ring, (i + 1) % 8], profiles[ring], zs[ring], ring < 2 ? radius : radius - t, i, b, g, bindings);
- var outerVertical = new EdgeId[8]; var innerVertical = new EdgeId[8]; var rim = new EdgeId[8];
- for (var i = 0; i < 8; i++) { outerVertical[i] = AddLine(v[0, i], v[1, i], points, b, g, bindings); innerVertical[i] = AddLine(v[2, i], v[3, i], points, b, g, bindings); rim[i] = AddLine(v[1, i], v[3, i], points, b, g, bindings); }
- var faces = new List<FaceId>();
- var outerBottom = AddFace(b, [Reverse(Row(edges, 0))]); BindPlane(outerBottom, new Point3D(0, 0, 0), MinusZ, g, bindings); faces.Add(outerBottom);
- // The inner material boundary faces into the cavity (+Z). Keep the
- // planar support and SameSense canonical rather than encoding the same
- // orientation as (-Z, false), because STEP import normalizes planes.
- var innerBottom = AddFace(b, [Forward(Row(edges, 2))]); BindPlane(innerBottom, new Point3D(0, 0, t), PlusZ, g, bindings); faces.Add(innerBottom);
- for (var i = 0; i < 8; i++) { var face = AddFace(b, [[new(edges[0, i], false), new(outerVertical[(i + 1) % 8], false), new(edges[1, i], true), new(outerVertical[i], true)]]); BindSurface(face, SideSurface(i, outer, radius, 0d), g, bindings); faces.Add(face); }
- for (var i = 0; i < 8; i++) { var face = AddFace(b, [[new(edges[2, i], false), new(innerVertical[(i + 1) % 8], false), new(edges[3, i], true), new(innerVertical[i], true)]]); BindSurface(face, SideSurface(i, inner, radius - t, t), g, bindings, false); faces.Add(face); }
- for (var i = 0; i < 8; i++) { var face = AddFace(b, [[new(edges[1, i], false), new(rim[(i + 1) % 8], false), new(edges[3, i], true), new(rim[i], true)]]); BindPlane(face, new Point3D(0, 0, height), PlusZ, g, bindings); faces.Add(face); }
- var shell = b.AddShell(faces); b.AddBody([shell]); return new BrepBody(b.Model, g, bindings, points);
- }
-
- private static BrepBody BuildFrustum(double rb, double rt, double h, double t, double innerBottom, double innerTop, double k)
- {
- var b = new TopologyBuilder(); var g = new BrepGeometryStore(); var bindings = new BrepBindingModel(); var points = new Dictionary<VertexId, Point3D>();
- var radii = new[] { rb, rt, innerBottom, innerTop }; var zs = new[] { 0d, h, t, h }; var vertices = new VertexId[4]; var circles = new EdgeId[4];
- for (var i = 0; i < 4; i++) { vertices[i] = b.AddVertex(); points[vertices[i]] = new Point3D(radii[i], 0, zs[i]); circles[i] = AddCircle(vertices[i], radii[i], zs[i], b, g, bindings); }
- var outerCone = AddFace(b, [Forward([circles[0]]), Reverse([circles[1]])]);
- var innerCone = AddFace(b, [Forward([circles[2]]), Reverse([circles[3]])]);
- var outerBottom = AddFace(b, [Reverse([circles[0]])]);
- var innerBottomFace = AddFace(b, [Forward([circles[2]])]);
- var rim = AddFace(b, [Forward([circles[1]]), Reverse([circles[3]])]);
- var outerSupport = Cone(rb, k); var innerSupport = Cone(rb - t * double.Sqrt(1d + k * k), k);
- BindSurface(outerCone, SurfaceGeometry.FromCone(outerSupport), g, bindings);
- BindSurface(innerCone, SurfaceGeometry.FromCone(innerSupport), g, bindings, false);
- BindPlane(outerBottom, new Point3D(0, 0, 0), MinusZ, g, bindings);
- // Canonical material-facing inner bottom; see rounded-box counterpart.
- BindPlane(innerBottomFace, new Point3D(0, 0, t), PlusZ, g, bindings);
- BindPlane(rim, new Point3D(0, 0, h), PlusZ, g, bindings);
- var shell = b.AddShell([outerCone, innerCone, outerBottom, innerBottomFace, rim]); b.AddBody([shell]); return new BrepBody(b.Model, g, bindings, points);
- }
-
- private static BrepBody BuildCylinder(double radius, double height, double thickness, double blendRadius)
- {
- if (blendRadius > 0) return BuildBlendedCylinder(radius, height, thickness, blendRadius);
- var b = new TopologyBuilder(); var g = new BrepGeometryStore(); var bindings = new BrepBindingModel(); var points = new Dictionary<VertexId, Point3D>();
- var radii = new[] { radius, radius, radius - thickness, radius - thickness };
- var zs = new[] { 0d, height, thickness, height }; var vertices = new VertexId[4]; var circles = new EdgeId[4];
- for (var i = 0; i < 4; i++) { vertices[i] = b.AddVertex(); points[vertices[i]] = new Point3D(radii[i], 0, zs[i]); circles[i] = AddCircle(vertices[i], radii[i], zs[i], b, g, bindings); }
- var outerWall = AddFace(b, [Forward([circles[0]]), Reverse([circles[1]])]);
- var innerWall = AddFace(b, [Forward([circles[2]]), Reverse([circles[3]])]);
- var outerBottom = AddFace(b, [Reverse([circles[0]])]);
- var innerBottom = AddFace(b, [Forward([circles[2]])]);
- var rim = AddFace(b, [Forward([circles[1]]), Reverse([circles[3]])]);
- BindSurface(outerWall, SurfaceGeometry.FromCylinder(new CylinderSurface(new Point3D(0, 0, 0), PlusZ, radius, PlusX)), g, bindings);
- BindSurface(innerWall, SurfaceGeometry.FromCylinder(new CylinderSurface(new Point3D(0, 0, thickness), PlusZ, radius - thickness, PlusX)), g, bindings, false);
- BindPlane(outerBottom, new Point3D(0, 0, 0), MinusZ, g, bindings);
- BindPlane(innerBottom, new Point3D(0, 0, thickness), PlusZ, g, bindings);
- BindPlane(rim, new Point3D(0, 0, height), PlusZ, g, bindings);
- var shell = b.AddShell([outerWall, innerWall, outerBottom, innerBottom, rim]); b.AddBody([shell]);
- return new BrepBody(b.Model, g, bindings, points);
- }
-
- private static BrepBody BuildBlendedCylinder(double radius, double height, double thickness, double blendRadius)
- {
- var b = new TopologyBuilder(); var g = new BrepGeometryStore(); var bindings = new BrepBindingModel(); var points = new Dictionary<VertexId, Point3D>();
- var major = radius - blendRadius;
- var radii = new[] { radius, radius, radius - thickness, radius - thickness, major, major };
- var zs = new[] { blendRadius, height, blendRadius, height, 0d, thickness };
- var vertices = new VertexId[6]; var circles = new EdgeId[6];
- for (var i = 0; i < 6; i++) { vertices[i] = b.AddVertex(); points[vertices[i]] = new Point3D(radii[i], 0, zs[i]); circles[i] = AddCircle(vertices[i], radii[i], zs[i], b, g, bindings); }
- var outerWall = AddFace(b, [Forward([circles[0]]), Reverse([circles[1]])]);
- var innerWall = AddFace(b, [Forward([circles[2]]), Reverse([circles[3]])]);
- var outerBlend = AddFace(b, [Forward([circles[4]]), Reverse([circles[0]])]);
- var innerBlend = AddFace(b, [Forward([circles[5]]), Reverse([circles[2]])]);
- var outerBottom = AddFace(b, [Reverse([circles[4]])]);
- var innerBottom = AddFace(b, [Forward([circles[5]])]);
- var rim = AddFace(b, [Forward([circles[1]]), Reverse([circles[3]])]);
- BindSurface(outerWall, SurfaceGeometry.FromCylinder(new CylinderSurface(new Point3D(0, 0, 0), PlusZ, radius, PlusX)), g, bindings);
- BindSurface(innerWall, SurfaceGeometry.FromCylinder(new CylinderSurface(new Point3D(0, 0, thickness), PlusZ, radius - thickness, PlusX)), g, bindings, false);
- var center = new Point3D(0, 0, blendRadius);
- BindSurface(outerBlend, SurfaceGeometry.FromTorus(new TorusSurface(center, PlusZ, major, blendRadius, PlusX)), g, bindings);
- BindSurface(innerBlend, SurfaceGeometry.FromTorus(new TorusSurface(center, PlusZ, major, blendRadius - thickness, PlusX)), g, bindings, false);
- BindPlane(outerBottom, new Point3D(0, 0, 0), MinusZ, g, bindings);
- BindPlane(innerBottom, new Point3D(0, 0, thickness), PlusZ, g, bindings);
- BindPlane(rim, new Point3D(0, 0, height), PlusZ, g, bindings);
- var shell = b.AddShell([outerWall, innerWall, outerBlend, innerBlend, outerBottom, innerBottom, rim]); b.AddBody([shell]);
- return new BrepBody(b.Model, g, bindings, points);
- }
-
- private static ConeSurface Cone(double intercept, double slope)
- {
- var apex = new Point3D(0, 0, -intercept / slope); var axis = slope > 0 ? PlusZ : MinusZ;
- return new ConeSurface(apex, axis, double.Atan(double.Abs(slope)), PlusX);
- }
-
private static bool FinitePositive(params double[] values) => values.All(v => double.IsFinite(v) && v > Tol);
private static KernelResult<ThinWalledBodyRealization> Failure(string code) => KernelResult<ThinWalledBodyRealization>.Failure([new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, code, "ThinWalledBody.Admission")]);
- private static (double X, double Y)[] ProfilePoints(double a, double c, double r) => [(a-r,c), (a,c-r), (a,-c+r), (a-r,-c), (-a+r,-c), (-a,-c+r), (-a,c-r), (-a+r,c)];
- private static EdgeId[] Row(EdgeId[,] edges, int row) => Enumerable.Range(0, 8).Select(i => edges[row, i]).ToArray();
- private static EdgeId AddProfileEdge(VertexId start, VertexId end, (double X, double Y)[] p, double z, double radius, int i, TopologyBuilder b, BrepGeometryStore g, BrepBindingModel bindings)
- {
- var edge = b.AddEdge(start, end);
- if (i % 2 == 1) { var a = new Point3D(p[i].X, p[i].Y, z); var q = new Point3D(p[(i + 1) % 8].X, p[(i + 1) % 8].Y, z); AddCurve(edge, CurveGeometry.FromLine(new Line3Curve(a, Direction3D.Create(q - a))), 0, (q - a).Length, g, bindings); }
- else { var center = CornerCenter(i, p, z); var a = new Point3D(p[i].X, p[i].Y, z); AddCurve(edge, CurveGeometry.FromCircle(new Circle3Curve(center, MinusZ, radius, Direction3D.Create(a - center))), 0, double.Pi / 2d, g, bindings); }
- return edge;
- }
- private static EdgeId AddCircle(VertexId vertex, double radius, double z, TopologyBuilder b, BrepGeometryStore g, BrepBindingModel bindings) { var edge = b.AddEdge(vertex, vertex); AddCurve(edge, CurveGeometry.FromCircle(new Circle3Curve(new Point3D(0, 0, z), PlusZ, radius, PlusX)), 0, 2d * double.Pi, g, bindings); return edge; }
- private static EdgeId AddLine(VertexId start, VertexId end, IReadOnlyDictionary<VertexId, Point3D> points, TopologyBuilder b, BrepGeometryStore g, BrepBindingModel bindings) { var edge=b.AddEdge(start,end); var a=points[start]; var q=points[end]; AddCurve(edge,CurveGeometry.FromLine(new Line3Curve(a,Direction3D.Create(q-a))),0,(q-a).Length,g,bindings); return edge; }
- private static Point3D CornerCenter(int i, (double X, double Y)[] p, double z) => i switch { 0 => new(p[i].X,p[(i+1)%8].Y,z), 2 => new(p[(i+1)%8].X,p[i].Y,z), 4 => new(p[i].X,p[(i+1)%8].Y,z), _ => new(p[(i+1)%8].X,p[i].Y,z) };
- private static SurfaceGeometry SideSurface(int i, (double X, double Y)[] profile, double radius, double z) { if (i % 2 == 0) return SurfaceGeometry.FromCylinder(new CylinderSurface(CornerCenter(i, profile, z), PlusZ, radius, PlusX)); var a=new Point3D(profile[i].X,profile[i].Y,z); var q=new Point3D(profile[(i+1)%8].X,profile[(i+1)%8].Y,z); var tangent=Direction3D.Create(q-a); return SurfaceGeometry.FromPlane(new PlaneSurface(a,Direction3D.Create(PlusZ.ToVector().Cross(tangent.ToVector())),PlusZ)); }
- private static void AddCurve(EdgeId edge, CurveGeometry curve, double start, double end, BrepGeometryStore g, BrepBindingModel bindings) { var id=new CurveGeometryId(g.Curves.Count()+1); g.AddCurve(id,curve); bindings.AddEdgeBinding(new EdgeGeometryBinding(edge,id,new ParameterInterval(start,end))); }
- private static void BindSurface(FaceId face, SurfaceGeometry surface, BrepGeometryStore g, BrepBindingModel bindings, bool sameSense=true) { var id=new SurfaceGeometryId(g.Surfaces.Count()+1); g.AddSurface(id,surface); bindings.AddFaceBinding(new FaceGeometryBinding(face,id,sameSense)); }
- private static void BindPlane(FaceId face, Point3D origin, Direction3D normal, BrepGeometryStore g, BrepBindingModel bindings, bool sameSense=true) => BindSurface(face, SurfaceGeometry.FromPlane(new PlaneSurface(origin,normal,PlusX)),g,bindings,sameSense);
- private static FaceId AddFace(TopologyBuilder b, IReadOnlyList<IReadOnlyList<Use>> loops) { var ids=new List<LoopId>(); foreach(var uses in loops) { var loop=b.AllocateLoopId(); var coedges=uses.Select(_=>b.AllocateCoedgeId()).ToArray(); for(var i=0;i<coedges.Length;i++) b.AddCoedge(new Coedge(coedges[i],uses[i].Edge,loop,coedges[(i+1)%coedges.Length],coedges[(i+coedges.Length-1)%coedges.Length],uses[i].Reverse)); b.AddLoop(new Loop(loop,coedges)); ids.Add(loop); } return b.AddFace(ids); }
- private static Use[] Forward(IReadOnlyList<EdgeId> edges) => edges.Select(e=>new Use(e,false)).ToArray();
- private static Use[] Reverse(IReadOnlyList<EdgeId> edges) => edges.Reverse().Select(e=>new Use(e,true)).ToArray();
- private readonly record struct Use(EdgeId Edge, bool Reverse);
}
diff --git a/Aetheris.Kernel.Core/Geometry/Planar/LineArcInset.cs b/Aetheris.Kernel.Core/Geometry/Planar/LineArcInset.cs
new file mode 100644
index 00000000..6654b810
--- /dev/null
+++ b/Aetheris.Kernel.Core/Geometry/Planar/LineArcInset.cs
@@ -0,0 +1,277 @@
+namespace Aetheris.Kernel.Core.Geometry.Planar;
+
+/// <summary>A planar span of a closed line/arc loop.</summary>
+public abstract record PlanarSpan;
+public sealed record PlanarLine((double X, double Y) Start, (double X, double Y) End) : PlanarSpan;
+/// <summary>A circular arc; a positive sweep runs counter-clockwise.</summary>
+public sealed record PlanarArc((double X, double Y) Center, double Radius, double StartAngle, double Sweep) : PlanarSpan;
+public sealed record PlanarCircle((double X, double Y) Center, double Radius) : PlanarSpan;
+
+/// <summary>
+/// Exact inward offset of a closed line/arc loop: the one offset authority behind hollow section stacks and hollow
+/// revolutions. Lines stay parallel lines; arcs stay concentric; a reflex corner rounds with the inset distance about
+/// the corner, which keeps a wall constant; a convex arc no larger than the inset vanishes and its neighbours meet at
+/// a sharp corner. A span that reverses, or neighbours that no longer meet, is refused. Crossings between spans that
+/// are not neighbours are left to the caller, which owns the arrangement.
+/// </summary>
+public static class LineArcInset
+{
+ private const double Tol = 1e-9;
+
+ private abstract record Carrier;
+ private sealed record LineCarrier((double X, double Y) Point, (double X, double Y) Direction) : Carrier;
+ private sealed record CircleCarrier((double X, double Y) Center, double Radius, bool CounterClockwise) : Carrier;
+
+ private sealed class Element(Carrier carrier, (double X, double Y) start, (double X, double Y) end, double originalSweep)
+ {
+ public Carrier Carrier { get; } = carrier;
+ public (double X, double Y) Start { get; set; } = start;
+ public (double X, double Y) End { get; set; } = end;
+ public double OriginalSweep { get; } = originalSweep;
+ }
+
+ /// <summary>Insets one closed loop; the material lies inside an outer loop and outside a hole loop.</summary>
+ public static IReadOnlyList<PlanarSpan>? InsetLoop(IReadOnlyList<PlanarSpan> curves, double distance, bool outer,
+ string context, List<string> diagnostics)
+ {
+ if (curves.Count == 1 && curves[0] is PlanarCircle circle)
+ {
+ var radius = outer ? circle.Radius - distance : circle.Radius + distance;
+ if (radius <= Tol) { diagnostics.Add($"inset-wall-offset-collapse:{context}: a circle of radius {circle.Radius:R} closes at wall {distance:R}"); return null; }
+ return [new PlanarCircle(circle.Center, radius)];
+ }
+ if (curves.Any(c => c is not (PlanarLine or PlanarArc)))
+ {
+ diagnostics.Add($"inset-offset-curve-unsupported:{context}: only lines and circular arcs have exact offsets of the same kind");
+ return null;
+ }
+ // Material on the left: an outer loop runs counter-clockwise, a hole clockwise.
+ var oriented = SignedArea(curves) > 0d == outer ? curves : Reverse(curves);
+ var elements = new List<Element?>();
+ foreach (var curve in oriented)
+ {
+ switch (curve)
+ {
+ case PlanarLine line:
+ {
+ var d = Unit(Sub(line.End, line.Start));
+ var n = (-d.Y, d.X);
+ elements.Add(new Element(new LineCarrier(Add(line.Start, Mul(n, distance)), d),
+ Add(line.Start, Mul(n, distance)), Add(line.End, Mul(n, distance)), 0d));
+ break;
+ }
+ case PlanarArc arc:
+ {
+ var ccw = arc.Sweep > 0d;
+ var radius = ccw ? arc.Radius - distance : arc.Radius + distance;
+ if (radius <= Tol) { elements.Add(null); break; }
+ var a0 = arc.StartAngle;
+ var a1 = a0 + arc.Sweep;
+ elements.Add(new Element(new CircleCarrier(arc.Center, radius, ccw),
+ Polar(arc.Center, radius, a0), Polar(arc.Center, radius, a1), arc.Sweep));
+ break;
+ }
+ }
+ }
+ var count = oriented.Count;
+ var kept = Enumerable.Range(0, count).Where(i => elements[i] is not null).ToArray();
+ if (kept.Length < 2) { diagnostics.Add($"inset-wall-offset-collapse:{context}: the loop closes at wall {distance:R}"); return null; }
+ var result = new List<PlanarSpan>();
+ var joins = new (double X, double Y)[kept.Length];
+ var reflexArcs = new PlanarArc?[kept.Length];
+ for (var k = 0; k < kept.Length; k++)
+ {
+ var i = kept[k];
+ var j = kept[(k + 1) % kept.Length];
+ var first = elements[i]!;
+ var second = elements[j]!;
+ var vanishedBetween = (j - i + count) % count != 1;
+ var vertex = EndPoint(oriented[i]);
+ if (!vanishedBetween)
+ {
+ var tout = Unit(EndTangent(oriented[i]));
+ var tin = Unit(StartTangent(oriented[j]));
+ var cross = tout.X * tin.Y - tout.Y * tin.X;
+ var dot = tout.X * tin.X + tout.Y * tin.Y;
+ if (double.Abs(cross) <= 1e-9 && dot > 0d)
+ {
+ if (Distance(first.End, second.Start) > 1e-7) { diagnostics.Add($"inset-wall-offset-collapse:{context}: tangent curves part at the inset"); return null; }
+ joins[k] = first.End;
+ continue;
+ }
+ if (double.Abs(cross) <= 1e-9) { diagnostics.Add($"inset-wall-offset-collapse:{context}: the loop turns back on itself"); return null; }
+ if (cross < 0d)
+ {
+ // Reflex corner: the wall rounds about the corner, keeping its thickness.
+ var a0 = double.Atan2(first.End.Y - vertex.Y, first.End.X - vertex.X);
+ var a1 = double.Atan2(second.Start.Y - vertex.Y, second.Start.X - vertex.X);
+ var sweep = a1 - a0;
+ while (sweep >= 0d) sweep -= 2d * double.Pi;
+ while (sweep < -2d * double.Pi) sweep += 2d * double.Pi;
+ reflexArcs[k] = new PlanarArc(vertex, distance, a0, sweep);
+ joins[k] = (double.NaN, double.NaN);
+ continue;
+ }
+ }
+ var expected = Mid(first.End, second.Start);
+ if (!TryIntersect(first.Carrier, second.Carrier, expected, out var point))
+ {
+ diagnostics.Add($"inset-wall-offset-collapse:{context}: neighbouring walls no longer meet at the inset");
+ return null;
+ }
+ joins[k] = point;
+ }
+ for (var k = 0; k < kept.Length; k++)
+ {
+ var element = elements[kept[k]]!;
+ var previous = (k + kept.Length - 1) % kept.Length;
+ var start = double.IsNaN(joins[previous].X) ? element.Start : joins[previous];
+ var end = double.IsNaN(joins[k].X) ? element.End : joins[k];
+ var curve = Trim(element, start, end);
+ if (curve is null)
+ {
+ diagnostics.Add($"inset-wall-offset-collapse:{context}: curve {kept[k]} reverses at wall {distance:R}; the section is narrower than twice the wall there");
+ return null;
+ }
+ result.Add(curve);
+ if (reflexArcs[k] is { } arc) result.Add(arc);
+ }
+ return result;
+ }
+
+ private static PlanarSpan? Trim(Element element, (double X, double Y) start, (double X, double Y) end)
+ {
+ switch (element.Carrier)
+ {
+ case LineCarrier line:
+ var along = (end.X - start.X) * line.Direction.X + (end.Y - start.Y) * line.Direction.Y;
+ return along > 1e-9 ? new PlanarLine(start, end) : null;
+ case CircleCarrier circle:
+ var a0 = double.Atan2(start.Y - circle.Center.Y, start.X - circle.Center.X);
+ var a1 = double.Atan2(end.Y - circle.Center.Y, end.X - circle.Center.X);
+ var sweep = a1 - a0;
+ // The trimmed span is the branch nearest the original one; a different sign means it reversed.
+ var best = sweep;
+ for (var k = -2; k <= 2; k++)
+ if (double.Abs(sweep + 2d * double.Pi * k - element.OriginalSweep) < double.Abs(best - element.OriginalSweep))
+ best = sweep + 2d * double.Pi * k;
+ if (double.Sign(best) != double.Sign(element.OriginalSweep) || double.Abs(best) <= 1e-9) return null;
+ return new PlanarArc(circle.Center, circle.Radius, a0, best);
+ default:
+ return null;
+ }
+ }
+
+ private static bool TryIntersect(Carrier first, Carrier second, (double X, double Y) expected, out (double X, double Y) point)
+ {
+ var candidates = new List<(double X, double Y)>();
+ switch (first, second)
+ {
+ case (LineCarrier a, LineCarrier b):
+ {
+ var den = a.Direction.X * b.Direction.Y - a.Direction.Y * b.Direction.X;
+ if (double.Abs(den) > 1e-12)
+ {
+ var w = Sub(b.Point, a.Point);
+ var s = (w.X * b.Direction.Y - w.Y * b.Direction.X) / den;
+ candidates.Add(Add(a.Point, Mul(a.Direction, s)));
+ }
+ break;
+ }
+ case (LineCarrier a, CircleCarrier c): candidates.AddRange(LineCircle(a, c)); break;
+ case (CircleCarrier c, LineCarrier a): candidates.AddRange(LineCircle(a, c)); break;
+ case (CircleCarrier a, CircleCarrier b): candidates.AddRange(CircleCircle(a, b)); break;
+ }
+ if (candidates.Count == 0) { point = default; return false; }
+ point = candidates.MinBy(c => Distance(c, expected));
+ return true;
+ }
+
+ private static IEnumerable<(double X, double Y)> LineCircle(LineCarrier line, CircleCarrier circle)
+ {
+ var w = Sub(line.Point, circle.Center);
+ var b = w.X * line.Direction.X + w.Y * line.Direction.Y;
+ var c = w.X * w.X + w.Y * w.Y - circle.Radius * circle.Radius;
+ var disc = b * b - c;
+ if (disc < -1e-12) yield break;
+ var root = double.Sqrt(double.Max(0d, disc));
+ yield return Add(line.Point, Mul(line.Direction, -b - root));
+ yield return Add(line.Point, Mul(line.Direction, -b + root));
+ }
+
+ private static IEnumerable<(double X, double Y)> CircleCircle(CircleCarrier a, CircleCarrier b)
+ {
+ var d = Distance(a.Center, b.Center);
+ if (d < 1e-12 || d > a.Radius + b.Radius + 1e-12 || d < double.Abs(a.Radius - b.Radius) - 1e-12) yield break;
+ var x = (d * d + a.Radius * a.Radius - b.Radius * b.Radius) / (2d * d);
+ var h = double.Sqrt(double.Max(0d, a.Radius * a.Radius - x * x));
+ var u = Mul(Sub(b.Center, a.Center), 1d / d);
+ var mid = Add(a.Center, Mul(u, x));
+ yield return Add(mid, Mul((-u.Y, u.X), h));
+ yield return Add(mid, Mul((u.Y, -u.X), h));
+ }
+
+ public static IReadOnlyList<PlanarSpan> Reverse(IReadOnlyList<PlanarSpan> curves) =>
+ curves.Reverse().Select(c => c switch
+ {
+ PlanarLine line => (PlanarSpan)new PlanarLine(line.End, line.Start),
+ PlanarArc arc => new PlanarArc(arc.Center, arc.Radius, arc.StartAngle + arc.Sweep, -arc.Sweep),
+ _ => c
+ }).ToArray();
+
+ public static double SignedArea(IReadOnlyList<PlanarSpan> curves)
+ {
+ var sum = 0d;
+ foreach (var curve in curves)
+ sum += curve switch
+ {
+ PlanarLine line => line.Start.X * line.End.Y - line.End.X * line.Start.Y,
+ PlanarArc arc => ArcDoubleArea(arc),
+ PlanarCircle circle => 2d * double.Pi * circle.Radius * circle.Radius,
+ _ => 0d
+ };
+ return sum / 2d;
+ }
+
+ private static double ArcDoubleArea(PlanarArc arc)
+ {
+ var a = arc.StartAngle; var b = a + arc.Sweep; var r = arc.Radius; var (x, y) = arc.Center;
+ return x * r * (double.Sin(b) - double.Sin(a)) - y * r * (double.Cos(b) - double.Cos(a)) + r * r * (b - a);
+ }
+
+ public static (double X, double Y) StartPoint(PlanarSpan curve) => curve switch
+ {
+ PlanarLine line => line.Start,
+ PlanarArc arc => Polar(arc.Center, arc.Radius, arc.StartAngle),
+ PlanarCircle circle => (circle.Center.X + circle.Radius, circle.Center.Y),
+ _ => throw new NotSupportedException()
+ };
+ public static (double X, double Y) EndPoint(PlanarSpan curve) => curve switch
+ {
+ PlanarLine line => line.End,
+ PlanarArc arc => Polar(arc.Center, arc.Radius, arc.StartAngle + arc.Sweep),
+ _ => throw new NotSupportedException()
+ };
+ private static (double X, double Y) StartTangent(PlanarSpan curve) => curve switch
+ {
+ PlanarLine line => Sub(line.End, line.Start),
+ PlanarArc arc => ArcTangent(arc, arc.StartAngle),
+ _ => throw new NotSupportedException()
+ };
+ private static (double X, double Y) EndTangent(PlanarSpan curve) => curve switch
+ {
+ PlanarLine line => Sub(line.End, line.Start),
+ PlanarArc arc => ArcTangent(arc, arc.StartAngle + arc.Sweep),
+ _ => throw new NotSupportedException()
+ };
+ private static (double X, double Y) ArcTangent(PlanarArc arc, double angle) =>
+ Mul((-double.Sin(angle), double.Cos(angle)), double.Sign(arc.Sweep));
+
+ private static (double X, double Y) Polar((double X, double Y) c, double r, double a) => (c.X + r * double.Cos(a), c.Y + r * double.Sin(a));
+ private static (double X, double Y) Add((double X, double Y) a, (double X, double Y) b) => (a.X + b.X, a.Y + b.Y);
+ private static (double X, double Y) Sub((double X, double Y) a, (double X, double Y) b) => (a.X - b.X, a.Y - b.Y);
+ private static (double X, double Y) Mul((double X, double Y) a, double s) => (a.X * s, a.Y * s);
+ private static (double X, double Y) Mid((double X, double Y) a, (double X, double Y) b) => ((a.X + b.X) / 2d, (a.Y + b.Y) / 2d);
+ private static double Distance((double X, double Y) a, (double X, double Y) b) => double.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y));
+ private static (double X, double Y) Unit((double X, double Y) v) { var l = double.Sqrt(v.X * v.X + v.Y * v.Y); return (v.X / l, v.Y / l); }
+}
diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
index 6f588b26..5bc0de1a 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
@@ -2644,18 +2644,20 @@ public static class Step242Importer
if (loops.Count == 0) return (true, new Dictionary<LoopId, bool>());
var outer = loops.SingleOrDefault(loop => loop.IsDeclaredOuter) ?? loops[0];
var resolved = new Dictionary<LoopId, bool>();
+ IReadOnlyList<UvPoint>? Project(LoopBuildData loop) => surface.Kind switch
+ {
+ SurfaceGeometryKind.Plane => SimplifyClosedPolygon(ProjectLoopToPlane(loop.Samples, surface.Plane!.Value), ContainmentEps),
+ SurfaceGeometryKind.Cylinder => ProjectLoopToCylinder(loop.Samples, surface.Cylinder!.Value),
+ SurfaceGeometryKind.Cone => ProjectLoopToCone(loop.Samples, surface.Cone!.Value),
+ SurfaceGeometryKind.Sphere => ProjectLoopToSphere(loop.Samples, surface.Sphere!.Value),
+ SurfaceGeometryKind.Torus => ProjectLoopToTorus(loop.Samples, surface.Torus!.Value),
+ _ => null,
+ };
+ var projections = loops.ToDictionary(loop => loop.LoopId, Project);
foreach (var loop in loops)
{
var isOuter = loop.LoopId == outer.LoopId;
- IReadOnlyList<UvPoint>? projected = surface.Kind switch
- {
- SurfaceGeometryKind.Plane => SimplifyClosedPolygon(ProjectLoopToPlane(loop.Samples, surface.Plane!.Value), ContainmentEps),
- SurfaceGeometryKind.Cylinder => ProjectLoopToCylinder(loop.Samples, surface.Cylinder!.Value),
- SurfaceGeometryKind.Cone => ProjectLoopToCone(loop.Samples, surface.Cone!.Value),
- SurfaceGeometryKind.Sphere => ProjectLoopToSphere(loop.Samples, surface.Sphere!.Value),
- SurfaceGeometryKind.Torus => ProjectLoopToTorus(loop.Samples, surface.Torus!.Value),
- _ => null,
- };
+ var projected = projections[loop.LoopId];
var signedArea = projected is null ? 0d : ComputeSignedArea(projected);
var periodicity = SurfacePeriodicity.Of(surface);
var boundaryAligned = surface.Kind == SurfaceGeometryKind.Sphere
@@ -2664,7 +2666,7 @@ public static class Step242Importer
: surface.Kind != SurfaceGeometryKind.Sphere
&& projected is not null
&& TryDeriveFullPeriodTraversalAlignment(projected, periodicity, out var periodicAligned)
- ? periodicAligned
+ ? FullTurnLoopAlignment(loop, projected, periodicAligned, isOuter)
: surface.Kind == SurfaceGeometryKind.Cone
&& TryDeriveSupportAlignmentFromBoundaryNormal(loop.Samples, surface, out var conicalAligned)
? conicalAligned
@@ -2676,6 +2678,20 @@ public static class Step242Importer
resolved[loop.LoopId] = isOuter ? boundaryAligned : !boundaryAligned;
}
return (resolved[outer.LoopId], resolved);
+
+ // A loop running once round a cylinder or cone says nothing by itself about which side the face lies on. When the
+ // face has another loop, the face lies between them: a loop with the face on its +v side bounds an aligned face
+ // when it runs +u. The answer is the face's, so an inner loop reports it negated, as the caller expects.
+ bool FullTurnLoopAlignment(LoopBuildData loop, IReadOnlyList<UvPoint> projected, bool runsPositiveU, bool isOuter)
+ {
+ if (surface.Kind is not (SurfaceGeometryKind.Cylinder or SurfaceGeometryKind.Cone) || loops.Count < 2) return runsPositiveU;
+ var others = loops.Where(other => other.LoopId != loop.LoopId).Select(other => projections[other.LoopId]).Where(p => p is { Count: > 0 }).ToArray();
+ if (others.Length == 0) return runsPositiveU;
+ var side = others.Average(p => p!.Average(point => point.Y)) - projected.Average(point => point.Y);
+ if (double.Abs(side) <= ContainmentEps) return runsPositiveU;
+ var faceAligned = (side > 0d) == runsPositiveU;
+ return isOuter ? faceAligned : !faceAligned;
+ }
}
private static bool TryDeriveFullPeriodTraversalAlignment(
diff --git a/Aetheris.Kernel.Firmament.Tests/ComposeHollowTests.cs b/Aetheris.Kernel.Firmament.Tests/ComposeHollowTests.cs
index 635f6554..05f98496 100644
--- a/Aetheris.Kernel.Firmament.Tests/ComposeHollowTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/ComposeHollowTests.cs
@@ -19,6 +19,9 @@ public sealed class ComposeHollowTests
},
// The reflex corner adds the square of the wall less a quarter disc; the bore's tube grows it by the wall.
{ "bracket-tray", (1275 - 9 * double.Pi) * 15 - (891 + 4 - double.Pi - 25 * double.Pi) * 13 },
+ // Revolved walls: Pappus over the wall meridian, computed independently (shapely, 512-segment round erosion).
+ { "bottle-revolve", 22657.640 },
+ { "sleeve-revolve", 18820.424 },
};
[Theory]
@@ -39,6 +42,8 @@ public sealed class ComposeHollowTests
[InlineData("narrow-neck", "hollow-wall-offset-collapse")]
[InlineData("closed-vessel", "firmament-v2-hollow-closed-vessel-unsupported")]
[InlineData("side-opening", "firmament-v2-hollow-opening-unsupported")]
+ [InlineData("revolve-pointed-tip", "revolve-shell-apex-unsupported")]
+ [InlineData("revolve-partial-turn", "firmament-v2-hollow-revolve-full-turn-required")]
public void HollowRefusalsNameTheirCause(string fixture, string code)
{
var built = FirmamentBuildAndExport.CompileSource(File.ReadAllText(Fixture("Invalid", fixture)));
@@ -46,6 +51,27 @@ public sealed class ComposeHollowTests
Assert.Contains(built.Diagnostics, d => d.Message.Contains(code, StringComparison.Ordinal));
}
+ [Fact]
+ public void RoundedBoxPrimitiveHollowsThroughTheSectionStack()
+ {
+ var result = HollowPrimitives.RoundedBox(120, 80, 24, 12, 2);
+ Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics.Select(x => x.Message)));
+ Assert.Equal("InsetRoundedProfile", result.Value.Feature.Witness.Kind);
+ Assert.True(result.Value.Plan.IsAuthoritative);
+ var step = Aetheris.Kernel.Core.Step242.Step242Exporter.ExportBody(result.Value.Body);
+ Assert.True(step.IsSuccess);
+ var imported = Step242Importer.ImportBody(step.Value);
+ var volume = BrepMassProperties.Evaluate(imported.Value, new(0.01d, double.Pi / 90d, 1d, MaximumSegments: 256)).AbsoluteVolume;
+ var expected = RoundedRect(120, 80, 12) * 24 - RoundedRect(116, 76, 10) * 22;
+ Assert.InRange(volume, expected * (1 - 2e-4), expected * (1 + 2e-4));
+ }
+
+ [Theory]
+ [InlineData(120, 80, 24, 12)]
+ [InlineData(120, 80, 2, 2)]
+ public void RoundedBoxPrimitiveRejectsCollapsedInnerBoundary(double width, double depth, double height, double thickness)
+ => Assert.False(HollowPrimitives.RoundedBox(width, depth, height, 12, thickness).IsSuccess);
+
[Fact]
public void ConvexArcsNoLargerThanTheWallVanishIntoSharpCorners()
{
diff --git a/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs b/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs
index 0495ea63..3ba3d92b 100644
--- a/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs
@@ -423,6 +423,7 @@ public static partial class FirmamentBuildAndExport
if (v2Parse.BoundRevolve is { } boundRevolve)
{
var authored = boundRevolve;
+ if (authored.Hollow is { } revolveHollow) return ExportHollowRevolve(authored, revolveHollow);
var built = ResolvedProfileRevolveEmitter.TryEmit(authored);
if (!built.Succeeded || built.Body is null || built.Plan is null)
return KernelResult<FirmamentStepExportResult>.Failure(built.Diagnostics.Select(message => new Kernel.Core.Diagnostics.KernelDiagnostic(
@@ -1982,6 +1983,74 @@ public static partial class FirmamentBuildAndExport
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) { MaterializedFeatures = FirmamentFeatureAccounting.Receipts(solid.Name, "EdgeFinish", first.Name, second.Name) });
}
+ /// <summary>
+ /// <c>Revolve&lt;Hollow&gt;</c>: the Profile becomes a meridian about the axis, the general meridian hollow derives
+ /// its constant wall, and the wall turns into a seamless shell of revolution.
+ /// </summary>
+ private static KernelResult<FirmamentStepExportResult> ExportHollowRevolve(ResolvedRevolve authored, PrismaticHollowIntent hollow)
+ {
+ KernelResult<FirmamentStepExportResult> Fail(IEnumerable<string> messages) => KernelResult<FirmamentStepExportResult>.Failure(messages.Select(message =>
+ new Kernel.Core.Diagnostics.KernelDiagnostic(Kernel.Core.Diagnostics.KernelDiagnosticCode.ValidationFailed, Kernel.Core.Diagnostics.KernelDiagnosticSeverity.Error, message, "FirmamentV2.Revolve")).ToArray());
+ var plane = authored.Profile.EffectiveConstructionPlane;
+ var origin = new Point3D(authored.Axis.Origin.X, authored.Axis.Origin.Y, authored.Axis.Origin.Z);
+ var direction = new Vector3D(authored.Axis.Direction.X, authored.Axis.Direction.Y, authored.Axis.Direction.Z);
+ direction = direction * (1d / direction.Length);
+ var local = plane.ToLocal(origin);
+ var d = (X: direction.Dot(plane.AxisX.ToVector()), Y: direction.Dot(plane.AxisY.ToVector()));
+ if (authored.Profile.Loops.Count != 1)
+ return Fail(["firmament-v2-hollow-revolve-meridian-invalid: Revolve<Hollow> turns one outer Profile loop."]);
+ var curves = authored.Profile.Loops[0].Segments.Select(segment => segment.Geometry).ToArray();
+ // The meridian's radius runs away from the axis on the Profile's side.
+ var sample = curves.Select(c => Kernel.Core.Geometry.Planar.LineArcInset.StartPoint(ProfileInset2D.ToPlanar(c)))
+ .Select(p => (p.X - local.X) * -d.Y + (p.Y - local.Y) * d.X).MaxBy(double.Abs);
+ var n = sample >= 0d ? (X: -d.Y, Y: d.X) : (X: d.Y, Y: -d.X);
+ (double R, double Z) Map((double X, double Y) p) => ((p.X - local.X) * n.X + (p.Y - local.Y) * n.Y, (p.X - local.X) * d.X + (p.Y - local.Y) * d.Y);
+ var reflected = n.X * d.Y - n.Y * d.X < 0d;
+ var meridian = new List<Kernel.Core.Geometry.Planar.PlanarSpan>();
+ foreach (var curve in curves)
+ {
+ switch (curve)
+ {
+ case LineArcLineSegment2D line:
+ meridian.Add(new Kernel.Core.Geometry.Planar.PlanarLine(Map(line.Start), Map(line.End)));
+ break;
+ case LineArcCircularArc2D arc:
+ {
+ var center = Map(arc.Center);
+ var start = Map((arc.Center.X + arc.Radius * Math.Cos(arc.StartAngleRadians), arc.Center.Y + arc.Radius * Math.Sin(arc.StartAngleRadians)));
+ meridian.Add(new Kernel.Core.Geometry.Planar.PlanarArc(center, arc.Radius, Math.Atan2(start.Z - center.Z, start.R - center.R),
+ reflected ? -arc.SweepAngleRadians : arc.SweepAngleRadians));
+ break;
+ }
+ default:
+ return Fail(["hollow-offset-curve-unsupported: Revolve<Hollow> meridians are lines and circular arcs."]);
+ }
+ }
+ var wall = Kernel.Core.Brep.Features.MeridianHollow.Wall(meridian, hollow.WallThickness, hollow.OpenTop, hollow.OpenBottom);
+ if (!wall.IsSuccess) return Fail(wall.Diagnostics.Select(x => x.Message));
+ var radial = plane.ToWorldVector(n);
+ var frame = new Kernel.Core.Brep.Features.RevolutionFrame(origin, Direction3D.Create(direction), Direction3D.Create(radial));
+ var shell = Kernel.Core.Brep.Features.BrepRevolvedShell.Build(wall.Value, frame);
+ if (!shell.IsSuccess) return Fail(shell.Diagnostics.Select(x => x.Message));
+ var body = shell.Value.Body;
+ var step = Step242Exporter.ExportBody(body, new Step242ExportOptions { ProductName = authored.Name });
+ if (!step.IsSuccess) return KernelResult<FirmamentStepExportResult>.Failure(step.Diagnostics);
+ var reimport = Step242Importer.ImportBody(step.Value);
+ if (!reimport.IsSuccess || reimport.Value is null) return KernelResult<FirmamentStepExportResult>.Failure(reimport.Diagnostics);
+ if (!FirmamentManifoldChecker.IsManifold(reimport.Value)) return Fail([$"firmament-revolve-step-reimport-not-manifold:{authored.Name}"]);
+ var surfaces = body.Topology.Faces.Select(face => body.GetFaceSurface(face.Id).Kind).ToArray();
+ var hash = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(step.Value))).ToLowerInvariant();
+ var report = new FirmamentRevolveReport(authored.Profile.Name, authored.AxisName, authored.SweepRadians,
+ authored.SweepRadians * 180d / Math.PI, authored.AuthoredAlias, authored.SweepRadians < 0d ? "Negative" : "Positive", "Full", hash,
+ surfaces.Select(kind => kind.ToString()).ToArray(), body.Topology.Vertices.Count(), body.Topology.Edges.Count(), body.Topology.Faces.Count(),
+ surfaces.Count(kind => kind == SurfaceGeometryKind.Plane), surfaces.Count(kind => kind == SurfaceGeometryKind.Cylinder),
+ surfaces.Count(kind => kind == SurfaceGeometryKind.Cone), surfaces.Count(kind => kind == SurfaceGeometryKind.Sphere),
+ surfaces.Count(kind => kind == SurfaceGeometryKind.Torus), surfaces.Count(kind => kind == SurfaceGeometryKind.SurfaceOfRevolution), true, hash);
+ return KernelResult<FirmamentStepExportResult>.Success(new(step.Value, authored.Name, 0, "hollow-revolve", "revolve", Revolve: report,
+ EngineeringFeatures: [new(authored.Name, "Revolve<Hollow>", authored.StableId, authored.Name, authored.Axis.StableId, authored.Profile.Name,
+ hollow.WallThickness, "WallThickness", "Base", PolicySource: "MeridianHollow", MaterializationRoute: "BrepRevolvedShell")]) { RuntimeBodySourceName = authored.Name, RuntimeBody = body });
+ }
+
private static KernelResult<FirmamentStepExportResult>? TryExportV2HollowBody(FirmamentV2Document document)
{
if (document.Solids.Count != 1 || document.Solid.ConstructionPolicy != FirmamentV2ConstructionPolicy.Hollow)
@@ -1995,7 +2064,7 @@ public static partial class FirmamentBuildAndExport
KernelResult<ThinWalledBodyRealization> realization = solid.Primitive switch
{
- FirmamentV2RoundedBoxRecord rounded when rounded.Size.Count == 3 => ThinWalledBodyBRepPlanner.CreateRoundedBox(rounded.Size[0], rounded.Size[1], rounded.Size[2], rounded.CornerRadius, solid.Hollow.WallThickness),
+ FirmamentV2RoundedBoxRecord rounded when rounded.Size.Count == 3 => HollowPrimitives.RoundedBox(rounded.Size[0], rounded.Size[1], rounded.Size[2], rounded.CornerRadius, solid.Hollow.WallThickness),
FirmamentV2FrustumRecord frustum => ThinWalledBodyBRepPlanner.CreateFrustum(frustum.BottomRadius, frustum.TopRadius, frustum.Height, solid.Hollow.WallThickness),
FirmamentV2CylinderRecord cylinder => ThinWalledBodyBRepPlanner.CreateCylinder(cylinder.Radius, cylinder.Height, solid.Hollow.WallThickness, solid.Hollow.BottomBlendRadius),
_ => throw new InvalidOperationException("Parser admitted a Hollow policy without a HollowConstructible witness.")
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/RevolveAuthoringParser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/RevolveAuthoringParser.cs
index 84985711..98e2f7a0 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/RevolveAuthoringParser.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/RevolveAuthoringParser.cs
@@ -11,7 +11,11 @@ public sealed record ResolvedRevolve(
ConceptIrAxisValue Axis,
double SweepRadians,
string? AuthoredAlias,
- string StableId);
+ string StableId)
+{
+ /// <summary>Set for <c>Revolve&lt;Hollow&gt;</c>: a full turn hollowed at constant wall.</summary>
+ public PrismaticHollowIntent? Hollow { get; init; }
+}
/// <summary>Finite semantic binder for Profile + explicit Axis + bounded Angle.</summary>
public static class RevolveAuthoringParser
@@ -47,8 +51,24 @@ public static class RevolveAuthoringParser
var profileName = fields.Word("Profile");
var axisName = fields.Word("About");
var angleExpression = fields.Take("Angle");
+ var hollowRevolve = feature.Type.Arguments.Count == 1 && FirmamentSyntaxValues.Reference(feature.Type.Arguments[0].Value) == "Hollow";
+ PrismaticHollowIntent? hollow = null;
+ if (hollowRevolve)
+ {
+ var wallExpression = fields.Take("WallThickness");
+ var openingsExpression = fields.Take("Openings");
+ var wall = FirmamentSyntaxValues.TryMeasure(wallExpression, "mm", out var w) ? w : double.NaN;
+ if (wallExpression is null) diagnostics.Add("firmament-v2-hollow-wall-thickness-required: Revolve<Hollow> requires wallThickness.");
+ else if (!(wall > 0d)) diagnostics.Add("firmament-v2-hollow-wall-thickness-must-be-positive");
+ var openings = (openingsExpression as SequenceSyntax)?.Items.Select(a => FirmamentSyntaxValues.Reference(a.Value)).ToArray() ?? [];
+ if (openings.Any(o => o is not ("Top" or "Bottom")) || openings.Distinct().Count() != openings.Length)
+ diagnostics.Add("firmament-v2-hollow-opening-unsupported: Revolve<Hollow> openings are Top and/or Bottom, the flat caps at the ends of the axis.");
+ if (openings.Length == 0)
+ diagnostics.Add("firmament-v2-hollow-closed-vessel-unsupported: A closed hollow needs an inner void shell, which is not built yet; open Top or Bottom.");
+ hollow = new(wall, openings.Contains("Top"), openings.Contains("Bottom"), $"offset:{feature.Span.Start}");
+ }
fields.Complete();
- if (feature.Type.Arguments.Count > 0 || feature.Modifiers.Count > 0 || name.Length == 0)
+ if (feature.Type.Arguments.Count > 0 && !hollowRevolve || feature.Modifiers.Count > 0 || name.Length == 0)
diagnostics.Add(Prefix + "header-invalid:" + name);
if (profileName is null) diagnostics.Add(Prefix + "profile-not-found:" + name);
if (axisName is null) diagnostics.Add(Prefix + "axis-not-found:" + name);
@@ -97,6 +117,7 @@ public static class RevolveAuthoringParser
if (angleExpression is not null && !TryAngle(angleExpression, out sweep, out alias)) diagnostics.Add(Prefix + "angle-invalid:" + name);
else if (angleExpression is not null && Math.Abs(sweep) <= Tol) diagnostics.Add(Prefix + "zero-angle:" + name);
else if (angleExpression is not null && Math.Abs(sweep) > 2d * Math.PI + Tol) diagnostics.Add(Prefix + "angle-out-of-range:" + name);
+ else if (hollow is not null && Math.Abs(Math.Abs(sweep) - 2d * Math.PI) > Tol) diagnostics.Add("firmament-v2-hollow-revolve-full-turn-required: Revolve<Hollow> turns a full revolution.");
if (profile is not null && axis is not null)
{
@@ -113,7 +134,7 @@ public static class RevolveAuthoringParser
reportedDiagnostics = diagnostics.Distinct(StringComparer.Ordinal).ToArray();
return reportedDiagnostics.Count == 0 && profile is not null && axis is not null
- ? new(name, profile, axisName!, axis, sweep, alias, "revolve:" + name)
+ ? new(name, profile, axisName!, axis, sweep, alias, "revolve:" + name) { Hollow = hollow }
: null;
}
diff --git a/Aetheris.Kernel.Firmament/Materializer/HollowPrimitives.cs b/Aetheris.Kernel.Firmament/Materializer/HollowPrimitives.cs
new file mode 100644
index 00000000..ae4ebabb
--- /dev/null
+++ b/Aetheris.Kernel.Firmament/Materializer/HollowPrimitives.cs
@@ -0,0 +1,70 @@
+using Aetheris.Kernel.Core.Air;
+using Aetheris.Kernel.Core.Brep;
+using Aetheris.Kernel.Core.Diagnostics;
+using Aetheris.Kernel.Core.Results;
+
+namespace Aetheris.Kernel.Firmament.Materializer;
+
+/// <summary>
+/// Hollow primitives that are section stacks. Like the revolved ones in <see cref="ThinWalledBodyBRepPlanner"/>,
+/// a primitive owns its admission and its witness; its body comes from the general hollow route.
+/// </summary>
+public static class HollowPrimitives
+{
+ private const double Tol = 1e-8;
+
+ public static KernelResult<ThinWalledBodyRealization> RoundedBox(double width, double depth, double height, double cornerRadius, double wallThickness)
+ {
+ if (!FinitePositive(width, depth, height, cornerRadius, wallThickness)) return Failure("RoundedBoxInnerBoundaryDegenerate");
+ if (width <= 2d * wallThickness + Tol || depth <= 2d * wallThickness + Tol || height <= wallThickness + Tol) return Failure("WallThicknessTooLarge");
+ if (cornerRadius <= wallThickness + Tol) return Failure("RoundedBoxInnerRadiusDegenerate");
+ if (cornerRadius >= double.Min(width, depth) / 2d - Tol) return Failure("RoundedBoxRadiusTooLarge");
+
+ var witness = new HollowConstructionWitness("InsetRoundedProfile", true,
+ "innerWidth=outerWidth-2T; innerDepth=outerDepth-2T; innerRadius=outerRadius-T; innerBottom=outerBottom+T; innerTop=outerTop",
+ ["OuterPlanarWall -> InnerPlanarWall", "OuterCornerCylinder -> InnerCornerCylinder", "OuterBottomPlane -> InnerBottomPlane"],
+ ["T>0", "width>2T", "depth>2T", "height>T", "cornerRadius>T"]);
+ var feature = new HollowBodyFeature("RoundedBox", new Dictionary<string, double> { ["Width"] = width, ["Depth"] = depth, ["Height"] = height, ["CornerRadius"] = cornerRadius }, wallThickness, ["Top"], "ConstantNormalThickness", witness, "Firmament Primitive<Hollow>");
+ var thickness = new List<ThinWallThicknessWitness>();
+ thickness.AddRange(Enumerable.Range(0, 4).Select(i => new ThinWallThicknessWitness($"PlanarWall({i})", "Plane", "Plane", wallThickness, "inward normal")));
+ thickness.AddRange(Enumerable.Range(0, 4).Select(i => new ThinWallThicknessWitness($"CornerWall({i})", "Cylinder", "Cylinder", wallThickness, "coaxial radial inward")));
+ thickness.Add(new ThinWallThicknessWitness("Bottom", "Plane", "Plane", wallThickness, "+Z"));
+ var construction = new ThinWalledBodyConstruction(feature,
+ ["OuterBottom", .. Enumerable.Range(0, 8).Select(i => $"OuterWall({i})")],
+ ["InnerBottom", .. Enumerable.Range(0, 8).Select(i => $"InnerWall({i})")],
+ Enumerable.Range(0, 8).Select(i => $"Rim({i})").ToArray(), ["OuterBottom", "InnerBottom"], thickness);
+ var plan = ThinWalledBodyBRepPlanner.MakePlan("RoundedBox", construction, 8, 8, 8, 2, $"{width:R}|{depth:R}|{height:R}|{cornerRadius:R}|{wallThickness:R}");
+ // The body is the rounded-rectangle extrusion hollowed through the general section-stack route.
+ var outline = RoundedRectangle("HollowRoundedBox.Outline", width, depth, cornerRadius);
+ var operations = new[] { new PrismaticProfileOperation("Stock", PrismaticProfileIntent.Base, outline.Name, 0d, height, "Stock", "primitive", null, null) };
+ var composition = new PrismaticProfileCompositionFeature("RoundedBox", "XY", "+Z",
+ new PrismaticProfilePlacement("LegacyImplicitWorldXY", 0d, 0d, 0d, "XY", "+Z", "+X", false), operations, [0d, height], "primitive-hollow")
+ { Hollow = new PrismaticHollowIntent(wallThickness, OpenTop: true, OpenBottom: false, "primitive") };
+ var stack = PrismaticSectionStackCompiler.Normalize(new PrismaticProfileCompositionParseResult(composition, new Dictionary<string, ResolvedProfile2D> { [outline.Name] = outline }, []), out var stackDiagnostics);
+ if (stack is null) return Failure(string.Join("; ", stackDiagnostics));
+ var emitted = PrismaticSectionStackEmitter.Emit(stack);
+ if (emitted.Body is null) return Failure(string.Join("; ", emitted.Diagnostics));
+ return KernelResult<ThinWalledBodyRealization>.Success(new ThinWalledBodyRealization(feature, construction, plan, BrepSplitFaceMerge.Merge(emitted.Body)));
+ }
+
+ private static ResolvedProfile2D RoundedRectangle(string name, double width, double depth, double radius)
+ {
+ var (x, y, r) = (width / 2d, depth / 2d, radius);
+ LineArcProfileCurve2D[] curves =
+ [
+ new LineArcLineSegment2D((-x + r, -y), (x - r, -y)),
+ new LineArcCircularArc2D((x - r, -y + r), r, -double.Pi / 2d, double.Pi / 2d),
+ new LineArcLineSegment2D((x, -y + r), (x, y - r)),
+ new LineArcCircularArc2D((x - r, y - r), r, 0d, double.Pi / 2d),
+ new LineArcLineSegment2D((x - r, y), (-x + r, y)),
+ new LineArcCircularArc2D((-x + r, y - r), r, double.Pi / 2d, double.Pi / 2d),
+ new LineArcLineSegment2D((-x, y - r), (-x, -y + r)),
+ new LineArcCircularArc2D((-x + r, -y + r), r, double.Pi, double.Pi / 2d),
+ ];
+ return new ResolvedProfile2D(name, "XY", [new ResolvedProfileLoop2D($"{name}.Outer", true, curves.Select((curve, i) =>
+ new ResolvedProfileSegment2D($"{name}.{i}", curve, new ProfileSegmentProvenance($"{name}.{i}", name, "generated", "hollow-primitive", "XY"))).ToArray())]);
+ }
+
+ private static bool FinitePositive(params double[] values) => values.All(v => double.IsFinite(v) && v > Tol);
+ private static KernelResult<ThinWalledBodyRealization> Failure(string code) => KernelResult<ThinWalledBodyRealization>.Failure([new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, code, "ThinWalledBody.Admission")]);
+}
diff --git a/Aetheris.Kernel.Firmament/Materializer/ProfileInset2D.cs b/Aetheris.Kernel.Firmament/Materializer/ProfileInset2D.cs
index f53dcc7c..23da34b0 100644
--- a/Aetheris.Kernel.Firmament/Materializer/ProfileInset2D.cs
+++ b/Aetheris.Kernel.Firmament/Materializer/ProfileInset2D.cs
@@ -1,3 +1,5 @@
+using Aetheris.Kernel.Core.Geometry.Planar;
+
namespace Aetheris.Kernel.Firmament.Materializer;
/// <summary>
@@ -9,22 +11,8 @@ namespace Aetheris.Kernel.Firmament.Materializer;
/// </summary>
public static class ProfileInset2D
{
- private const double Tol = 1e-9;
-
public sealed record InsetResult(ResolvedProfile2D? Profile, IReadOnlyList<string> Diagnostics);
- private abstract record Carrier;
- private sealed record LineCarrier((double X, double Y) Point, (double X, double Y) Direction) : Carrier;
- private sealed record CircleCarrier((double X, double Y) Center, double Radius, bool CounterClockwise) : Carrier;
-
- private sealed class Element(Carrier carrier, (double X, double Y) start, (double X, double Y) end, double originalSweep)
- {
- public Carrier Carrier { get; } = carrier;
- public (double X, double Y) Start { get; set; } = start;
- public (double X, double Y) End { get; set; } = end;
- public double OriginalSweep { get; } = originalSweep;
- }
-
public static InsetResult Inset(PrismaticSectionRegion region, double distance, string name, string context)
{
var diagnostics = new List<string>();
@@ -68,182 +56,34 @@ public static class ProfileInset2D
public static IReadOnlyList<LineArcProfileCurve2D>? InsetLoop(IReadOnlyList<LineArcProfileCurve2D> curves, double distance, bool outer,
string context, List<string> diagnostics)
{
- if (curves.Count == 1 && curves[0] is LineArcFullCircle2D circle)
- {
- var radius = outer ? circle.Radius - distance : circle.Radius + distance;
- if (radius <= Tol) { diagnostics.Add($"hollow-wall-offset-collapse:{context}: a circle of radius {circle.Radius:R} closes at wall {distance:R}"); return null; }
- return [new LineArcFullCircle2D(circle.Center, radius)];
- }
- if (curves.Any(c => c is not (LineArcLineSegment2D or LineArcCircularArc2D)))
+ if (curves.Any(c => c is not (LineArcLineSegment2D or LineArcCircularArc2D or LineArcFullCircle2D)))
{
diagnostics.Add($"hollow-offset-curve-unsupported:{context}: only lines and circular arcs have exact offsets of the same kind");
return null;
}
- // Material on the left: an outer loop runs counter-clockwise, a hole clockwise.
- var oriented = SignedArea(curves) > 0d == outer ? curves : Reverse(curves);
- var elements = new List<Element?>();
- foreach (var curve in oriented)
- {
- switch (curve)
- {
- case LineArcLineSegment2D line:
- {
- var d = Unit(Sub(line.End, line.Start));
- var n = (-d.Y, d.X);
- elements.Add(new Element(new LineCarrier(Add(line.Start, Mul(n, distance)), d),
- Add(line.Start, Mul(n, distance)), Add(line.End, Mul(n, distance)), 0d));
- break;
- }
- case LineArcCircularArc2D arc:
- {
- var ccw = arc.SweepAngleRadians > 0d;
- var radius = ccw ? arc.Radius - distance : arc.Radius + distance;
- if (radius <= Tol) { elements.Add(null); break; }
- var a0 = arc.StartAngleRadians;
- var a1 = a0 + arc.SweepAngleRadians;
- elements.Add(new Element(new CircleCarrier(arc.Center, radius, ccw),
- Polar(arc.Center, radius, a0), Polar(arc.Center, radius, a1), arc.SweepAngleRadians));
- break;
- }
- }
- }
- var count = oriented.Count;
- var kept = Enumerable.Range(0, count).Where(i => elements[i] is not null).ToArray();
- if (kept.Length < 2) { diagnostics.Add($"hollow-wall-offset-collapse:{context}: the loop closes at wall {distance:R}"); return null; }
- var result = new List<LineArcProfileCurve2D>();
- var joins = new (double X, double Y)[kept.Length];
- var reflexArcs = new LineArcCircularArc2D?[kept.Length];
- for (var k = 0; k < kept.Length; k++)
- {
- var i = kept[k];
- var j = kept[(k + 1) % kept.Length];
- var first = elements[i]!;
- var second = elements[j]!;
- var vanishedBetween = (j - i + count) % count != 1;
- var vertex = EndPoint(oriented[i]);
- if (!vanishedBetween)
- {
- var tout = Unit(EndTangent(oriented[i]));
- var tin = Unit(StartTangent(oriented[j]));
- var cross = tout.X * tin.Y - tout.Y * tin.X;
- var dot = tout.X * tin.X + tout.Y * tin.Y;
- if (double.Abs(cross) <= 1e-9 && dot > 0d)
- {
- if (Distance(first.End, second.Start) > 1e-7) { diagnostics.Add($"hollow-wall-offset-collapse:{context}: tangent curves part at the inset"); return null; }
- joins[k] = first.End;
- continue;
- }
- if (double.Abs(cross) <= 1e-9) { diagnostics.Add($"hollow-wall-offset-collapse:{context}: the loop turns back on itself"); return null; }
- if (cross < 0d)
- {
- // Reflex corner: the wall rounds about the corner, keeping its thickness.
- var a0 = double.Atan2(first.End.Y - vertex.Y, first.End.X - vertex.X);
- var a1 = double.Atan2(second.Start.Y - vertex.Y, second.Start.X - vertex.X);
- var sweep = a1 - a0;
- while (sweep >= 0d) sweep -= 2d * double.Pi;
- while (sweep < -2d * double.Pi) sweep += 2d * double.Pi;
- reflexArcs[k] = new LineArcCircularArc2D(vertex, distance, a0, sweep);
- joins[k] = (double.NaN, double.NaN);
- continue;
- }
- }
- var expected = Mid(first.End, second.Start);
- if (!TryIntersect(first.Carrier, second.Carrier, expected, out var point))
- {
- diagnostics.Add($"hollow-wall-offset-collapse:{context}: neighbouring walls no longer meet at the inset");
- return null;
- }
- joins[k] = point;
- }
- for (var k = 0; k < kept.Length; k++)
- {
- var element = elements[kept[k]]!;
- var previous = (k + kept.Length - 1) % kept.Length;
- var start = double.IsNaN(joins[previous].X) ? element.Start : joins[previous];
- var end = double.IsNaN(joins[k].X) ? element.End : joins[k];
- var curve = Trim(element, start, end);
- if (curve is null)
- {
- diagnostics.Add($"hollow-wall-offset-collapse:{context}: curve {kept[k]} reverses at wall {distance:R}; the section is narrower than twice the wall there");
- return null;
- }
- result.Add(curve);
- if (reflexArcs[k] is { } arc) result.Add(arc);
- }
- return result;
+ var core = new List<string>();
+ var inset = LineArcInset.InsetLoop(curves.Select(ToPlanar).ToArray(), distance, outer, context, core);
+ diagnostics.AddRange(core.Select(d => d.StartsWith("inset-", StringComparison.Ordinal) ? "hollow-" + d[6..] : d));
+ return inset?.Select(FromPlanar).ToArray();
}
- private static LineArcProfileCurve2D? Trim(Element element, (double X, double Y) start, (double X, double Y) end)
+ public static PlanarSpan ToPlanar(LineArcProfileCurve2D curve) => curve switch
{
- switch (element.Carrier)
- {
- case LineCarrier line:
- var along = (end.X - start.X) * line.Direction.X + (end.Y - start.Y) * line.Direction.Y;
- return along > 1e-9 ? new LineArcLineSegment2D(start, end) : null;
- case CircleCarrier circle:
- var a0 = double.Atan2(start.Y - circle.Center.Y, start.X - circle.Center.X);
- var a1 = double.Atan2(end.Y - circle.Center.Y, end.X - circle.Center.X);
- var sweep = a1 - a0;
- // The trimmed span is the branch nearest the original one; a different sign means it reversed.
- var best = sweep;
- for (var k = -2; k <= 2; k++)
- if (double.Abs(sweep + 2d * double.Pi * k - element.OriginalSweep) < double.Abs(best - element.OriginalSweep))
- best = sweep + 2d * double.Pi * k;
- if (double.Sign(best) != double.Sign(element.OriginalSweep) || double.Abs(best) <= 1e-9) return null;
- return new LineArcCircularArc2D(circle.Center, circle.Radius, a0, best);
- default:
- return null;
- }
- }
-
- private static bool TryIntersect(Carrier first, Carrier second, (double X, double Y) expected, out (double X, double Y) point)
- {
- var candidates = new List<(double X, double Y)>();
- switch (first, second)
- {
- case (LineCarrier a, LineCarrier b):
- {
- var den = a.Direction.X * b.Direction.Y - a.Direction.Y * b.Direction.X;
- if (double.Abs(den) > 1e-12)
- {
- var w = Sub(b.Point, a.Point);
- var s = (w.X * b.Direction.Y - w.Y * b.Direction.X) / den;
- candidates.Add(Add(a.Point, Mul(a.Direction, s)));
- }
- break;
- }
- case (LineCarrier a, CircleCarrier c): candidates.AddRange(LineCircle(a, c)); break;
- case (CircleCarrier c, LineCarrier a): candidates.AddRange(LineCircle(a, c)); break;
- case (CircleCarrier a, CircleCarrier b): candidates.AddRange(CircleCircle(a, b)); break;
- }
- if (candidates.Count == 0) { point = default; return false; }
- point = candidates.MinBy(c => Distance(c, expected));
- return true;
- }
+ LineArcLineSegment2D line => new PlanarLine(line.Start, line.End),
+ LineArcCircularArc2D arc => new PlanarArc(arc.Center, arc.Radius, arc.StartAngleRadians, arc.SweepAngleRadians),
+ LineArcFullCircle2D circle => new PlanarCircle(circle.Center, circle.Radius),
+ _ => throw new NotSupportedException()
+ };
- private static IEnumerable<(double X, double Y)> LineCircle(LineCarrier line, CircleCarrier circle)
+ public static LineArcProfileCurve2D FromPlanar(PlanarSpan span) => span switch
{
- var w = Sub(line.Point, circle.Center);
- var b = w.X * line.Direction.X + w.Y * line.Direction.Y;
- var c = w.X * w.X + w.Y * w.Y - circle.Radius * circle.Radius;
- var disc = b * b - c;
- if (disc < -1e-12) yield break;
- var root = double.Sqrt(double.Max(0d, disc));
- yield return Add(line.Point, Mul(line.Direction, -b - root));
- yield return Add(line.Point, Mul(line.Direction, -b + root));
- }
+ PlanarLine line => new LineArcLineSegment2D(line.Start, line.End),
+ PlanarArc arc => new LineArcCircularArc2D(arc.Center, arc.Radius, arc.StartAngle, arc.Sweep),
+ PlanarCircle circle => new LineArcFullCircle2D(circle.Center, circle.Radius),
+ _ => throw new NotSupportedException()
+ };
- private static IEnumerable<(double X, double Y)> CircleCircle(CircleCarrier a, CircleCarrier b)
- {
- var d = Distance(a.Center, b.Center);
- if (d < 1e-12 || d > a.Radius + b.Radius + 1e-12 || d < double.Abs(a.Radius - b.Radius) - 1e-12) yield break;
- var x = (d * d + a.Radius * a.Radius - b.Radius * b.Radius) / (2d * d);
- var h = double.Sqrt(double.Max(0d, a.Radius * a.Radius - x * x));
- var u = Mul(Sub(b.Center, a.Center), 1d / d);
- var mid = Add(a.Center, Mul(u, x));
- yield return Add(mid, Mul((-u.Y, u.X), h));
- yield return Add(mid, Mul((u.Y, -u.X), h));
- }
+ public static double SignedArea(IReadOnlyList<LineArcProfileCurve2D> curves) => LineArcInset.SignedArea(curves.Select(ToPlanar).ToArray());
private static ResolvedProfileLoop2D Loop(string name, string loop, bool isOuter, IReadOnlyList<LineArcProfileCurve2D> curves) =>
new($"{name}.{loop}", isOuter, curves.Select((curve, i) => new ResolvedProfileSegment2D($"{name}.{loop}.{i}", curve,
@@ -252,67 +92,5 @@ public static class ProfileInset2D
private static IReadOnlyList<LineArcProfileCurve2D> Curves(ResolvedProfile2D profile) =>
profile.Loops[0].Segments.Select(s => s.Geometry).ToArray();
- private static IReadOnlyList<LineArcProfileCurve2D> Reverse(IReadOnlyList<LineArcProfileCurve2D> curves) =>
- curves.Reverse().Select(c => c switch
- {
- LineArcLineSegment2D line => (LineArcProfileCurve2D)new LineArcLineSegment2D(line.End, line.Start),
- LineArcCircularArc2D arc => new LineArcCircularArc2D(arc.Center, arc.Radius, arc.StartAngleRadians + arc.SweepAngleRadians, -arc.SweepAngleRadians),
- _ => c
- }).ToArray();
-
- public static double SignedArea(IReadOnlyList<LineArcProfileCurve2D> curves)
- {
- var sum = 0d;
- foreach (var curve in curves)
- sum += curve switch
- {
- LineArcLineSegment2D line => line.Start.X * line.End.Y - line.End.X * line.Start.Y,
- LineArcCircularArc2D arc => ArcDoubleArea(arc),
- LineArcFullCircle2D circle => 2d * double.Pi * circle.Radius * circle.Radius,
- _ => 0d
- };
- return sum / 2d;
- }
-
- private static double ArcDoubleArea(LineArcCircularArc2D arc)
- {
- var a = arc.StartAngleRadians; var b = a + arc.SweepAngleRadians; var r = arc.Radius; var (x, y) = arc.Center;
- return x * r * (double.Sin(b) - double.Sin(a)) - y * r * (double.Cos(b) - double.Cos(a)) + r * r * (b - a);
- }
-
- private static (double X, double Y) StartPoint(LineArcProfileCurve2D curve) => curve switch
- {
- LineArcLineSegment2D line => line.Start,
- LineArcCircularArc2D arc => Polar(arc.Center, arc.Radius, arc.StartAngleRadians),
- LineArcFullCircle2D circle => (circle.Center.X + circle.Radius, circle.Center.Y),
- _ => throw new NotSupportedException()
- };
- private static (double X, double Y) EndPoint(LineArcProfileCurve2D curve) => curve switch
- {
- LineArcLineSegment2D line => line.End,
- LineArcCircularArc2D arc => Polar(arc.Center, arc.Radius, arc.StartAngleRadians + arc.SweepAngleRadians),
- _ => throw new NotSupportedException()
- };
- private static (double X, double Y) StartTangent(LineArcProfileCurve2D curve) => curve switch
- {
- LineArcLineSegment2D line => Sub(line.End, line.Start),
- LineArcCircularArc2D arc => ArcTangent(arc, arc.StartAngleRadians),
- _ => throw new NotSupportedException()
- };
- private static (double X, double Y) EndTangent(LineArcProfileCurve2D curve) => curve switch
- {
- LineArcLineSegment2D line => Sub(line.End, line.Start),
- LineArcCircularArc2D arc => ArcTangent(arc, arc.StartAngleRadians + arc.SweepAngleRadians),
- _ => throw new NotSupportedException()
- };
- private static (double X, double Y) ArcTangent(LineArcCircularArc2D arc, double angle) =>
- Mul((-double.Sin(angle), double.Cos(angle)), double.Sign(arc.SweepAngleRadians));
-
- private static (double X, double Y) Polar((double X, double Y) c, double r, double a) => (c.X + r * double.Cos(a), c.Y + r * double.Sin(a));
- private static (double X, double Y) Add((double X, double Y) a, (double X, double Y) b) => (a.X + b.X, a.Y + b.Y);
- private static (double X, double Y) Sub((double X, double Y) a, (double X, double Y) b) => (a.X - b.X, a.Y - b.Y);
- private static (double X, double Y) Mul((double X, double Y) a, double s) => (a.X * s, a.Y * s);
- private static (double X, double Y) Mid((double X, double Y) a, (double X, double Y) b) => ((a.X + b.X) / 2d, (a.Y + b.Y) / 2d);
- private static double Distance((double X, double Y) a, (double X, double Y) b) => double.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y));
- private static (double X, double Y) Unit((double X, double Y) v) { var l = double.Sqrt(v.X * v.X + v.Y * v.Y); return (v.X / l, v.Y / l); }
+ private static (double X, double Y) StartPoint(LineArcProfileCurve2D curve) => LineArcInset.StartPoint(ToPlanar(curve));
}
diff --git a/docs/development/reports/2026-11/HOLLOW-GENERALIZATION.md b/docs/development/reports/2026-11/HOLLOW-GENERALIZATION.md
index 4f10b315..b1eb96e0 100644
--- a/docs/development/reports/2026-11/HOLLOW-GENERALIZATION.md
+++ b/docs/development/reports/2026-11/HOLLOW-GENERALIZATION.md
@@ -131,8 +131,51 @@ valid solids in OCCT, with volumes equal to closed forms (35369.8, 26302.9, 8127
the bespoke `RoundedBox<Hollow>` planner's volume exactly (26 faces there, 27 here: the stack splits the outer walls
at the floor level).
+## Phase 3: primitives retired, Revolve<Hollow>
+
+- The inset moved to Core as `LineArcInset`, the one offset authority. `ProfileInset2D` adapts Firmament profiles
+ to it and keeps the region-level checks that need the arrangement.
+- `MeridianHollow`: the full axial section is the meridian and its mirror; its inset, cut back to the half-plane,
+ is the cavity. An open cap is pushed out by 2t along the straight wall reaching it before the inset, and the
+ cavity is cut at the cap's plane, so the opening is exact.
+- `BrepRevolvedShell`: a full turn of a closed line/arc meridian with no seam edges. Every face is bounded by the
+ circles its span's endpoints sweep. Only radial spans may meet the axis. This is the topology the bespoke
+ frustum and cylinder builders hand-wrote.
+- `ThinWalledBodyBRepPlanner.CreateFrustum` and `CreateCylinder` (with or without the bottom blend) keep their
+ admission and witnesses but take their bodies from `MeridianHollow` + `BrepRevolvedShell`. The four hand-written
+ builders are deleted. `RoundedBox<Hollow>` moved to `HollowPrimitives.RoundedBox` on the section stack.
+- `Revolve<Hollow>` (`wallThickness`, `openings`, full turn only) maps the Profile into the meridian about its
+ axis and takes the same route.
+
+Evidence: the frustum cups, the cylinder body and the blended utensil holder rebuild with face counts and OCCT
+volumes identical to the bespoke builders; the rounded enclosures keep their volumes (27 faces instead of 26: the
+stack splits the outer walls at the floor level, and `BrepSplitFaceMerge` leaves that body as it is). The bottle and
+sleeve match Pappus volumes computed independently (shapely, 512-segment round erosion) to 6 figures.
+
+A third defect surfaced in the round trip: the STEP importer decided a cylinder's or cone's face side from a loop
+running once round it as if the face always lay on the loop's +v side. That holds for an upright cup's cone, not
+for a bottle's shoulder, whose cone opens downward; the reimported bottle measured 42515 mm³ for 22658. With
+another loop on the face, the importer now takes the side from where that loop lies. Five NIST files re-hash; each
+kernel volume moves towards OCCT's:
+
+| File | Before | After | OCCT |
+| --- | --- | --- | --- |
+| FTC-08 | 505510.6 | 503678.9 | 503633.0 |
+| FTC-11 | 6861.5 | 5271.3 | 5135.1 |
+| STC-10 | 200664.9 | 190412.0 | 188312.8 |
+| CTC-05 | 4837978.1 | 9277231.0 | 12694917.8 |
+| STC-06 | 94655.2 | 179703.7 | 3323540.5 |
+
+CTC-05 and STC-06 are still far from OCCT (STC-06 by a factor of 18), so their kernel volumes have another defect; it is not chased here.
+
+Found, not caused here: the perforated blended utensil holder (`ordning-utensil-holder-blended`) exports with OCCT
+volume −21002 mm³, before and after this change. Its shell is inside out; the Perforation radial-cut builder owns that
+topology.
+
## Next
-Phase 3 (desugaring `RoundedBox`/`Cylinder<Hollow>` and retiring their planners) is coupled to Perforation, which
-consumes `ThinWalledBodyRealization` directly; it moves with Perforation onto section stacks. `Revolve<Hollow>`
-needs the revolve emitter to accept an axis-touching meridian. Phases 4 and 5 as planned.
+- Closed vessels: the cavity is a second shell; the section stack and the revolved shell both need void shells.
+- Apexes and poles in `BrepRevolvedShell` (pointed cones, domed bottoms).
+- Perforation onto the general hollow body instead of its own cylinder builder, which would also retire the
+ inside-out shell above.
+- Phases 4 and 5 as planned.
diff --git a/docs/public/firmament/revolve.md b/docs/public/firmament/revolve.md
index 8cd0a12f..b1d25538 100644
--- a/docs/public/firmament/revolve.md
+++ b/docs/public/firmament/revolve.md
@@ -49,6 +49,40 @@ Model RevolvedSphere {
Pipeline endpoint links prefer `from`/`to`, with `From`/`To` retained as aliases.
See [Writing Firmament](syntax.md) for the distinction from fields such as `from:`.
+## Hollow revolutions
+
+`Revolve<Hollow>` turns a solid meridian into a constant-wall shell of
+revolution. The meridian closes along the axis; `openings` names the flat end
+caps (`Top` is the end farthest along the axis direction) that the cavity runs
+out through.
+
+```firmament
+Model Bottle {
+ units: mm
+ Axis spindle { origin: [0mm, 0mm, 0mm]; direction: [0, 0, 1] }
+ Concept Struct meridian on XZ {
+ Polygon2 section { points: [[0mm, 0mm], [30mm, 0mm], [32mm, 40mm], [14mm, 58mm], [14mm, 75mm], [0mm, 75mm]] }
+ }
+ Profile outline using meridian { Loop Outer { section |> TraceLoop } }
+ Revolve<Hollow> body { profile: outline; about: spindle; angle: full; wallThickness: 1.5mm; openings: [Top] }
+}
+```
+
+- The wall is exact: every face of revolution has a partner at the wall
+ thickness (plane to plane, cylinder to cylinder, cone to a cone of the same
+ angle, torus to a torus with the same centre circle).
+- Outer meridian corners keep their arcs concentric; inside corners get an
+ inner round so the wall stays constant.
+- `[Top, Bottom]` makes a sleeve.
+- An open end must be a flat cap reached by a straight wall.
+- The angle must be `full`.
+- A meridian that runs to a point on the axis (a cone tip or a sphere pole) is
+ refused (`revolve-shell-apex-unsupported`). So is a closed vessel with no
+ opening.
+
+`Cylinder<Hollow>` and `Frustum<Hollow>` are built through this route, and
+`RoundedBox<Hollow>` through the hollow section stack.
+
## Angles
Radians are dimensionless numeric values. Degree literals use `deg`. The lowercase semantic aliases `quarter`, `half`, and `full` mean π/2, π, and 2π. All forms lower through one angle path.
diff --git a/docs/public/reference/language/solids-and-features.md b/docs/public/reference/language/solids-and-features.md
index 52d0291e..23f66b9d 100644
--- a/docs/public/reference/language/solids-and-features.md
+++ b/docs/public/reference/language/solids-and-features.md
@@ -103,6 +103,9 @@ Model EnclosureLid {
- `openings` lists the end caps the cavity runs out through: `[Top]`, `[Bottom]`
or `[Top, Bottom]` for a tube. Cut other openings with `Modify` features.
+For bodies of revolution, see
+[`Revolve<Hollow>`](../../firmament/revolve.md#hollow-revolutions).
+
The build refuses a section narrower than twice the wall
(`hollow-wall-offset-collapse`, naming the band and loop), a Profile with
ellipse or Bézier spans (`hollow-offset-curve-unsupported`), and a body with no
diff --git a/docs/public/reference/supported-features.md b/docs/public/reference/supported-features.md
index 2ff472c6..9cc2b741 100644
--- a/docs/public/reference/supported-features.md
+++ b/docs/public/reference/supported-features.md
@@ -30,7 +30,7 @@
| `AddOffset<Prism>` / `RemoveOffset<Prism>` | Bounded (Prism subset) | Explicit active Compose target, closed Profile tool, whole Top or bounded `Span<Plane>` support, `+Z` direction; Add uses positive Height, Remove uses positive Depth or ThroughAll; edge-crossing removals allowed on whole Top; Cylinder/Sphere deferred and rejected typed |
| Lower-level profile composition | Bounded | Existing prismatic `Compose` `Add`/`Remove` remains compatible for bounded blockout authoring |
| Semantic holes, slots, patterns | Bounded | Qualified shaft/counterbore/countersink and finite static pattern routes; no stable generated-instance selector |
-| Edge finishes/hollow/lattice | Bounded | Documented admitted chamfer/fillet, hollow, and cubic-truss routes; not arbitrary topology. `Compose<Hollow>` and `Extrude<Hollow>` hollow any line/arc section stack at constant wall with Top and/or Bottom openings; see [Hollow bodies](language/solids-and-features.md#hollow-bodies) |
+| Edge finishes/hollow/lattice | Bounded | Documented admitted chamfer/fillet, hollow, and cubic-truss routes; not arbitrary topology. `Compose<Hollow>` and `Extrude<Hollow>` hollow any line/arc section stack, and `Revolve<Hollow>` any full-turn line/arc meridian with flat axis caps, at constant wall with Top and/or Bottom openings; see [Hollow bodies](language/solids-and-features.md#hollow-bodies) |
| Templates/Records/Static/Tables | Supported | Typed compile-time specialization, finite data, `with`, and `Require` |
| STEP AP242 export | Bounded | Deterministic single-body routes plus semantic PMI; unsupported intent fails loudly |
| Exact face graft / subdivision sculpting | Bounded | Native planar four-line face replacement by an outward bicubic graph; explicit box/sphere quad cages, Catmull-Clark refinement, creases, protected vertices, movement and scaling. MeshState exports STL/GLB with replay/provenance sidecars, never STEP; arbitrary BRep retopology and global mesh self-intersection proof are not implemented. See [sculpting](../firmament/sculpting.md). |
diff --git a/fixtures/Canonical/Hollow/bottle-revolve.firmament b/fixtures/Canonical/Hollow/bottle-revolve.firmament
new file mode 100644
index 00000000..921d778c
--- /dev/null
+++ b/fixtures/Canonical/Hollow/bottle-revolve.firmament
@@ -0,0 +1,11 @@
+// A turned bottle: drafted body, conical shoulder, straight neck open at the top.
+// The wall is the meridian inset at constant thickness and turned into a seamless shell.
+Model Bottle {
+ units: mm
+ Axis spindle { origin: [0mm, 0mm, 0mm]; direction: [0, 0, 1] }
+ Concept Struct meridian on XZ {
+ Polygon2 section { points: [[0mm, 0mm], [30mm, 0mm], [32mm, 40mm], [14mm, 58mm], [14mm, 75mm], [0mm, 75mm]] }
+ }
+ Profile outline using meridian { Loop Outer { section |> TraceLoop } }
+ Revolve<Hollow> body { profile: outline; about: spindle; angle: full; wallThickness: 1.5mm; openings: [Top] }
+}
diff --git a/fixtures/Canonical/Hollow/sleeve-revolve.firmament b/fixtures/Canonical/Hollow/sleeve-revolve.firmament
new file mode 100644
index 00000000..95b5be90
--- /dev/null
+++ b/fixtures/Canonical/Hollow/sleeve-revolve.firmament
@@ -0,0 +1,10 @@
+// The same meridian open at both ends: a sleeve, with no axis-touching face.
+Model Sleeve {
+ units: mm
+ Axis spindle { origin: [0mm, 0mm, 0mm]; direction: [0, 0, 1] }
+ Concept Struct meridian on XZ {
+ Polygon2 section { points: [[0mm, 0mm], [30mm, 0mm], [32mm, 40mm], [14mm, 58mm], [14mm, 75mm], [0mm, 75mm]] }
+ }
+ Profile outline using meridian { Loop Outer { section |> TraceLoop } }
+ Revolve<Hollow> body { profile: outline; about: spindle; angle: full; wallThickness: 1.5mm; openings: [Top, Bottom] }
+}
diff --git a/fixtures/Invalid/Hollow/revolve-partial-turn.firmament b/fixtures/Invalid/Hollow/revolve-partial-turn.firmament
new file mode 100644
index 00000000..0f523547
--- /dev/null
+++ b/fixtures/Invalid/Hollow/revolve-partial-turn.firmament
@@ -0,0 +1,10 @@
+// A hollow revolve turns a full revolution.
+Model HalfCup {
+ units: mm
+ Axis spindle { origin: [0mm, 0mm, 0mm]; direction: [0, 0, 1] }
+ Concept Struct meridian on XZ {
+ Polygon2 section { points: [[0mm, 0mm], [30mm, 0mm], [30mm, 40mm], [0mm, 40mm]] }
+ }
+ Profile outline using meridian { Loop Outer { section |> TraceLoop } }
+ Revolve<Hollow> body { profile: outline; about: spindle; angle: half; wallThickness: 1.5mm; openings: [Top] }
+}
diff --git a/fixtures/Invalid/Hollow/revolve-pointed-tip.firmament b/fixtures/Invalid/Hollow/revolve-pointed-tip.firmament
new file mode 100644
index 00000000..10b620a4
--- /dev/null
+++ b/fixtures/Invalid/Hollow/revolve-pointed-tip.firmament
@@ -0,0 +1,10 @@
+// A cone running to a point on the axis has an apex, which the seamless shell does not build.
+Model PointedCup {
+ units: mm
+ Axis spindle { origin: [0mm, 0mm, 0mm]; direction: [0, 0, 1] }
+ Concept Struct meridian on XZ {
+ Polygon2 section { points: [[0mm, 0mm], [30mm, 40mm], [0mm, 40mm]] }
+ }
+ Profile outline using meridian { Loop Outer { section |> TraceLoop } }
+ Revolve<Hollow> body { profile: outline; about: spindle; angle: full; wallThickness: 1.5mm; openings: [Top] }
+}
diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.json
index 67cd1951..15ec85d5 100644
--- a/testdata/step242/manifests/nist.v0.report.json
+++ b/testdata/step242/manifests/nist.v0.report.json
@@ -97,7 +97,7 @@
"edges": 331,
"faces": 156
},
- "canonicalSha256": "cedca3b92fdd337542d09b1c1037f076aafbac25cce7332225c1e13f1ea11b74"
+ "canonicalSha256": "f93eb4de341d8bc03271498a8f7b31d910af1c4ac76732a7e1cc22c73469ed87"
},
{
"fileId": "testdata_step242_nist_FTC_nist_ftc_06_asme1_ap242-e2",
@@ -177,7 +177,7 @@
"edges": 616,
"faces": 247
},
- "canonicalSha256": "e16a234296d3f8dcd35cd0d835f5cac5e1f0ab8d16eb915645a0336a1686a9b6"
+ "canonicalSha256": "34ebf9c91a799b3add82a37f03b9e63ecefbc609006aabf36c7a5e43b1b01b3a"
},
{
"fileId": "testdata_step242_nist_FTC_nist_ftc_09_asme1_ap242-e1",
@@ -237,7 +237,7 @@
"edges": 104,
"faces": 42
},
- "canonicalSha256": "a85cc3381f92b7e484c2f7ebd4d02c0adc371ab0a9ef7150116be3564099689d"
+ "canonicalSha256": "211aef84a6524a25297a4d84c6f6e15dfc847dd26090e13815cd1b2e4be6bd58"
},
{
"fileId": "testdata_step242_nist_STC_nist_stc_06_asme1_ap242-e3",
@@ -257,7 +257,7 @@
"edges": 310,
"faces": 144
},
- "canonicalSha256": "e9392176c0e168443dd5d1a6ec8e8f615209987c04e9a70d52a62e2349beb833"
+ "canonicalSha256": "7fb76c2335ecfca4ebf88bfb08fc57545d9ed884220096ac9bcb4a87c0229827"
},
{
"fileId": "testdata_step242_nist_STC_nist_stc_07_asme1_ap242-e3",
@@ -337,6 +337,6 @@
"edges": 551,
"faces": 256
},
- "canonicalSha256": "b2f3bc168bd85c77cf6b4c0056a9b2b590c2e880524de86a64296746c57d11d9"
+ "canonicalSha256": "999e5873342b098991263c2b9347068803af42e41ca0c368f9726d44cf94eb12"
}
]