Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Firmament authoring conveniences from the CTC-01 decompile

Claude1b4f2ef6a67e
diff --git a/Aetheris.CLI.Tests/AuthoringConvenienceCliTests.cs b/Aetheris.CLI.Tests/AuthoringConvenienceCliTests.cs
new file mode 100644
index 00000000..6acc1703
--- /dev/null
+++ b/Aetheris.CLI.Tests/AuthoringConvenienceCliTests.cs
@@ -0,0 +1,75 @@
+using System.Text.Json;
+using Aetheris.Kernel.Core.Step242;
+
+namespace Aetheris.CLI.Tests;
+
+/// <summary>Small authoring conveniences found while reconstructing NIST CTC-01: trigonometric Statics,
+/// Close after a path that already returns to its start, variant shapes as one-line Profiles, and diagnostics
+/// that explain path and shape errors instead of repeating their codes.</summary>
+public sealed class AuthoringConvenienceCliTests
+{
+ private static readonly string RepoRoot = FindRepoRoot();
+
+ [Fact]
+ public void TrigonometricStaticsResolveToTheDrawingDimension()
+ {
+ var body = BuildAndImport("fixtures/Regression/AuthoringConvenience/trig-statics.firmament");
+ var xs = body.Topology.Vertices.Select(v => body.TryGetVertexPoint(v.Id, out var p) ? p.X : double.NaN).ToArray();
+ // 2·(10/cos30°)·sin60° + 10√2·√2 + 10·tan30°·tan60° = 20 + 20 + 10.
+ Assert.Equal(50d, xs.Max() - xs.Min(), 9);
+ }
+
+ [Fact]
+ public void CloseAfterAnArcIntoTheStartAddsNoEdge()
+ {
+ var body = BuildAndImport("fixtures/Regression/AuthoringConvenience/close-after-arc.firmament");
+ // Four sides, four corner cylinders, top and bottom: no sliver face from a zero-length closing line.
+ Assert.Equal(10, body.Topology.Faces.Count());
+ }
+
+ [Fact]
+ public void VariantShapeBuildsAsAOneLineProfile()
+ {
+ var body = BuildAndImport("fixtures/Regression/AuthoringConvenience/regular-polygon-profile.firmament");
+ Assert.Equal(8, body.Topology.Faces.Count());
+ }
+
+ [Theory]
+ [InlineData("sqrt-negative.firmament", "firmament-v2-expression-unsupported", "outside its domain")]
+ [InlineData("unknown-intrinsic.firmament", "firmament-v2-expression-unsupported", "calls 'Atan', which is not a compile-time intrinsic (Pow, Sqrt, Sin, Cos, Tan)")]
+ [InlineData("zero-length-step.firmament", "concept-path-zero-length:Outline:Back", "Step 'Back' of Path 'Outline' has zero length")]
+ [InlineData("shape-negative-size.firmament", "firmament-boundary2-invalid-dimensions:Plate__Boundary", "Shape 'Plate' has missing or non-positive dimensions")]
+ public void RejectionsExplainThemselves(string file, string code, string message)
+ {
+ var stdout = new StringWriter();
+ var stderr = new StringWriter();
+ var exit = CliRunner.Run(["validate", Path.Combine(RepoRoot, "fixtures/Invalid/AuthoringConvenience", file), "--json"], stdout, stderr);
+ Assert.NotEqual(0, exit);
+ using var document = JsonDocument.Parse(stdout.ToString());
+ var report = document.RootElement.TryGetProperty("firmamentV2Validation", out var nested) ? nested : document.RootElement;
+ var diagnostic = report.GetProperty("diagnostics").EnumerateArray().Single(d => d.GetProperty("code").GetString() == code);
+ var text = diagnostic.GetProperty("message").GetString()!;
+ Assert.Contains(message, text, StringComparison.Ordinal);
+ Assert.NotEqual(code, text);
+ }
+
+ private static Aetheris.Kernel.Core.Brep.BrepBody BuildAndImport(string fixture)
+ {
+ var directory = Path.Combine(Path.GetTempPath(), "aetheris-authoring-convenience", Guid.NewGuid().ToString("N"));
+ Directory.CreateDirectory(directory);
+ var step = Path.Combine(directory, Path.GetFileNameWithoutExtension(fixture) + ".step");
+ var stdout = new StringWriter();
+ var stderr = new StringWriter();
+ Assert.True(CliRunner.Run(["build", Path.Combine(RepoRoot, fixture), "--out", step], stdout, stderr) == 0, $"{fixture}: {stderr}{stdout}");
+ var import = Step242Importer.ImportBody(File.ReadAllText(step));
+ Assert.True(import.IsSuccess, string.Join("; ", import.Diagnostics.Select(d => d.Message)));
+ return import.Value;
+ }
+
+ private static string FindRepoRoot()
+ {
+ var directory = new DirectoryInfo(AppContext.BaseDirectory);
+ while (directory is not null && !File.Exists(Path.Combine(directory.FullName, "Aetheris.slnx"))) directory = directory.Parent;
+ return directory?.FullName ?? throw new InvalidOperationException("Repository root not found.");
+ }
+}
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/ClosedBoundary2Authoring.cs b/Aetheris.Kernel.Firmament/FirmamentV2/ClosedBoundary2Authoring.cs
index 18c0e582..07360374 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/ClosedBoundary2Authoring.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/ClosedBoundary2Authoring.cs
@@ -147,12 +147,14 @@ internal static class ClosedBoundary2Authoring
{ diagnostics.Add(Prefix + "profile-value-header:" + profile.Name!.Text); continue; }
var name = profile.Name!.Text;
string replacement;
- if (profile.Initializer is ObjectSyntax { Name: null, Type: ReferenceSyntax type } value && IsBoundaryType(type.Name.Text))
+ // A variant shape such as RegularPolygon2<6> { ... } parses as an object whose type is a specialization.
+ if (profile.Initializer is ObjectSyntax { Name: null } value
+ && BoundaryValueType(value.Type, out var type, out var typeArguments) && IsBoundaryType(type.Name.Text))
{
var boundaryName = name + "__Boundary";
if (FirmamentSyntaxTraversal.Declarations(syntax).Any(d => d.Name?.Text == boundaryName))
{ diagnostics.Add(Prefix + "duplicate-name:" + boundaryName); continue; }
- var boundary = new DeclarationSyntax(new(type.Name, [], type.Span), new(boundaryName, value.Span),
+ var boundary = new DeclarationSyntax(new(type.Name, typeArguments, value.Type!.Span), new(boundaryName, value.Span),
[], [], null, null, [], null, value.Body, false, value.Span);
replacement = FirmamentSyntaxWriter.Statement(boundary) + $"\nProfile {name} {{ From: {boundaryName}; }}";
}
@@ -167,6 +169,17 @@ internal static class ClosedBoundary2Authoring
return source;
}
+ private static bool BoundaryValueType(ExpressionSyntax? syntax, out ReferenceSyntax type, out IReadOnlyList<ArgumentSyntax> arguments)
+ {
+ (type, arguments) = syntax switch
+ {
+ ReferenceSyntax plain => (plain, []),
+ SpecializationSyntax { Target: ReferenceSyntax generic } specialized => (generic, specialized.Arguments),
+ _ => (null!, [])
+ };
+ return type is not null;
+ }
+
internal static bool IsBoundaryType(string type) => type is "Rect2" or "Square2" or "Circle2" or "Ellipse2" or "Slot2"
or "RoundedRect2" or "SmoothRoundedRect2" or "Triangle2" or "Polygon2" or "RegularPolygon2";
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/ConceptFunctionBinding.cs b/Aetheris.Kernel.Firmament/FirmamentV2/ConceptFunctionBinding.cs
index bc186f15..1a342311 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/ConceptFunctionBinding.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/ConceptFunctionBinding.cs
@@ -26,7 +26,7 @@ internal static partial class ConceptPointAuthoring
var type = FirmamentSyntaxValues.Reference(d.ResultType) ?? "";
var args = d.Parameters.Select(p => (Name: p.Name?.Text ?? "", Type: FirmamentSyntaxValues.Reference(p.Value) ?? "")).ToArray();
if (d.Name is null || d.Type.Arguments.Count != 0 || d.Occurrence || d.Initializer is null || d.Body is not null || d.Modifiers.Count != 0 || d.Clauses.Count != 0 || d.Annotation is not null
- || name is "Pow" or "Sin" or "Cos" or "Point2" or "Point3" || !Allowed(type) || args.Length > 16 || args.Any(a => a.Name.Length == 0 || !Allowed(a.Type))
+ || FirmamentNumericEvaluation.Intrinsics.Contains(name) || name is "Point2" or "Point3" || !Allowed(type) || args.Length > 16 || args.Any(a => a.Name.Length == 0 || !Allowed(a.Type))
|| args.Select(a => a.Name).Distinct().Count() != args.Length || d.Parameters.Any(p => p.Default is not null)
|| !functions.TryAdd(name, new(name, args, type, d.Initializer)))
error("function-definition-invalid", $"Function '{name}' requires unique typed parameters and one expression result (scalar, Point2, Point3 or a declared Record).", d.Span);
@@ -53,7 +53,7 @@ internal static partial class ConceptPointAuthoring
var bodyTree = new DocumentSyntax("function", [new ExpressionStatementSyntax(f.Body, f.Body.Span)], [], f.Body.Span);
if (FirmamentSyntaxTraversal.Expressions(bodyTree).OfType<ReferenceSyntax>().Any(r =>
!f.Parameters.Any(p => p.Name == r.Name.Text) && !functions.ContainsKey(r.Name.Text)
- && r.Name.Text is not ("Point2" or "Point3" or "Sin" or "Cos" or "Pow") && scalars?.IsRecordType(r.Name.Text) != true)) throw new FormatException();
+ && r.Name.Text is not ("Point2" or "Point3") && !FirmamentNumericEvaluation.Intrinsics.Contains(r.Name.Text) && scalars?.IsRecordType(r.Name.Text) != true)) throw new FormatException();
var arguments = f.Parameters.ToDictionary(p => p.Name, p => Placeholder(p.Type, 0), StringComparer.Ordinal);
var body = new FirmamentSyntaxSubstitution(arguments).Expression(f.Body);
var expanded = new Inline(this, new HashSet<string> { f.Name }).Expression(body);
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2DiagnosticAdapter.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2DiagnosticAdapter.cs
index 6ddd17c3..da62f27b 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2DiagnosticAdapter.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2DiagnosticAdapter.cs
@@ -96,6 +96,56 @@ public static class FirmamentV2DiagnosticAdapter
// Producers write "code[:parameters]: explanation"; the explanation is the message.
_ when diagnosticCode.IndexOf(": ", StringComparison.Ordinal) is > 0 and var split && !diagnosticCode[..split].Any(char.IsWhiteSpace)
=> diagnosticCode[(split + 2)..],
+ _ when PathMessage(diagnosticCode) is { } path => path,
+ _ when BoundaryMessage(diagnosticCode) is { } boundary => boundary,
_ => diagnosticCode
};
+
+ // concept-path-<kind>:<path>[:<step>[:detail...]]
+ private static string? PathMessage(string code)
+ {
+ if (!code.StartsWith("concept-path-", StringComparison.Ordinal)) return null;
+ var parts = code.Split(':');
+ var kind = parts[0]["concept-path-".Length..];
+ var path = parts.ElementAtOrDefault(1) ?? "?";
+ var step = parts.ElementAtOrDefault(2);
+ var where = step is null ? $"Path '{path}'" : $"Step '{step}' of Path '{path}'";
+ return kind switch
+ {
+ "zero-length" => $"{where} has zero length: it ends where it starts. Remove it, or end the path one step earlier.",
+ "unknown-target" => $"{where} goes To '{parts.ElementAtOrDefault(3)}', which is not a named point. Use Start, a Concept point, or an earlier step's End.",
+ "length-invalid" => $"{where} needs a positive length.",
+ "turn-and-heading" => $"{where} sets both turn and heading; give one.",
+ "to-mixed-direction-or-length" => $"{where} combines To with a length, turn or heading. To fixes the endpoint, so give it alone.",
+ "field-unknown" => $"{where} has unknown field '{parts.ElementAtOrDefault(3)}'. Allowed: {parts.ElementAtOrDefault(4)?.Replace("allowed=", "", StringComparison.Ordinal).Replace(",", ", ", StringComparison.Ordinal)}.",
+ "duplicate-step" => $"Path '{path}' has two steps named '{step}'. Step names must be unique within a path.",
+ "name-collision" => $"'{path}' is already declared. Path and step names must not collide with other names.",
+ "start-invalid" => $"{where} needs start: Point2(x, y) with lengths.",
+ "heading-invalid" => $"{where} heading must be an angle, for example 90deg.",
+ _ when kind.EndsWith("-invalid", StringComparison.Ordinal) && step is not null
+ => $"{where} is not a valid {kind[..^"-invalid".Length]} step{(parts.Length > 3 ? ": " + string.Join(":", parts[3..]) : ".")}",
+ _ => null
+ };
+ }
+
+ // firmament-boundary2-<reason>:<name>
+ private static string? BoundaryMessage(string code)
+ {
+ const string prefix = "firmament-boundary2-";
+ if (!code.StartsWith(prefix, StringComparison.Ordinal) || code.LastIndexOf(':') is not (> 0 and var colon)) return null;
+ var reason = code[prefix.Length..colon];
+ var name = code[(colon + 1)..];
+ // A one-line Profile is lowered through a generated "<name>__Boundary" shape; report the authored name.
+ if (name.EndsWith("__Boundary", StringComparison.Ordinal)) name = name[..^"__Boundary".Length];
+ return reason switch
+ {
+ "profile-value-unsupported" => $"Profile '{name}' = ... needs a shape value (Rect2, Circle2, Slot2, RoundedRect2, RegularPolygon2<N>, ...) or the name of a closed Path or shape.",
+ "profile-value-header" => $"Profile '{name}' = value takes no type annotation, parameters or clauses.",
+ "duplicate-name" => $"'{name}' is already declared.",
+ "reserved-value-name" => $"'{name}' is reserved for a generated shape name; choose another name.",
+ "variant-unsupported" => $"Shape '{name}' has a variant this shape does not take; only Triangle2, Polygon2 and RegularPolygon2 take <...>.",
+ "invalid-dimensions" => $"Shape '{name}' has missing or non-positive dimensions. Check its required fields and length units.",
+ _ => $"Shape '{name}' is invalid: {reason.Replace('-', ' ')}."
+ };
+ }
}
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2StaticValues.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2StaticValues.cs
index 6a11f40a..8e56903f 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2StaticValues.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2StaticValues.cs
@@ -74,6 +74,13 @@ public static partial class FirmamentV2Parser
}
if (ValueExpression(valueSyntax, type) is { } expression)
declarations.Add(new(d.Name.Text, type, expression, d.Span, tolerance));
+ else if (FirmamentSyntaxTraversal.Expressions(new DocumentSyntax("static", [new ExpressionStatementSyntax(valueSyntax, valueSyntax.Span)], [], valueSyntax.Span))
+ .OfType<CallSyntax>().Select(c => FirmamentSyntaxValues.Reference(c.Target))
+ .FirstOrDefault(n => n is not null && !FirmamentNumericEvaluation.Intrinsics.Contains(n) && n is not ("Point2" or "Point3")) is { } unknown)
+ Error(ExpressionUnsupported, $"Static '{d.Name.Text}' calls '{unknown}', which is not a compile-time intrinsic ({string.Join(", ", FirmamentNumericEvaluation.IntrinsicNames)}) or a declared Function.", valueSyntax.Span, d.Name.Text);
+ else if (FirmamentSyntaxTraversal.Expressions(new DocumentSyntax("static", [new ExpressionStatementSyntax(valueSyntax, valueSyntax.Span)], [], valueSyntax.Span))
+ .OfType<CallSyntax>().Any(c => FirmamentSyntaxValues.Reference(c.Target) is { } n && FirmamentNumericEvaluation.Intrinsics.Contains(n)))
+ Error(ExpressionUnsupported, $"Static '{d.Name.Text}' calls an intrinsic outside its domain or with the wrong units. Pow and Sqrt take unitless numbers (Sqrt of a nonnegative value); Sin, Cos and Tan take an angle such as 60deg (Tan is undefined at 90deg + k*180deg).", valueSyntax.Span, d.Name.Text);
else Error(ExpressionUnsupported, "Expected a typed literal, scalar reference or dimensional arithmetic; tol belongs at the end of a Static initializer.", valueSyntax.Span, d.Name.Text);
}
@@ -172,10 +179,13 @@ public static partial class FirmamentV2Parser
if (e is UnarySyntax { Operator: UnaryOperator.Not } not && ValueExpression(not.Operand, FirmamentV2PrimitiveType.Bool) is { } operand)
return new FirmamentV2UnaryExpression("!", operand, text);
var unit = e is QuantitySyntax q ? q.Unit.Text : e is UnarySyntax { Operand: QuantitySyntax uq } ? uq.Unit.Text : "";
+ // An evaluated value substituted back as a literal keeps the authored span (for example "Sqrt(3)"), so a
+ // literal's Int/Float spelling comes from its own text, not from the span it replaced.
+ var numeral = e is LiteralSyntax { Kind: LiteralKind.Number } numberLiteral ? numberLiteral.Raw : text;
var inferred = unit switch { "mm" => FirmamentV2PrimitiveType.Length, "deg" => FirmamentV2PrimitiveType.Angle, "s" or "ms" => FirmamentV2PrimitiveType.Time,
"" => e is LiteralSyntax { Kind: LiteralKind.Boolean } ? FirmamentV2PrimitiveType.Bool
: e is LiteralSyntax { Kind: LiteralKind.String } ? FirmamentV2PrimitiveType.String
- : text.Contains('.') || text.Contains('e', StringComparison.OrdinalIgnoreCase) ? FirmamentV2PrimitiveType.Float : FirmamentV2PrimitiveType.Int, _ => (FirmamentV2PrimitiveType?)null };
+ : numeral.Contains('.') || numeral.Contains('e', StringComparison.OrdinalIgnoreCase) ? FirmamentV2PrimitiveType.Float : FirmamentV2PrimitiveType.Int, _ => (FirmamentV2PrimitiveType?)null };
if (inferred is null) return null;
if (inferred is FirmamentV2PrimitiveType.String or FirmamentV2PrimitiveType.Bool)
{
@@ -189,7 +199,10 @@ public static partial class FirmamentV2Parser
}
catch (System.Text.Json.JsonException) { return null; }
}
- if (!FirmamentSyntaxValues.TryMeasure(e, inferred == FirmamentV2PrimitiveType.Time ? "s" : unit, out var n) || inferred == FirmamentV2PrimitiveType.Int && (n < int.MinValue || n > int.MaxValue || n != Math.Truncate(n))) return null;
+ if (!FirmamentSyntaxValues.TryMeasure(e, inferred == FirmamentV2PrimitiveType.Time ? "s" : unit, out var n)) return null;
+ // An intrinsic call such as Tan(60deg) has no decimal point in its text but a fractional result.
+ if (inferred == FirmamentV2PrimitiveType.Int && e is CallSyntax && n != Math.Truncate(n)) inferred = FirmamentV2PrimitiveType.Float;
+ if (inferred == FirmamentV2PrimitiveType.Int && (n < int.MinValue || n > int.MaxValue || n != Math.Truncate(n))) return null;
// Float declarations admit integer-written constants, as legacy let did.
if (inferred == FirmamentV2PrimitiveType.Int && expected == FirmamentV2PrimitiveType.Float) inferred = expected;
return new FirmamentV2LiteralExpression(new(inferred.Value, inferred == FirmamentV2PrimitiveType.Int ? (object)(int)n : n, n, inferred == FirmamentV2PrimitiveType.Time ? "s" : unit.Length == 0 ? null : unit, text));
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs
index 17cb74cd..869124a0 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs
@@ -590,6 +590,9 @@ public static class ProfileAuthoringParser
var guideName = $"{name}.{step.Name}";
var endpointName = $"{guideName}.End";
if (guides.ContainsKey(guideName) || points.ContainsKey(endpointName)) { diagnostics.Add($"concept-path-name-collision:{guideName}"); continue; }
+ // A path whose last step already returns to the start needs no closing edge: Close then only marks
+ // the loop closed, adds no segment and names no guide.
+ if (step.Kind == "Close" && path.Steps.Count > 0 && Distance(current, path.Start) <= Tolerance) { points[endpointName] = path.Start; continue; }
if (!TryBindStep(name, step, current, ref heading, path.Start, points, out var curves, out var endpoint, out var diagnostic)) { diagnostics.Add(diagnostic!); continue; }
if (curves!.Count == 1) guides[guideName] = curves[0];
points[endpointName] = endpoint; path.Steps.Add(new BoundPathStep(step.Name, step.Kind == "Line" ? "Span" : step.Kind == "Arc" ? "ArcTransition" : step.Kind, guideName, endpointName, curves, current, endpoint, heading)); current = endpoint;
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/Syntax/FirmamentNumericEvaluation.cs b/Aetheris.Kernel.Firmament/FirmamentV2/Syntax/FirmamentNumericEvaluation.cs
index 6d4fe258..fb2dc670 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/Syntax/FirmamentNumericEvaluation.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/Syntax/FirmamentNumericEvaluation.cs
@@ -8,6 +8,10 @@ internal static partial class FirmamentNumericEvaluation
{
internal readonly record struct Value(double Number, string Unit);
+ /// <summary>Intrinsic functions every compile-time expression may call; Function declarations cannot reuse these names.</summary>
+ internal static readonly IReadOnlyList<string> IntrinsicNames = ["Pow", "Sqrt", "Sin", "Cos", "Tan"];
+ internal static readonly IReadOnlySet<string> Intrinsics = new HashSet<string>(IntrinsicNames, StringComparer.Ordinal);
+
internal static bool TryEvaluate(string source, out Value value,
IReadOnlyDictionary<string, Value>? variables = null,
Func<string, IReadOnlyList<Value>, Value>? functions = null, bool typeOnly = false)
@@ -60,12 +64,19 @@ internal static partial class FirmamentNumericEvaluation
}
if (target.Name.Text == "Pow" && args.Count == 2 && args.All(a => a.Unit.Length == 0))
result = new(typeOnly ? 1 : Math.Pow(args[0].Number, args[1].Number), "");
- else if (target.Name.Text is "Sin" or "Cos" && args.Count == 1 && args[0].Unit is "" or "rad" or "deg")
+ else if (target.Name.Text == "Sqrt" && args.Count == 1 && args[0].Unit.Length == 0)
+ {
+ if (!typeOnly && args[0].Number < 0) return false;
+ result = new(typeOnly ? 1 : Math.Sqrt(args[0].Number), "");
+ }
+ else if (target.Name.Text is "Sin" or "Cos" or "Tan" && args.Count == 1 && args[0].Unit is "" or "rad" or "deg")
{
// Bare numbers and explicit rad quantities are radians. An Angle
// retains its authored unit until this intrinsic consumes it.
var radians = args[0].Unit == "deg" ? args[0].Number * Math.PI / 180 : args[0].Number;
- result = new(typeOnly ? 1 : target.Name.Text == "Sin" ? Math.Sin(radians) : Math.Cos(radians), "");
+ // Tan is undefined at odd multiples of 90°; reject rather than return a huge rounding artifact.
+ if (!typeOnly && target.Name.Text == "Tan" && Math.Abs(Math.Cos(radians)) < 1e-12) return false;
+ result = new(typeOnly ? 1 : target.Name.Text switch { "Sin" => Math.Sin(radians), "Cos" => Math.Cos(radians), _ => Math.Tan(radians) }, "");
}
else if (functions is not null) result = functions(target.Name.Text, args);
else return false;
diff --git a/docs/development/reports/2026-11/CTC-01-DECOMPILE.md b/docs/development/reports/2026-11/CTC-01-DECOMPILE.md
index 493ff0d9..1f9f368c 100644
--- a/docs/development/reports/2026-11/CTC-01-DECOMPILE.md
+++ b/docs/development/reports/2026-11/CTC-01-DECOMPILE.md
@@ -78,6 +78,31 @@ drawing would: plate, lugs, boss, cuts, holes, chamfer.
Not investigated: `analyze section` reports "no bounded geometry" on CTC-01 at z = −75, −55 and −25.
+## Follow-up: items 4–6 and diagnostics fixed
+
+- `Tan` and `Sqrt` join `Pow`, `Sin` and `Cos`. All five now come from one intrinsic list, which Function
+ binding also uses for its reserved names.
+ - Correction to item 4: `Sin` and `Cos` already worked. They passed only because the "deg" in
+ `Sin(60deg)` contains an `e`, which the Static literal sniff reads as Float.
+ - Static typing now takes an evaluated literal's Int/Float spelling from its own text, not from the
+ authored span it replaced. `Sqrt(3)` was typed Int and rejected.
+ - Unknown calls and out-of-domain calls (`Sqrt(-2)`, `Tan(90deg)`) get specific messages.
+- `Close` after a path that already returns to its start adds no edge. It previously failed with
+ `concept-path-zero-length`.
+- `Profile X = RegularPolygon2<N> { … }` builds. One-line Profile values now accept specialized
+ shape types.
+- `concept-path-*` and `firmament-boundary2-*` codes get explanatory messages. The generated
+ `__Boundary` suffix is no longer shown to authors.
+- The CTC-01 fixture now uses `Tan(60deg)`, `Sqrt(2)`, a plain final `Close` and the one-line hexagon. Its
+ geometry is unchanged (IoU 0.9967, 71/85 carriers).
+- Tests: `AuthoringConvenienceCliTests`, with fixtures under `fixtures/Regression/AuthoringConvenience`
+ and `fixtures/Invalid/AuthoringConvenience`.
+
+Found while checking item 3: Paths already have semantic `Chamfer`, `Cutback`, `Step`, `Notch` and `Tab`
+steps, but none are in the public docs. `Notch` is rectangular with sharp corners (width, depth), so
+CTC-01's notches still need a corner radius, and its V-notches a V form with a tip radius. Item 3 is
+better framed as extending these steps than as new path primitives.
+
## Verdict
Meaningful progression. CTC-01 builds with every feature Firmament can express, and the comparison
diff --git a/docs/public/reference/language/README.md b/docs/public/reference/language/README.md
index f9dea467..c855b5d0 100644
--- a/docs/public/reference/language/README.md
+++ b/docs/public/reference/language/README.md
@@ -118,8 +118,11 @@ units optional in every field.
| Volume (assertions) | `mm^3` |
Mixed degree/radian arithmetic needs an explicit conversion; the compiler will
-not add the raw numbers. `Sin` and `Cos` take radians as a bare number, or an
-angle with explicit units, and return a dimensionless value.
+not add the raw numbers. `Sin`, `Cos` and `Tan` take radians as a bare number,
+or an angle with explicit units, and return a dimensionless value; `Tan` rejects
+90deg + k*180deg. `Sqrt(x)` and `Pow(x, y)` take dimensionless values; `Sqrt`
+rejects a negative argument. For example,
+`Static flank: Length = depth / Cos(30deg)`.
Planar points such as a Hole's or Rect2's `center` accept both `Point2(x, y)` and
`[x, y]`, with length coordinates. Arithmetic with dimensional checking is
diff --git a/docs/public/reference/language/profiles.md b/docs/public/reference/language/profiles.md
index 4e06acc5..c3e88b04 100644
--- a/docs/public/reference/language/profiles.md
+++ b/docs/public/reference/language/profiles.md
@@ -27,8 +27,15 @@ Model Plate {
```
This uses the same fields and the same exact boundary as a named `Rect2`,
-`Circle2`, `Slot2` or other closed shape. `Profile copy = outline` derives an
-immutable copy of a named Profile or closed shape.
+`Circle2`, `Slot2` or other closed shape, including variant shapes such as
+`Profile hex = RegularPolygon2<6> { center: [0mm, 0mm]; acrossFlats: 24mm }`.
+`Profile copy = outline` derives an immutable copy of a named Profile or closed
+shape.
+
+A Path's final `Close name` step draws the straight edge back to the start. If
+the steps before it already end at the start (for example, the outline ends with
+an arc into its start point), `Close` adds no edge and only marks the Path
+closed. In that case it names no edge either.
[Sheet metal](../../firmament/sheet-metal.md) consumes the same named Profiles
for its `Base` and `Cut` operations, within its own limits (a rectangular base,
diff --git a/fixtures/Invalid/AuthoringConvenience/shape-negative-size.firmament b/fixtures/Invalid/AuthoringConvenience/shape-negative-size.firmament
new file mode 100644
index 00000000..b1ba4cc1
--- /dev/null
+++ b/fixtures/Invalid/AuthoringConvenience/shape-negative-size.firmament
@@ -0,0 +1,5 @@
+Model ShapeNegativeSize {
+ units: mm
+ Profile Plate = RoundedRect2 { center: [0mm, 0mm]; size: [-10mm, 5mm]; radius: 1mm }
+ Extrude Body { profile: Plate; from: 0mm; to: 2mm }
+}
diff --git a/fixtures/Invalid/AuthoringConvenience/sqrt-negative.firmament b/fixtures/Invalid/AuthoringConvenience/sqrt-negative.firmament
new file mode 100644
index 00000000..9cc3705d
--- /dev/null
+++ b/fixtures/Invalid/AuthoringConvenience/sqrt-negative.firmament
@@ -0,0 +1,5 @@
+Model SqrtNegative {
+ units: mm
+ Static s: Float = Sqrt(-2)
+ Box Body { size: [10mm, 10mm, 10mm] }
+}
diff --git a/fixtures/Invalid/AuthoringConvenience/unknown-intrinsic.firmament b/fixtures/Invalid/AuthoringConvenience/unknown-intrinsic.firmament
new file mode 100644
index 00000000..6b7d6aa7
--- /dev/null
+++ b/fixtures/Invalid/AuthoringConvenience/unknown-intrinsic.firmament
@@ -0,0 +1,5 @@
+Model UnknownIntrinsic {
+ units: mm
+ Static a: Float = Atan(1)
+ Box Body { size: [10mm, 10mm, 10mm] }
+}
diff --git a/fixtures/Invalid/AuthoringConvenience/zero-length-step.firmament b/fixtures/Invalid/AuthoringConvenience/zero-length-step.firmament
new file mode 100644
index 00000000..1be74f60
--- /dev/null
+++ b/fixtures/Invalid/AuthoringConvenience/zero-length-step.firmament
@@ -0,0 +1,13 @@
+Model ZeroLengthStep {
+ units: mm
+ Path Outline {
+ start: Point2(0mm, 0mm)
+ heading: 0deg
+ Line Back { to: Start }
+ Line A { length: 10mm }
+ Line B { turn: 90deg; length: 10mm }
+ Close Done
+ }
+ Profile Tri from Outline
+ Extrude Body { profile: Tri; from: 0mm; to: 2mm }
+}
diff --git a/fixtures/Regression/AuthoringConvenience/close-after-arc.firmament b/fixtures/Regression/AuthoringConvenience/close-after-arc.firmament
new file mode 100644
index 00000000..05533b65
--- /dev/null
+++ b/fixtures/Regression/AuthoringConvenience/close-after-arc.firmament
@@ -0,0 +1,19 @@
+// A rounded-rectangle Path whose last arc returns to its start, so Close adds no edge.
+Model CloseAfterArc {
+ units: mm
+ Path Outline {
+ start: Point2(-15mm, -20mm)
+ heading: 0deg
+ Line Bottom { length: 30mm }
+ Arc BottomRight { radius: 5mm; turn: 90deg }
+ Line Right { length: 30mm }
+ Arc TopRight { radius: 5mm; turn: 90deg }
+ Line Top { length: 30mm }
+ Arc TopLeft { radius: 5mm; turn: 90deg }
+ Line Left { length: 30mm }
+ Arc BottomLeft { radius: 5mm; turn: 90deg }
+ Close Done
+ }
+ Profile Plate from Outline
+ Extrude Body { profile: Plate; from: 0mm; to: 4mm }
+}
diff --git a/fixtures/Regression/AuthoringConvenience/regular-polygon-profile.firmament b/fixtures/Regression/AuthoringConvenience/regular-polygon-profile.firmament
new file mode 100644
index 00000000..b7036981
--- /dev/null
+++ b/fixtures/Regression/AuthoringConvenience/regular-polygon-profile.firmament
@@ -0,0 +1,6 @@
+// A variant shape as a one-line Profile.
+Model RegularPolygonProfile {
+ units: mm
+ Profile Hex = RegularPolygon2<6> { center: [0mm, 0mm]; acrossFlats: 20mm }
+ Extrude Body { profile: Hex; from: 0mm; to: 5mm }
+}
diff --git a/fixtures/Regression/AuthoringConvenience/trig-statics.firmament b/fixtures/Regression/AuthoringConvenience/trig-statics.firmament
new file mode 100644
index 00000000..ff4162b9
--- /dev/null
+++ b/fixtures/Regression/AuthoringConvenience/trig-statics.firmament
@@ -0,0 +1,10 @@
+// Compile-time trigonometry: a 60° V-notch's flank and a square's diagonal, written as the drawing states them.
+Model TrigStatics {
+ units: mm
+ Static depth: Length = 10mm
+ Static flank: Length = depth / Cos(30deg)
+ Static halfMouth: Length = depth * Tan(30deg)
+ Static diagonal: Length = 10mm * Sqrt(2)
+ Static width: Length = 2 * flank * Sin(60deg) + diagonal * Sqrt(2) + halfMouth * Tan(60deg)
+ Box Body { size: [width, 10mm, 10mm] }
+}
diff --git a/fixtures/Regression/Decompile/ctc-01.firmament b/fixtures/Regression/Decompile/ctc-01.firmament
index 5dda8d28..ae7dceb7 100644
--- a/fixtures/Regression/Decompile/ctc-01.firmament
+++ b/fixtures/Regression/Decompile/ctc-01.firmament
@@ -18,23 +18,19 @@ Model Ctc01 {
Construction Plane CenterPlane { Trace: Datums.Center }
Construction Plane MidPlane { Trace: Datums.Midline }
- // V-notch: 60° included angle, R10 tip whose centre is 30 mm in from the edge. Lengths follow from the
- // angle (no trig in Static arithmetic, so tan 60° is written as Pow(3, 0.5)).
- Static root3: Float = Pow(3, 0.5)
+ // V-notch: 60° included angle, R10 tip whose centre is 30 mm in from the edge. Lengths follow from the angle.
Static vTip: Length = 10mm
Static vTipCentre: Length = 30mm
- Static vHalfMouth: Length = (vTipCentre + 2 * vTip) / root3
- Static vFlank: Length = (vTipCentre + vTip / 2) * 2 / root3
+ Static vHalfMouth: Length = (vTipCentre + 2 * vTip) / Tan(60deg)
+ Static vFlank: Length = (vTipCentre + vTip / 2) * 2 / Tan(60deg)
Static vX: Length = 110mm
- Static chamfer: Length = 50mm * Pow(2, 0.5)
+ Static chamfer: Length = 50mm * Sqrt(2)
// Plate silhouette, counterclockwise from the bottom-left lug. The long edges carry two 60° V-notches
// (y = -125, R10 tips at x = ±110) and two rectangular notches (y = +125, 85 wide, 25 deep, R10 corners).
Path Outline {
- start: Point2(-400mm, 0mm)
- heading: -90deg
- Line EndLeftLower { length: 175mm }
- Arc LugOuterFrontLeft { radius: 50mm; turn: 90deg }
+ start: Point2(-350mm, -225mm)
+ heading: 0deg
Line LugFootLeft { length: 50mm }
Arc LugCornerLeft { radius: 50mm; turn: 90deg }
Line LugInnerLeft { length: 25mm }
@@ -77,7 +73,9 @@ Model Ctc01 {
Arc LugCornerBackLeft { radius: 50mm; turn: 90deg }
Line LugFootBackLeft { length: 50mm }
Arc LugOuterBackLeft { radius: 50mm; turn: 90deg }
- Close EndLeftUpper
+ Line EndLeft { length: 350mm }
+ Arc LugOuterFrontLeft { radius: 50mm; turn: 90deg }
+ Close Done
}
Profile Plate from Outline
@@ -108,10 +106,7 @@ Model Ctc01 {
}
Profile LugBackRight from LugChamferedPath
- Concept Struct BossLayout on XY {
- RegularPolygon2<6> Hexagon { center: [0mm, 0mm]; acrossFlats: 100mm; rotation: 30deg }
- }
- Profile HexBoss using BossLayout { Loop Outer { Hexagon |> TraceLoop } }
+ Profile HexBoss = RegularPolygon2<6> { center: [0mm, 0mm]; acrossFlats: 100mm; rotation: 30deg }
Profile Obround = Slot2 { center: [-285mm, 0mm]; length: 120mm; width: 40mm }
Profile Window = RoundedRect2 { center: [285mm, 0mm]; size: [100mm, 50mm]; radius: 10mm }