Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
IntelliDraft: line, arc, Axis2 and SmoothRoundedRect2 drafting
Claude05b3f1590e31
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentIntelliDraftTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentIntelliDraftTests.csindex ab0b67e5..11fcc6a4 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentIntelliDraftTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentIntelliDraftTests.cs@@ -63,6 +63,83 @@ public class FirmamentIntelliDraftTestsAssert.True(result.IsSuccess, string.Join(";", result.Diagnostics.Select(d => d.Message)));Assert.Equal(4416, new FirmamentMeasurements(result.Value).Volume().ValueMm3!.Value, 6);}+ [Fact]+ public void SmoothRoundedRectangleIsADrawableShapeWithItsCornerExtent()+ {+ var draft = new Draft(); draft.Add(new("layout", Name: "layout"));+ draft.Add(new("shape", draft.Id("layout"), "outline", Kind: "SmoothRoundedRect2", Width: 40, Height: 20, Radius: 5));+ Assert.Contains("SmoothRoundedRect2 outline { center: [0mm, 0mm]; size: [40mm, 20mm]; cornerExtent: 5mm }", draft.Source);+ var shape = Assert.Single(draft.View.Shapes);+ Assert.Equal(["Center X", "Center Y", "Width", "Height", "Corner extent"], shape.Controls.Select(c => c.Label));+ draft.Add(new("trace", draft.Id("layout"), "section", Trace: [new("outline", WholeLoop: true)]));+ draft.Add(new("extrude", draft.Id("section"), "body", Length: 6));+ var built = FirmamentBuildAndExport.CompileSource(draft.Source);+ Assert.True(built.IsSuccess, string.Join(";", built.Diagnostics.Select(d => d.Message)));+ }++ [Fact]+ public void Axis2IsDeclaredFromTwoDrawnPointsAndProjectedAsAReference()+ {+ var draft = new Draft(); draft.Add(new("layout", Name: "layout"));+ draft.Add(new("axis", draft.Id("layout"), "spine", X: 5, Y: -2, DirectionX: 30, DirectionY: 40));+ Assert.Contains("Axis2 spine { origin: [5mm, -2mm]; direction: [30, 40] }", draft.Source);+ var axis = Assert.Single(draft.View.Axes);+ Assert.Equal("spine", axis.Name); Assert.Equal(draft.Id("layout"), axis.Owner);+ Assert.Equal([5d, -2], axis.Origin); Assert.Equal(0.6, axis.Direction[0], 12); Assert.Equal(0.8, axis.Direction[1], 12);+ Assert.Empty(draft.View.Diagnostics);+ Assert.Throws<FirmamentLanguageEditException>(() => draft.Add(new("axis", draft.Id("layout"), "none", DirectionX: 0, DirectionY: 0)));+ draft.Add(new("shape", draft.Id("layout"), "outline", Kind: "Rect2", Width: 40, Height: 20));+ draft.Add(new("trace", draft.Id("layout"), "section", Trace: [new("outline", WholeLoop: true)]));+ draft.Add(new("extrude", draft.Id("section"), "body", Length: 6));+ var built = FirmamentBuildAndExport.CompileSource(draft.Source);+ Assert.True(built.IsSuccess, string.Join(";", built.Diagnostics.Select(d => d.Message)));+ }++ [Theory]+ [InlineData(true)]+ [InlineData(false)]+ public void LineAndCircleSpansAreClickableAndKeepTheirArcWhenJoinedEitherWay(bool left)+ {+ var draft = new Draft(); draft.Add(new("layout", Name: "layout"));+ foreach (var (name, x, y) in new[] { ("center", 0d, 0d), ("lower", -3d, -4d), ("upper", -3d, 4d) })+ draft.Add(new("point", draft.Id("layout"), name, X: x, Y: y));+ draft.Add(new("circle", draft.Id("layout"), "rim", Radius: 5, From: "center"));+ draft.Add(new("line", draft.Id("layout"), "chord", From: "upper", To: "lower"));+ var spans = draft.View.Spans;+ var chord = Assert.Single(spans, s => s.Reference == "chord");+ Assert.Equal(("upper", "lower"), (chord.From, chord.To));+ // Counter-clockwise arcs: lower→upper passes the right side, upper→lower the left.+ Assert.Equal(2, spans.Count(s => s.Reference == "rim"));+ var arc = Assert.Single(spans, s => s.Reference == "rim" && s.From == (left ? "upper" : "lower"));+ Assert.Equal(left ? 2 * Math.Atan2(4, 3) : 2 * Math.PI - 2 * Math.Atan2(4, 3), arc.Curve.Sweep, 10);+ draft.Add(new("trace", draft.Id("layout"), "section", Trace: [new("chord", chord.From, chord.To, Connect: true), new("rim", arc.From, arc.To, Connect: true)]));+ // Picked clockwise on the left, so it is written counter-clockwise; the arc stays the same one.+ Assert.Contains(left ? "rim from upper to lower as rim |> chord from lower to upper" : "chord from upper to lower as chord |> rim from lower to upper", draft.Source);+ draft.Add(new("extrude", draft.Id("section"), "body", Length: 6));+ var built = FirmamentBuildAndExport.CompileSource(draft.Source);+ Assert.True(built.IsSuccess, string.Join(";", built.Diagnostics.Select(d => d.Message)));+ var traced = Assert.Single(FirmamentSketchService.Project(draft.Source, "draft.firmament", "1").Loops[0].Curves, c => c.Kind == "Arc");+ Assert.Equal(arc.Curve.Sweep, traced.Sweep, 10);+ }++ [Fact]+ public void PickedSpansNeedNoParticularStartOrDirection()+ {+ var draft = new Draft(); draft.Add(new("layout", Name: "layout"));+ foreach (var (name, x, y) in new[] { ("a", 0d, 0d), ("b", 10d, 0d), ("c", 10d, 10d), ("d", 0d, 10d) })+ draft.Add(new("point", draft.Id("layout"), name, X: x, Y: y));+ foreach (var (name, from, to) in new[] { ("bottom", "a", "b"), ("right", "b", "c"), ("top", "c", "d"), ("left", "d", "a") })+ draft.Add(new("line", draft.Id("layout"), name, From: from, To: to));+ // Bottom is listed a→b, but the next pick (left) meets it at a; the picks also run clockwise.+ var picks = new[] { "bottom", "left", "top", "right" }.Select(n => draft.View.Spans.Single(s => s.Reference == n))+ .Select(s => new FirmamentDraftTrace(s.Reference, s.From, s.To, Connect: true)).ToArray();+ draft.Add(new("trace", draft.Id("layout"), "section", Trace: picks));+ draft.Add(new("extrude", draft.Id("section"), "body", Length: 2));+ var built = FirmamentBuildAndExport.CompileSource(draft.Source);+ Assert.True(built.IsSuccess, string.Join(";", built.Diagnostics.Select(d => d.Message)));+ Assert.Equal(200, new FirmamentMeasurements(built.Value).Volume().ValueMm3!.Value, 6);+ }+private sealed class Draft{public string Source = "Model Part { units: mm }";diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentIntelliDraft.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentIntelliDraft.csindex 16f8d641..d02a3b6f 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentIntelliDraft.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentIntelliDraft.cs@@ -15,7 +15,10 @@ public sealed record FirmamentDraftConstruction(IReadOnlyList<FirmamentDraftElempublic IReadOnlyList<FirmamentDraftFrame> Frames { get; init; } = [];public IReadOnlyList<FirmamentSketchShape> Shapes { get; init; } = [];public IReadOnlyList<FirmamentDraftSpan> Spans { get; init; } = [];+ /// <summary>Axis2 declarations in a layout: unbounded reference directions, never traced.</summary>+ public IReadOnlyList<FirmamentDraftAxis> Axes { get; init; } = [];}+public sealed record FirmamentDraftAxis(string Id, string Name, string Owner, double[] Origin, double[] Direction);public sealed record FirmamentDraftSpan(string Id, string Owner, string Reference, string From, string To, FirmamentSketchCurve Curve);public sealed record FirmamentDraftFrame(string Owner, FirmamentSketchFrame Frame);public sealed record FirmamentDraftTrace(string Reference, string? From = null, string? To = null,@@ -25,7 +28,7 @@ public sealed record FirmamentDraftOperation(string Action, string? Parent = nuldouble Radius = 10, double Turn = 0, string? From = null, string? To = null,IReadOnlyList<FirmamentDraftTrace>? Trace = null, string? Field = null, double Value = 0,double Width = 60, double Height = 40, string? Reference = null, double InsetX = 8, double InsetY = 8,- bool SharedInset = true, string? TargetProfile = null);+ bool SharedInset = true, string? TargetProfile = null, double DirectionX = 1, double DirectionY = 0);/// <summary>Bounded source transactions for construction, trace and extrusion. Open construction is/// explicitly not an admitted part. All geometry comes from the existing Profile binding owner.</summary>@@ -42,7 +45,7 @@ public static class FirmamentIntelliDraftreturn new(f.Name.Text, source.Substring(f.Value.Span.Start, f.Value.Span.Length), unit is null ? null : value,unit, unit is not null && FirmamentSketchService.Literal(f.Value));}- var elements = declarations.Where(d => FirmamentSketchService.EditableShapes.Contains(d.Syntax.Type.Name.Text) || d.Syntax.Type.Name.Text is "Model" or "Struct" or "Static" or "Point2" or "Line2" or "Path" or "Line" or "Arc" or "Close" or "Profile" or "Extrude")+ var elements = declarations.Where(d => FirmamentSketchService.EditableShapes.Contains(d.Syntax.Type.Name.Text) || d.Syntax.Type.Name.Text is "Model" or "Struct" or "Static" or "Point2" or "Line2" or "Axis2" or "Path" or "Line" or "Arc" or "Close" or "Profile" or "Extrude").Select(d => new FirmamentDraftElement(d.Id, d.Syntax.Name?.Text ?? d.Id, d.Syntax.Type.Name.Text, d.ParentId,new(d.Syntax.Span.Start, d.Syntax.Span.Length), (d.Syntax.Body?.Statements.OfType<FieldSyntax>() ?? []).Select(Field).Concat(d.Syntax.Initializer is { } initial ? [new FirmamentDraftField("value", source.Substring(initial.Span.Start, initial.Span.Length),@@ -54,7 +57,7 @@ public static class FirmamentIntelliDraft.Select(d => new FirmamentOutlineDiagnostic("error", d.Code, d.Message,d.SourceSpan is { } s ? new(s.Start, s.Length) : null)));if (diagnostics.Count > 0) return new(elements, [], [], diagnostics, "Unresolved");- var duplicate = elements.Where(e => FirmamentSketchService.EditableShapes.Contains(e.Kind) || e.Kind is "Point2" or "Line2" or "Path")+ var duplicate = elements.Where(e => FirmamentSketchService.EditableShapes.Contains(e.Kind) || e.Kind is "Point2" or "Line2" or "Axis2" or "Path").GroupBy(e => e.Name).FirstOrDefault(g => g.Count() > 1);if (duplicate is not null)return new(elements, [], [], [new("error", "draft-guide-ambiguous", $"Construction preview requires an unambiguous guide name: '{duplicate.Key}'.", duplicate.First().Span)], "Unresolved");@@ -79,7 +82,9 @@ public static class FirmamentIntelliDraft}var spans = ProfileAuthoringParser.ConstructionSpans(bound.Points, bound.Guides).Select(s =>{- var owner = elements.FirstOrDefault(e => s.Guide.StartsWith(e.Name + ".", StringComparison.Ordinal) && e.Kind == "Rect2");+ // Rect2 sides, and named Line2 and Circle2 guides, are clickable spans between named points.+ var owner = elements.FirstOrDefault(e => s.Guide.StartsWith(e.Name + ".", StringComparison.Ordinal) && e.Kind == "Rect2"+ || s.Guide == e.Name && e.Kind is "Line2" or "Circle2");var id = s.Guide + ":" + s.From + ":" + s.To;var parentCurve = curves.Single(c => c.Name == s.Guide);return new FirmamentDraftSpan(id, owner?.Id ?? "", s.Guide, s.From, s.To,@@ -87,10 +92,22 @@ public static class FirmamentIntelliDraft}).Where(s => s.Owner.Length > 0).ToArray();return new(elements, bound.Points.Select(p => new FirmamentDraftPoint(p.Key, p.Value.X, p.Value.Y)).ToArray(),curves, diagnostics, diagnostics.Count == 0 ? "ConstructionResolvedNotTraced" : "Unresolved")- { Frames = frames, Shapes = FirmamentSketchService.ConstructionShapes(source, document, "construction"), Spans = spans };+ { Frames = frames, Shapes = FirmamentSketchService.ConstructionShapes(source, document, "construction"), Spans = spans, Axes = Axes(elements) };}public static FirmamentLanguageEdit Edit(string source, string document, string revision, FirmamentDraftOperation request)+ {+ try { return EditOnce(source, document, revision, request); }+ catch (FirmamentLanguageEditException error) when (request is { Action: "trace", Trace: { Count: > 1 } picks }+ && picks.All(t => t.Connect) && error.Message.Contains("outer winding must be CounterClockwise", StringComparison.Ordinal))+ {+ // Edges picked on the canvas carry no intended direction. A clockwise pick order is+ // written in the counter-clockwise order an outer loop requires; the geometry is the same.+ return EditOnce(source, document, revision, request with { Trace = picks.Reverse().ToArray() });+ }+ }++ private static FirmamentLanguageEdit EditOnce(string source, string document, string revision, FirmamentDraftOperation request){var view = Project(source, document);var operations = new List<FirmamentLanguageEditOperation>();@@ -112,7 +129,7 @@ public static class FirmamentIntelliDraftvar shapeOwner = Owner("Struct");var shapeName = Name();if (request.Kind is null || !FirmamentSketchService.EditableShapes.Contains(request.Kind))- throw Refuse("draft-shape-unsupported", "Choose Rect2, Circle2, Ellipse2, Slot2 or RoundedRect2.");+ throw Refuse("draft-shape-unsupported", "Choose Rect2, Circle2, Ellipse2, Slot2, RoundedRect2 or SmoothRoundedRect2.");var centerFields = $"center: [{Mm(request.X)}, {Mm(request.Y)}]";var shapeFields = request.Kind switch{@@ -121,6 +138,7 @@ public static class FirmamentIntelliDraft"Ellipse2" => $"axisLengths: [{Positive(request.Width)}mm, {Positive(request.Height)}mm]","Slot2" => $"length: {Positive(request.Width)}mm; width: {Positive(request.Height)}mm; rotation: {Number(request.Turn)}deg","RoundedRect2" => $"size: [{Positive(request.Width)}mm, {Positive(request.Height)}mm]; radius: {Positive(request.Radius)}mm",+ "SmoothRoundedRect2" => $"size: [{Positive(request.Width)}mm, {Positive(request.Height)}mm]; cornerExtent: {Positive(request.Radius)}mm",_ => throw Refuse("draft-shape-unsupported", "Choose a supported construction shape.")};Insert(shapeOwner.Id, $"{request.Kind} {shapeName} {{ {centerFields}; {shapeFields} }}");@@ -199,6 +217,11 @@ public static class FirmamentIntelliDraftcase "point":Insert(Owner("Struct").Id, $"Point2 {Name()} {{ position: [{Mm(request.X)}, {Mm(request.Y)}] }}");break;+ case "axis":+ if (!double.IsFinite(request.DirectionX) || !double.IsFinite(request.DirectionY) || Math.Abs(request.DirectionX) + Math.Abs(request.DirectionY) < 1e-12)+ throw Refuse("draft-axis-direction", "Draw the axis with two different points.");+ Insert(Owner("Struct").Id, $"Axis2 {Name()} {{ origin: [{Mm(request.X)}, {Mm(request.Y)}]; direction: [{Number(request.DirectionX)}, {Number(request.DirectionY)}] }}");+ break;case "line":Insert(Owner("Struct").Id, $"Line2 {Name()} {{ from: {Point(request.From)}; to: {Point(request.To)} }}");break;@@ -239,6 +262,13 @@ public static class FirmamentIntelliDraftvar entries = request.Trace ?? [];if (entries.Count == 0) throw Refuse("draft-trace-empty", "Add guides in boundary order before tracing.");(double X, double Y)? previous = null;+ (double X, double Y)? At(string? name) => view.Points.Where(p => p.Name == name).Select(p => ((double X, double Y)?)(p.X, p.Y)).FirstOrDefault();+ // The first picked span has no predecessor: run it toward the span picked after it.+ if (entries is [{ Connect: true } first, { Connect: true } second, ..] && At(first.From) is { } a && At(first.To) is { } b+ && At(second.From) is { } c && At(second.To) is { } d+ && (ProfileAuthoringParser.SameConstructionPoint(a, c) || ProfileAuthoringParser.SameConstructionPoint(a, d))+ && !ProfileAuthoringParser.SameConstructionPoint(b, c) && !ProfileAuthoringParser.SameConstructionPoint(b, d))+ previous = b;string Entry(FirmamentDraftTrace entry){if (entry.WholeLoop)@@ -252,7 +282,11 @@ public static class FirmamentIntelliDraft{var start = view.Points.SingleOrDefault(p => p.Name == entry.From); var end = view.Points.SingleOrDefault(p => p.Name == entry.To);if (start is null || end is null) throw Refuse("draft-point-required", "Select a span with named construction endpoints.");- if (previous is { } p && ProfileAuthoringParser.SameConstructionPoint(p, (end.X, end.Y))) (start, end) = (end, start);+ // A circle span is the counter-clockwise arc from its first to its second point.+ // Joining it backwards keeps that arc and traces it clockwise.+ var circle = view.Guides.Any(g => g.Name == entry.Reference && g.Kind == "Circle");+ if (previous is { } p && ProfileAuthoringParser.SameConstructionPoint(p, (end.X, end.Y)))+ { (start, end) = (end, start); if (circle) entry = entry with { Reverse = !entry.Reverse }; }if (previous is { } current && !ProfileAuthoringParser.SameConstructionPoint(current, (start.X, start.Y)))throw Refuse("draft-trace-disconnected", $"'{entry.Reference}' does not join the preceding span. Select a connected span or reorder the trace.");if (entry.Alias is null && entries.Count(e => e.Reference == entry.Reference) > 1)@@ -263,7 +297,7 @@ public static class FirmamentIntelliDraftvar text = entry.Reference;if (entry.From is not null || entry.To is not null) text += $" from {Point(entry.From)} to {Point(entry.To)}";if (entry.Alias is not null) text += " as " + FirmamentLanguageEditService.RequireIdentifier(entry.Alias, "edge alias");- return text + (entry.Reverse ? " |> Reverse" : "");+ return (entry.Reverse ? "Reverse " : "") + text; // prefix form, as in Loop Inner { Reverse a.Bottom |> … }}Profile($"Profile {name} using {owner.Name} {{ Loop Outer {{ {string.Join(" |> ", entries.Select(Entry))}{(entries.Count == 1 && entries[0].WholeLoop ? "" : " |> Close")} }} }}");}@@ -286,6 +320,26 @@ public static class FirmamentIntelliDraft}return result;}+ private static IReadOnlyList<FirmamentDraftAxis> Axes(IReadOnlyList<FirmamentDraftElement> elements)+ {+ static double[]? Pair(FirmamentDraftField? field, string unit)+ {+ var parts = field?.Value.Trim().TrimStart('[').TrimEnd(']').Split(',');+ if (parts is not { Length: 2 }) return null;+ var result = new double[2];+ for (var i = 0; i < 2; i++)+ if (!FirmamentNumericEvaluation.TryEvaluateScalar(parts[i].Trim(), out result[i], out var u) || u != unit) return null;+ return result;+ }+ return elements.Where(e => e.Kind == "Axis2").Select(e =>+ {+ var origin = Pair(e.Fields.FirstOrDefault(f => FirmamentSyntaxFields.SameField(f.Name, "Origin")), "mm");+ var direction = Pair(e.Fields.FirstOrDefault(f => FirmamentSyntaxFields.SameField(f.Name, "Direction")), "");+ if (origin is null || direction is null || Math.Abs(direction[0]) + Math.Abs(direction[1]) < 1e-12) return null;+ var length = Math.Sqrt(direction[0] * direction[0] + direction[1] * direction[1]);+ return new FirmamentDraftAxis(e.Id, e.Name, e.Parent ?? "", origin, [direction[0] / length, direction[1] / length]);+ }).OfType<FirmamentDraftAxis>().ToArray();+ }private static string Number(double value) => double.IsFinite(value) ? value.ToString("R", CultureInfo.InvariantCulture): throw Refuse("draft-number-invalid", "Use a finite dimension or angle.");private static string Positive(double value) => value > 0 ? Number(value) : throw Refuse("draft-size-invalid", "Use a positive dimension.");diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentSketch.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentSketch.csindex 4023d652..4717a3e5 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentSketch.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentSketch.cs@@ -32,7 +32,7 @@ public sealed record FirmamentSketchEditRequest(string Kind, string? Node = null/// Profile resolution and structural transactions. A resolved sketch is deliberately not a built solid.</summary>public static class FirmamentSketchService{- internal static readonly IReadOnlySet<string> EditableShapes = new HashSet<string>(StringComparer.Ordinal) { "Rect2", "Circle2", "Ellipse2", "Slot2", "RoundedRect2" };+ internal static readonly IReadOnlySet<string> EditableShapes = new HashSet<string>(StringComparer.Ordinal) { "Rect2", "Circle2", "Ellipse2", "Slot2", "RoundedRect2", "SmoothRoundedRect2" };private static readonly IReadOnlySet<string> DomainResults = new HashSet<string>(StringComparer.Ordinal);private sealed record Target(string Node, string? Field, ExpressionSyntax Expression, string? Parameter);@@ -191,6 +191,7 @@ public static class FirmamentSketchService"Circle2" => $"diameter: {Length(request.Width)}", "Slot2" => $"length: {Length(request.Width)} width: {Length(request.Height)}","Ellipse2" => $"axisLengths: [{Length(request.Width)}, {Length(request.Height)}]","RoundedRect2" => $"size: [{Length(request.Width)}, {Length(request.Height)}] radius: {Length(Math.Min(request.Width, request.Height) / 8)}",+ "SmoothRoundedRect2" => $"size: [{Length(request.Width)}, {Length(request.Height)}] cornerExtent: {Length(Math.Min(request.Width, request.Height) / 4)}",_ => $"size: [{Length(request.Width)}, {Length(request.Height)}]"};operations.Add(new("insertDeclaration") { Parent = request.Node, Source = $"{request.Shape} {shape} {{ center: [{Length(request.X)}, {Length(request.Y)}] {fields} }}" });@@ -308,7 +309,7 @@ public static class FirmamentSketchService("size", 0) => "Width", ("size", 1) => "Height", ("center", 0) => "Center X", ("center", 1) => "Center Y",("axislengths" or "axes", 0) => "Width", ("axislengths" or "axes", 1) => "Height",("radius", _) => "Radius", ("diameter", _) => "Diameter", ("width", _) => "Width", ("rotation", _) => "Rotation",- ("length", _) => "Overall length", _ => name + (axis is null ? "" : " " + axis)+ ("length", _) => "Overall length", ("cornerextent", _) => "Corner extent", _ => name + (axis is null ? "" : " " + axis)};private static ExpressionSyntax[] Components(ExpressionSyntax expression) => expression switch{diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.csindex 2edbf64f..eef4f745 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs@@ -1125,6 +1125,23 @@ public static class ProfileAuthoringParservar result = new List<(string, string, string, LineArcProfileCurve2D)>();foreach (var (name, geometry) in guides){+ if (geometry is LineArcFullCircle2D circle)+ {+ // Counter-clockwise arcs between consecutive named points on the circle.+ var stops = new List<KeyValuePair<string, (double X, double Y)>>();+ foreach (var point in points.Where(p => OnCircle(p.Value, circle.Center, circle.Radius)).OrderBy(p => p.Key, StringComparer.Ordinal))+ if (!stops.Any(p => Distance(p.Value, point.Value) <= Tolerance)) stops.Add(point);+ if (stops.Count < 2) continue;+ var around = stops.OrderBy(p => Math.Atan2(p.Value.Y - circle.Center.Y, p.Value.X - circle.Center.X)).ToArray();+ for (var i = 0; i < around.Length; i++)+ {+ var diagnostics = new List<string>();+ var next = around[(i + 1) % around.Length];+ var selected = SelectGuide(circle, around[i].Value, next.Value, "CounterClockwise", name, name, diagnostics);+ if (selected is not null && diagnostics.Count == 0) result.Add((name, around[i].Key, next.Key, selected));+ }+ continue;+ }if (geometry is not LineArcLineSegment2D line || Distance(line.Start, line.End) <= Tolerance) continue;var owner = name.Contains('.') ? name[..name.LastIndexOf('.')] : name;var landmarks = new List<KeyValuePair<string, (double X, double Y)>>();diff --git a/Aetheris.Web.Runtime/sdk/src/index.d.ts b/Aetheris.Web.Runtime/sdk/src/index.d.tsindex cf2f8c6f..1d058010 100644--- a/Aetheris.Web.Runtime/sdk/src/index.d.ts+++ b/Aetheris.Web.Runtime/sdk/src/index.d.ts@@ -178,6 +178,8 @@ export interface MeasurementResult {export interface DraftElement { id: string; name: string; kind: string; parent: string | null; span: { start: number; length: number }; fields: readonly { name: string; value: string; number: number | null; unit: string | null; editable: boolean }[] }export interface DraftTrace { reference: string; from?: string; to?: string; alias?: string; reverse?: boolean; connect?: boolean; wholeLoop?: boolean }-export interface DraftOperation { action: 'layout' | 'point' | 'line' | 'circle' | 'path' | 'step' | 'trace' | 'extrude' | 'movePoint' | 'dimension' | 'rectangle' | 'shape' | 'parameter'; width?: number; height?: number; reference?: string; insetX?: number; insetY?: number; sharedInset?: boolean; targetProfile?: string; field?: string; value?: number; parent?: string; name?: string; kind?: string; plane?: string; x?: number; y?: number; length?: number; radius?: number; turn?: number; from?: string; to?: string; trace?: readonly DraftTrace[] }+export interface DraftOperation { action: 'layout' | 'point' | 'line' | 'circle' | 'path' | 'step' | 'trace' | 'extrude' | 'movePoint' | 'dimension' | 'rectangle' | 'shape' | 'parameter' | 'axis'; width?: number; height?: number; reference?: string; insetX?: number; insetY?: number; sharedInset?: boolean; targetProfile?: string; field?: string; value?: number; parent?: string; name?: string; kind?: string; plane?: string; x?: number; y?: number; length?: number; radius?: number; turn?: number; from?: string; to?: string; trace?: readonly DraftTrace[]; /** Axis2 direction; any non-zero vector, written unitless as drawn. */ directionX?: number; directionY?: number }export interface DraftSpan { id: string; owner: string; reference: string; from: string; to: string; curve: SketchCurve }-export interface DraftConstruction { shapes?: readonly SketchShape[]; spans?: readonly DraftSpan[]; frames: readonly { owner: string; frame: NonNullable<SketchProjection['frame']> }[]; elements: readonly DraftElement[]; points: readonly { name: string; x: number; y: number }[]; guides: readonly SketchCurve[]; diagnostics: readonly SketchProjection['diagnostics'][number][]; validationLevel: 'ConstructionResolvedNotTraced' | 'Unresolved' }+/** An Axis2 reference direction in a layout. Unbounded and never traced. */+export interface DraftAxis { id: string; name: string; owner: string; origin: readonly [number, number]; direction: readonly [number, number] }+export interface DraftConstruction { shapes?: readonly SketchShape[]; spans?: readonly DraftSpan[]; axes?: readonly DraftAxis[]; frames: readonly { owner: string; frame: NonNullable<SketchProjection['frame']> }[]; elements: readonly DraftElement[]; points: readonly { name: string; x: number; y: number }[]; guides: readonly SketchCurve[]; diagnostics: readonly SketchProjection['diagnostics'][number][]; validationLevel: 'ConstructionResolvedNotTraced' | 'Unresolved' }diff --git a/docs/public/firmament/sketcher.md b/docs/public/firmament/sketcher.mdindex 047f9a2b..6c301e44 100644--- a/docs/public/firmament/sketcher.md+++ b/docs/public/firmament/sketcher.md@@ -6,43 +6,50 @@ sketch model, browser constraint solver or mesh-to-profile conversion.## Construction, trace, part**IntelliDraft** in the viewport toolbar authors the same retained construction-used in Firmament code. Begin with **Layout** (a Concept Struct on XY, XZ or YZ),-then dimensioned construction shapes. `Rect2` supplies right angles and equal,-parallel opposite sides. Its type and dimensions remain authoritative when-Trace selects material boundary spans from its named edges and corners.--The sidebar's scrollable, searchable shape list selects retained construction.-Its checkboxes show or hide construction in the workspace. Hidden shapes are-excluded from picking and alignment, but their source and any existing traced-Profile remain intact. **Show all** restores visibility; the visibility choice is-local to the open workspace and does not suppress engineering geometry.--Draw a circle, ellipse, slot or rounded rectangle with its palette tool, size it-through the inspector, and drag it into place. **Use whole shape outline** traces-its closed boundary through the existing compiler owner. Slots use overall-length including both round ends; a vertically drawn slot retains a 90 degree-rotation. Rounded rectangles expose their corner radius. Invalid dimensions are-rejected instead of silently clamped.--For an L, draw a rectangle, then enter its exact 60 × 40 mm size and center-(0,0) mm. Draw a second independent rectangle and size it to 52 × 32 mm. Drag it-to align its top and right edges with the first: its center is then (4,4) mm.-Temporary alignment guides help placement; they do not link the shapes. Other-edges and centers can align in the same way. Hold Alt to bypass alignment.-Moving or resizing one rectangle later does not move the other.--Choose **Trace** and select the envelope's bottom and lower-right spans, the-second rectangle's bottom and left edges, and the envelope's upper-left top-span and left edge. **Trace Profile** checks the resulting boundary. Rectangles-remain typed constructions, not authored point lists or meshes. **Use whole-rectangle outline** traces a single full rectangle.--**Shapes** edits exact dimensions. Apply or discard pending fields before-switching tools or building. Draw/drag previews commit on release; Escape-cancels an active gesture. Fit, zoom buttons and middle-drag navigate the canvas.-The drawing palette creates rectangles, circles, ellipses, slots and rounded rectangles. Alignment uses projected-bounds of shapes in the same Concept Struct. It writes independent placement-values, without persistent constraint metadata.+used in Firmament code. A new draft opens ready to draw: the first shape creates+its layout (a Concept Struct on the plane chosen in the toolbar, XY by default).+`Rect2` supplies right angles and equal, parallel opposite sides. Its type and+dimensions remain authoritative when Trace selects boundary spans from its named+edges and corners.++The toolbar draws lines, arcs, rectangles, circles, ellipses, slots and rounded+rectangles. Keys: V select, L line, A arc, R rectangle, C circle, E ellipse,+S slot, U rounded, T trace, F fit, Delete removes the selection, Ctrl+Z / Ctrl+Y+undo and redo, Escape steps back. A tool stays active after drawing and proposes+the next free name (`rect1`, `rect2`, …). Points snap to a grid that follows the+zoom; Alt snaps to 0.1 mm.++- **Line** writes a `Line2` between named points. Ends that land on an existing+ named point (a rectangle corner, another line's end) reuse it; new ends are+ written as `Point2 <line>Start` / `<line>End`. The line menu also declares an+ `Axis2 { origin; direction }`: an unbounded reference direction that is shown+ on the canvas but never traced.+- **Arc** drags from the centre to the start, then clicks the end (15° steps;+ Alt is free). It writes a `Circle2` guide centred on a named point plus the+ named points on it. The arc itself is chosen when tracing: each pair of+ neighbouring points on a circle is a counter-clockwise span.+- The rounded menu also draws `SmoothRoundedRect2` (continuous-curvature+ corners) with its `cornerExtent`.++Selected shapes show their dimensions on the canvas; click one to type a value.+Values driven by an expression are dashed and read-only. Resizing a shape whose+edge is lined up with another shape's edge asks once whether to move that shape+too; nothing is stored, and drags never ask. Rename and Delete act on the selected+shape, line, arc or axis. A shape that is part of the traced outline is not+deleted until the outline is retraced without it.++The sidebar's searchable shape list selects retained construction. Its checkboxes+show or hide construction in the workspace; hidden shapes are excluded from+picking and alignment, but their source and any traced Profile remain intact.+Temporary alignment guides help placement while dragging; they do not link+shapes. Hold Alt to bypass alignment.++Choose **Trace** and click the edges of the outline on the canvas: rectangle+sides, lines and arcs between named points, across shapes. Click order and+direction do not matter; the outline is written counter-clockwise. The sidebar+shows whether the outline is closed. **Use this outline** writes the Profile;+**Use whole shape outline** traces one closed shape. Picks are also available+as a list under **Edges as a list**.Explicit dimension-driven relationships remain optional under **Advanced**.The top-right inset preset intentionally creates expressions and shared inputs;@@ -50,14 +57,12 @@ it is not the default placement behavior. Existing expressions remain read-onlyat their derived controls and are edited through their inputs, never flattenedby a drag.-Named **Point**, **Line**, **Circle** guides and Paths remain under **Advanced**.-They support outlines that closed shapes do not express well. Circle spans select-named start and end points; reversing a trace entry preserves its named source.--Alternatively, create a **Path**, then append named Line or Arc steps with-lengths, radii and signed turns. **Close Path with line** explicitly adds a-closing line. **Trace this Path** resolves that boundary to a Profile. Trace's-**Close** checks an already closed boundary and never supplies a missing edge.+Named **Point**, **Line**, **Circle** guides and Paths remain under **Advanced**,+with a manual guide trace. Alternatively, create a **Path**, then append named+Line or Arc steps with lengths, radii and signed turns. **Close Path with line**+explicitly adds a closing line. **Trace this Path** resolves that boundary to a+Profile. Trace's **Close** checks an already closed boundary and never supplies a+missing edge.Complete examples:@@ -178,15 +183,16 @@ explicitly rejected while those support adapters still assume world XY.## Current boundary-The **Sketch** dimension workspace edits authored Rect2, Circle2, Ellipse2, Slot2 and RoundedRect2 fields+The **Sketch** dimension workspace edits authored Rect2, Circle2, Ellipse2, Slot2, RoundedRect2 and SmoothRoundedRect2 fieldsand displays the resolved line/arc/ellipse/cubic curves of other Profiles.Generated Template/Feature bodies do not become writable source through theirexpanded geometry. Profiles must have an unambiguous authored name in thedocument; edits do not reach into included files.-IntelliDraft currently authors one unambiguous Model, retained Rect2 construction,-named Point2/Line2/Circle2 guides, line/arc Paths, one outer trace and a positive-extrusion. The optional Advanced related-rectangle preset shares a top-right corner with+IntelliDraft currently authors one unambiguous Model, retained closed shapes,+named Point2/Line2/Circle2 guides, Axis2 references, line/arc Paths, one outer+trace and a positive extrusion. Strokes snap to named points, not to arbitrary+intersections; an arc's circle stays a full construction circle. The optional Advanced related-rectangle preset shares a top-right corner withan unrotated rectangle in the same Concept Struct. Its wall/inset values and therectangle dimensions remain compile-time source expressions. Trace selectionuses named landmarks on the compiler's bounded guides; it does not invent