Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Firmament P2: add built-in linear and circular pattern ops

Yuechen Li839c5093cea0
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
index 0e138678..68736f08 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
@@ -234,6 +234,30 @@ public sealed class FirmamentBuildAndExportTests
"cylinder");
}
+ [Fact]
+ public void Run_P2LinearHoleRowExample_Writes_Default_Export_Artifact()
+ {
+ AssertExampleBuildAndExport(
+ "testdata/firmament/examples/p2_linear_hole_row.firmament",
+ "p2_linear_hole_row.step",
+ "hole_marker_1__lin3",
+ 4,
+ "primitive",
+ "cylinder");
+ }
+
+ [Fact]
+ public void Run_P2FlangeBoltCirclePatternExample_Writes_Default_Export_Artifact()
+ {
+ AssertExampleBuildAndExport(
+ "testdata/firmament/examples/p2_flange_bolt_circle_pattern.firmament",
+ "p2_flange_bolt_circle_pattern.step",
+ "bolt_marker_1__cir5",
+ 6,
+ "primitive",
+ "cylinder");
+ }
+
[Fact]
public void Semantic_Placement_Build_Is_Deterministic()
{
@@ -246,6 +270,18 @@ public sealed class FirmamentBuildAndExportTests
Assert.Equal(first.Value.Export.StepText, second.Value.Export.StepText);
}
+ [Fact]
+ public void P2_CircularPattern_Build_Is_Deterministic()
+ {
+ var fullSourcePath = FirmamentCorpusHarness.ResolveFixtureFullPath("testdata/firmament/examples/p2_flange_bolt_circle_pattern.firmament");
+ var first = FirmamentBuildAndExport.Run(fullSourcePath);
+ var second = FirmamentBuildAndExport.Run(fullSourcePath);
+
+ Assert.True(first.IsSuccess);
+ Assert.True(second.IsSuccess);
+ Assert.Equal(first.Value.Export.StepText, second.Value.Export.StepText);
+ }
+
[Fact]
public void Run_UnsupportedBoxWithCylinderHoleFixture_Fails_And_Does_Not_Write_Fallback_Export()
{
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentDocumentCoherenceValidationTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentDocumentCoherenceValidationTests.cs
index 0e0396d7..5b9c9a78 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentDocumentCoherenceValidationTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentDocumentCoherenceValidationTests.cs
@@ -37,6 +37,18 @@ public sealed class FirmamentDocumentCoherenceValidationTests
Assert.True(result.Compilation.IsSuccess);
}
+ [Fact]
+ public void Compiler_Rejects_PatternCircular_With_Unknown_Axis_Root()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/p2_invalid_pattern_unknown_axis.firmament");
+
+ Assert.False(result.Compilation.IsSuccess);
+ var diagnostic = Assert.Single(result.Compilation.Diagnostics);
+ Assert.Equal(
+ $"[{FirmamentDiagnosticCodes.ValidationTargetUnknownSelectorRootFeatureId.Value}] Pattern op 'pattern_circular' at index 2 references unknown selector root feature id 'missing' via field 'axis'.",
+ diagnostic.Message);
+ }
+
[Theory]
[InlineData("testdata/firmament/fixtures/m2a-invalid-add-to-missing-id.firmament", "add", "to", "missing")]
[InlineData("testdata/firmament/fixtures/m2a-invalid-subtract-from-missing-id.firmament", "subtract", "from", "missing")]
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveLoweringTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveLoweringTests.cs
index eda868df..95ef07b8 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveLoweringTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveLoweringTests.cs
@@ -1,5 +1,6 @@
using Aetheris.Kernel.Firmament.Lowering;
using Aetheris.Kernel.Firmament.ParsedModel;
+using System.Linq;
namespace Aetheris.Kernel.Firmament.Tests;
@@ -264,6 +265,23 @@ public sealed class FirmamentPrimitiveLoweringTests
});
}
+ [Fact]
+ public void Compile_Expands_LinearPattern_Into_Repeated_Primitives_With_Deterministic_Ids()
+ {
+ var result = Compile(FirmamentCorpusHarness.ReadFixtureText("testdata/firmament/examples/p2_linear_hole_row.firmament"));
+
+ Assert.True(result.Compilation.IsSuccess);
+ var primitives = result.Compilation.Value.PrimitiveLoweringPlan!.Primitives
+ .Where(p => p.Kind == FirmamentLoweredPrimitiveKind.Cylinder)
+ .OrderBy(p => p.OpIndex)
+ .ToArray();
+ Assert.Equal(4, primitives.Length);
+ Assert.Equal("hole_marker_1", primitives[0].FeatureId);
+ Assert.Equal("hole_marker_1__lin1", primitives[1].FeatureId);
+ Assert.Equal("hole_marker_1__lin2", primitives[2].FeatureId);
+ Assert.Equal("hole_marker_1__lin3", primitives[3].FeatureId);
+ }
+
[Fact]
public void Compile_Lowers_Boolean_Placement_Metadata_Using_Primitive_Placement_Model()
diff --git a/Aetheris.Kernel.Firmament/Diagnostics/FirmamentDiagnosticCodes.cs b/Aetheris.Kernel.Firmament/Diagnostics/FirmamentDiagnosticCodes.cs
index beca80cf..5490a078 100644
--- a/Aetheris.Kernel.Firmament/Diagnostics/FirmamentDiagnosticCodes.cs
+++ b/Aetheris.Kernel.Firmament/Diagnostics/FirmamentDiagnosticCodes.cs
@@ -31,6 +31,10 @@ public static class FirmamentDiagnosticCodes
public static readonly FirmamentDiagnosticCode PlacementUnsupportedSemanticField = new($"{FirmamentDiagnosticConventions.StructurePrefix}-0023");
public static readonly FirmamentDiagnosticCode PlacementInvalidSemanticCombination = new($"{FirmamentDiagnosticConventions.StructurePrefix}-0024");
+ public static readonly FirmamentDiagnosticCode PatternMissingRequiredField = new($"{FirmamentDiagnosticConventions.StructurePrefix}-0025");
+ public static readonly FirmamentDiagnosticCode PatternInvalidFieldTypeOrShape = new($"{FirmamentDiagnosticConventions.StructurePrefix}-0026");
+ public static readonly FirmamentDiagnosticCode PatternInvalidFieldValue = new($"{FirmamentDiagnosticConventions.StructurePrefix}-0027");
+
public static readonly FirmamentDiagnosticCode ReferenceDuplicateFeatureId = new($"{FirmamentDiagnosticConventions.ReferencePrefix}-0001");
public static readonly FirmamentDiagnosticCode ReferenceUnknownFeatureId = new($"{FirmamentDiagnosticConventions.ReferencePrefix}-0002");
public static readonly FirmamentDiagnosticCode ValidationTargetUnknownFeatureId = new($"{FirmamentDiagnosticConventions.ReferencePrefix}-0003");
diff --git a/Aetheris.Kernel.Firmament/FirmamentCompiler.cs b/Aetheris.Kernel.Firmament/FirmamentCompiler.cs
index 94b8b2c7..1f875f11 100644
--- a/Aetheris.Kernel.Firmament/FirmamentCompiler.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentCompiler.cs
@@ -41,6 +41,13 @@ public sealed class FirmamentCompiler
KernelResult<FirmamentCompilationArtifact>.Failure(booleanValidationResult.Diagnostics));
}
+ var patternValidationResult = FirmamentPatternRequiredFieldValidator.Validate(parseResult.Value);
+ if (!patternValidationResult.IsSuccess)
+ {
+ return new FirmamentCompileResult(
+ KernelResult<FirmamentCompilationArtifact>.Failure(patternValidationResult.Diagnostics));
+ }
+
var validationValidationResult = FirmamentValidationRequiredFieldValidator.Validate(parseResult.Value);
if (!validationValidationResult.IsSuccess)
{
diff --git a/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs b/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs
index 869e2c32..7ba8bbea 100644
--- a/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs
+++ b/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs
@@ -152,6 +152,18 @@ internal static class FirmamentCanonicalFormatter
break;
case FirmamentKnownOpKind.ExpectManifold:
break;
+ case FirmamentKnownOpKind.PatternLinear:
+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "source");
+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "count");
+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "step");
+ break;
+ case FirmamentKnownOpKind.PatternCircular:
+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "source");
+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "count");
+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "axis");
+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "angle_degrees");
+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "angle_step_degrees");
+ break;
}
foreach (var pair in entry.RawFields)
diff --git a/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs b/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs
index 0fb4b6f4..cfcff5a2 100644
--- a/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs
+++ b/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs
@@ -12,7 +12,9 @@ public enum FirmamentKnownOpKind
Intersect,
ExpectExists,
ExpectSelectable,
- ExpectManifold
+ ExpectManifold,
+ PatternLinear,
+ PatternCircular
}
internal static class FirmamentKnownOpKinds
@@ -30,7 +32,9 @@ internal static class FirmamentKnownOpKinds
["intersect"] = FirmamentKnownOpKind.Intersect,
["expect_exists"] = FirmamentKnownOpKind.ExpectExists,
["expect_selectable"] = FirmamentKnownOpKind.ExpectSelectable,
- ["expect_manifold"] = FirmamentKnownOpKind.ExpectManifold
+ ["expect_manifold"] = FirmamentKnownOpKind.ExpectManifold,
+ ["pattern_linear"] = FirmamentKnownOpKind.PatternLinear,
+ ["pattern_circular"] = FirmamentKnownOpKind.PatternCircular
};
public static bool TryParse(string opName, out FirmamentKnownOpKind kind) =>
@@ -50,6 +54,8 @@ internal static class FirmamentKnownOpKinds
FirmamentKnownOpKind.ExpectExists => FirmamentOpFamily.Validation,
FirmamentKnownOpKind.ExpectSelectable => FirmamentOpFamily.Validation,
FirmamentKnownOpKind.ExpectManifold => FirmamentOpFamily.Validation,
+ FirmamentKnownOpKind.PatternLinear => FirmamentOpFamily.Pattern,
+ FirmamentKnownOpKind.PatternCircular => FirmamentOpFamily.Pattern,
_ => throw new ArgumentOutOfRangeException(nameof(kind), kind, "Unknown Firmament known op kind.")
};
}
diff --git a/Aetheris.Kernel.Firmament/ParsedModel/FirmamentOpFamily.cs b/Aetheris.Kernel.Firmament/ParsedModel/FirmamentOpFamily.cs
index 37a77f11..8199c410 100644
--- a/Aetheris.Kernel.Firmament/ParsedModel/FirmamentOpFamily.cs
+++ b/Aetheris.Kernel.Firmament/ParsedModel/FirmamentOpFamily.cs
@@ -4,5 +4,6 @@ public enum FirmamentOpFamily
{
Primitive,
Boolean,
- Validation
+ Validation,
+ Pattern
}
diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentDocumentCoherenceValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentDocumentCoherenceValidator.cs
index 997994af..fac76953 100644
--- a/Aetheris.Kernel.Firmament/Validation/FirmamentDocumentCoherenceValidator.cs
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentDocumentCoherenceValidator.cs
@@ -2,6 +2,7 @@ using Aetheris.Kernel.Core.Diagnostics;
using Aetheris.Kernel.Core.Results;
using Aetheris.Kernel.Firmament.Diagnostics;
using Aetheris.Kernel.Firmament.ParsedModel;
+using System.Globalization;
namespace Aetheris.Kernel.Firmament.Validation;
@@ -13,6 +14,7 @@ internal static class FirmamentDocumentCoherenceValidator
var featureIds = new HashSet<string>(StringComparer.Ordinal);
var featureKindsById = new Dictionary<string, FirmamentKnownOpKind>(StringComparer.Ordinal);
+ var featureEntriesById = new Dictionary<string, FirmamentParsedOpEntry>(StringComparer.Ordinal);
var updatedEntries = new List<FirmamentParsedOpEntry>(parsedDocument.Ops.Entries.Count);
for (var index = 0; index < parsedDocument.Ops.Entries.Count; index++)
@@ -31,6 +33,35 @@ internal static class FirmamentDocumentCoherenceValidator
continue;
}
+ if (entry.Family == FirmamentOpFamily.Pattern)
+ {
+ var patternExpansion = ExpandPattern(entry, index, featureIds, featureKindsById, featureEntriesById);
+ if (!patternExpansion.IsSuccess)
+ {
+ return KernelResult<FirmamentParsedDocument>.Failure(patternExpansion.Diagnostics);
+ }
+
+ foreach (var expanded in patternExpansion.Value)
+ {
+ updatedEntries.Add(expanded);
+
+ var expandedFeatureId = expanded.RawFields["id"];
+ if (!featureIds.Add(expandedFeatureId))
+ {
+ return KernelResult<FirmamentParsedDocument>.Failure([
+ CreateDiagnostic(
+ FirmamentDiagnosticCodes.ReferenceDuplicateFeatureId,
+ $"Pattern op '{entry.OpName}' at index {index} produced duplicate feature id '{expandedFeatureId}'.")
+ ]);
+ }
+
+ featureKindsById[expandedFeatureId] = expanded.KnownKind;
+ featureEntriesById[expandedFeatureId] = expanded;
+ }
+
+ continue;
+ }
+
ValidatePlacementSelectorReference(entry, index, featureIds, featureKindsById, out var placementDiagnostic);
if (placementDiagnostic is not null)
{
@@ -64,6 +95,7 @@ internal static class FirmamentDocumentCoherenceValidator
}
featureKindsById[featureId] = entry.KnownKind;
+ featureEntriesById[featureId] = entry;
}
var updatedDocument = parsedDocument with
@@ -74,6 +106,267 @@ internal static class FirmamentDocumentCoherenceValidator
return KernelResult<FirmamentParsedDocument>.Success(updatedDocument);
}
+ private static KernelResult<IReadOnlyList<FirmamentParsedOpEntry>> ExpandPattern(
+ FirmamentParsedOpEntry patternEntry,
+ int opIndex,
+ HashSet<string> featureIds,
+ IReadOnlyDictionary<string, FirmamentKnownOpKind> featureKindsById,
+ IReadOnlyDictionary<string, FirmamentParsedOpEntry> featureEntriesById)
+ {
+ var sourceId = patternEntry.RawFields["source"];
+ if (!featureIds.Contains(sourceId) || !featureEntriesById.TryGetValue(sourceId, out var sourceEntry))
+ {
+ return KernelResult<IReadOnlyList<FirmamentParsedOpEntry>>.Failure([
+ CreateDiagnostic(
+ FirmamentDiagnosticCodes.ReferenceUnknownFeatureId,
+ $"Pattern op '{patternEntry.OpName}' at index {opIndex} references unknown feature id '{sourceId}' via field 'source'.")
+ ]);
+ }
+
+ if (sourceEntry.Family is not (FirmamentOpFamily.Primitive or FirmamentOpFamily.Boolean))
+ {
+ return KernelResult<IReadOnlyList<FirmamentParsedOpEntry>>.Failure([
+ CreateDiagnostic(
+ FirmamentDiagnosticCodes.PatternInvalidFieldValue,
+ $"Pattern op '{patternEntry.OpName}' at index {opIndex} uses unsupported source feature id '{sourceId}' from op family '{sourceEntry.Family}'.")
+ ]);
+ }
+
+ if (!int.TryParse(patternEntry.RawFields["count"], NumberStyles.Integer, CultureInfo.InvariantCulture, out var count) || count <= 0)
+ {
+ return KernelResult<IReadOnlyList<FirmamentParsedOpEntry>>.Failure([
+ CreateDiagnostic(
+ FirmamentDiagnosticCodes.PatternInvalidFieldValue,
+ $"Pattern op '{patternEntry.OpName}' at index {opIndex} has invalid field 'count' value; expected an integer value greater than 0.")
+ ]);
+ }
+
+ return patternEntry.KnownKind switch
+ {
+ FirmamentKnownOpKind.PatternLinear => ExpandLinearPattern(patternEntry, sourceEntry, opIndex, count),
+ FirmamentKnownOpKind.PatternCircular => ExpandCircularPattern(patternEntry, sourceEntry, opIndex, count, featureIds, featureKindsById),
+ _ => KernelResult<IReadOnlyList<FirmamentParsedOpEntry>>.Success(Array.Empty<FirmamentParsedOpEntry>())
+ };
+ }
+
+ private static KernelResult<IReadOnlyList<FirmamentParsedOpEntry>> ExpandLinearPattern(
+ FirmamentParsedOpEntry patternEntry,
+ FirmamentParsedOpEntry sourceEntry,
+ int opIndex,
+ int count)
+ {
+ if (!TryParseNumericVector(patternEntry.RawFields["step"], out var step) || step.Count != 3)
+ {
+ return KernelResult<IReadOnlyList<FirmamentParsedOpEntry>>.Failure([
+ CreateDiagnostic(
+ FirmamentDiagnosticCodes.PatternInvalidFieldTypeOrShape,
+ $"Pattern op '{patternEntry.OpName}' at index {opIndex} has invalid field 'step'; expected exactly 3 numeric components.")
+ ]);
+ }
+
+ var expanded = new List<FirmamentParsedOpEntry>(count);
+ var chainReferenceId = sourceEntry.RawFields["id"];
+ for (var i = 1; i <= count; i++)
+ {
+ var instanceId = $"{sourceEntry.RawFields["id"]}__lin{i.ToString(CultureInfo.InvariantCulture)}";
+ var cloned = CloneWithPlacementOffset(
+ sourceEntry,
+ instanceId,
+ step[0] * i,
+ step[1] * i,
+ step[2] * i);
+ cloned = ChainBooleanReferenceIfNeeded(cloned, chainReferenceId);
+ chainReferenceId = cloned.RawFields["id"];
+ expanded.Add(cloned);
+ }
+
+ return KernelResult<IReadOnlyList<FirmamentParsedOpEntry>>.Success(expanded);
+ }
+
+ private static KernelResult<IReadOnlyList<FirmamentParsedOpEntry>> ExpandCircularPattern(
+ FirmamentParsedOpEntry patternEntry,
+ FirmamentParsedOpEntry sourceEntry,
+ int opIndex,
+ int count,
+ HashSet<string> featureIds,
+ IReadOnlyDictionary<string, FirmamentKnownOpKind> featureKindsById)
+ {
+ var axis = patternEntry.RawFields["axis"];
+ if (!TryValidateSelectorReference(
+ axis,
+ featureIds,
+ featureKindsById,
+ $"Pattern op '{patternEntry.OpName}' at index {opIndex}",
+ "axis",
+ out _,
+ out _,
+ out _,
+ out var axisDiagnostic))
+ {
+ return KernelResult<IReadOnlyList<FirmamentParsedOpEntry>>.Failure([axisDiagnostic!]);
+ }
+
+ var hasSpan = patternEntry.RawFields.TryGetValue("angle_degrees", out var spanRaw) && !string.IsNullOrWhiteSpace(spanRaw);
+ var hasStep = patternEntry.RawFields.TryGetValue("angle_step_degrees", out var stepRaw) && !string.IsNullOrWhiteSpace(stepRaw);
+ if (!hasSpan && !hasStep)
+ {
+ return KernelResult<IReadOnlyList<FirmamentParsedOpEntry>>.Failure([
+ CreateDiagnostic(
+ FirmamentDiagnosticCodes.PatternMissingRequiredField,
+ $"Pattern op '{patternEntry.OpName}' at index {opIndex} is missing required field 'angle_degrees'.")
+ ]);
+ }
+
+ if (hasSpan && hasStep)
+ {
+ return KernelResult<IReadOnlyList<FirmamentParsedOpEntry>>.Failure([
+ CreateDiagnostic(
+ FirmamentDiagnosticCodes.PatternInvalidFieldValue,
+ $"Pattern op '{patternEntry.OpName}' at index {opIndex} has invalid field 'angle_degrees' value; specify either 'angle_degrees' (span) or 'angle_step_degrees', not both.")
+ ]);
+ }
+
+ if (!TryParseNumeric(hasStep ? stepRaw! : spanRaw!, out var angle))
+ {
+ return KernelResult<IReadOnlyList<FirmamentParsedOpEntry>>.Failure([
+ CreateDiagnostic(
+ FirmamentDiagnosticCodes.PatternInvalidFieldTypeOrShape,
+ $"Pattern op '{patternEntry.OpName}' at index {opIndex} has invalid field '{(hasStep ? "angle_step_degrees" : "angle_degrees")}'; expected a numeric scalar value.")
+ ]);
+ }
+
+ var angularStep = hasStep ? angle : angle / count;
+ var baseAngle = sourceEntry.Placement?.AngleDegrees ?? 0d;
+ var expanded = new List<FirmamentParsedOpEntry>(count);
+ var chainReferenceId = sourceEntry.RawFields["id"];
+ for (var i = 1; i <= count; i++)
+ {
+ var instanceId = $"{sourceEntry.RawFields["id"]}__cir{i.ToString(CultureInfo.InvariantCulture)}";
+ var instanceAngle = baseAngle + (angularStep * i);
+ var cloned = CloneWithCircularPlacement(sourceEntry, instanceId, axis, instanceAngle);
+ cloned = ChainBooleanReferenceIfNeeded(cloned, chainReferenceId);
+ chainReferenceId = cloned.RawFields["id"];
+ expanded.Add(cloned);
+ }
+
+ return KernelResult<IReadOnlyList<FirmamentParsedOpEntry>>.Success(expanded);
+ }
+
+ private static FirmamentParsedOpEntry CloneWithPlacementOffset(FirmamentParsedOpEntry sourceEntry, string instanceId, double dx, double dy, double dz)
+ {
+ var clonedFields = new Dictionary<string, string>(sourceEntry.RawFields, StringComparer.Ordinal)
+ {
+ ["id"] = instanceId
+ };
+
+ var sourcePlacement = sourceEntry.Placement;
+ var baseOffset = sourcePlacement?.Offset ?? [0d, 0d, 0d];
+ var placement = new FirmamentParsedPlacement(
+ sourcePlacement?.On ?? new FirmamentParsedPlacementOriginAnchor(),
+ [baseOffset[0] + dx, baseOffset[1] + dy, baseOffset[2] + dz],
+ sourcePlacement?.OnFace,
+ sourcePlacement?.CenteredOn,
+ sourcePlacement?.AroundAxis,
+ sourcePlacement?.RadialOffset,
+ sourcePlacement?.AngleDegrees,
+ sourcePlacement?.UnknownFields ?? Array.Empty<string>());
+
+ return sourceEntry with
+ {
+ RawFields = clonedFields,
+ Placement = placement
+ };
+ }
+
+ private static FirmamentParsedOpEntry CloneWithCircularPlacement(FirmamentParsedOpEntry sourceEntry, string instanceId, string axisSelector, double angleDegrees)
+ {
+ var clonedFields = new Dictionary<string, string>(sourceEntry.RawFields, StringComparer.Ordinal)
+ {
+ ["id"] = instanceId
+ };
+
+ var sourcePlacement = sourceEntry.Placement;
+ var placement = new FirmamentParsedPlacement(
+ sourcePlacement?.On,
+ sourcePlacement?.Offset ?? [0d, 0d, 0d],
+ sourcePlacement?.OnFace,
+ sourcePlacement?.CenteredOn,
+ axisSelector,
+ sourcePlacement?.RadialOffset ?? 0d,
+ angleDegrees,
+ sourcePlacement?.UnknownFields ?? Array.Empty<string>());
+
+ return sourceEntry with
+ {
+ RawFields = clonedFields,
+ Placement = placement
+ };
+ }
+
+ private static FirmamentParsedOpEntry ChainBooleanReferenceIfNeeded(FirmamentParsedOpEntry entry, string nextPrimaryReference)
+ {
+ if (entry.Family != FirmamentOpFamily.Boolean)
+ {
+ return entry;
+ }
+
+ var primaryReferenceField = GetReferenceFieldName(entry.KnownKind);
+ var fields = new Dictionary<string, string>(entry.RawFields, StringComparer.Ordinal)
+ {
+ [primaryReferenceField] = nextPrimaryReference
+ };
+
+ return entry with { RawFields = fields };
+ }
+
+ private static bool TryParseNumericVector(string raw, out IReadOnlyList<double> values)
+ {
+ values = Array.Empty<double>();
+ var trimmed = raw.Trim();
+ if (!trimmed.StartsWith("[", StringComparison.Ordinal) || !trimmed.EndsWith("]", StringComparison.Ordinal))
+ {
+ return false;
+ }
+
+ try
+ {
+ using var doc = System.Text.Json.JsonDocument.Parse(trimmed);
+ if (doc.RootElement.ValueKind != System.Text.Json.JsonValueKind.Array)
+ {
+ return false;
+ }
+
+ var parsed = new List<double>();
+ foreach (var item in doc.RootElement.EnumerateArray())
+ {
+ if (!TryParseNumeric(item.ToString(), out var value))
+ {
+ return false;
+ }
+
+ parsed.Add(value);
+ }
+
+ values = parsed;
+ return true;
+ }
+ catch (System.Text.Json.JsonException)
+ {
+ return false;
+ }
+ }
+
+ private static bool TryParseNumeric(string raw, out double value)
+ {
+ var trimmed = raw.Trim();
+ if (trimmed.StartsWith("\"", StringComparison.Ordinal) && trimmed.EndsWith("\"", StringComparison.Ordinal) && trimmed.Length >= 2)
+ {
+ trimmed = trimmed[1..^1];
+ }
+
+ return double.TryParse(trimmed, NumberStyles.Float, CultureInfo.InvariantCulture, out value);
+ }
+
private static void ValidateValidationTargetReference(
FirmamentParsedOpEntry entry,
int index,
diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentPatternRequiredFieldValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentPatternRequiredFieldValidator.cs
new file mode 100644
index 00000000..85f9e723
--- /dev/null
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentPatternRequiredFieldValidator.cs
@@ -0,0 +1,235 @@
+using System.Globalization;
+using System.Text.Json;
+using Aetheris.Kernel.Core.Diagnostics;
+using Aetheris.Kernel.Core.Results;
+using Aetheris.Kernel.Firmament.Diagnostics;
+using Aetheris.Kernel.Firmament.ParsedModel;
+
+namespace Aetheris.Kernel.Firmament.Validation;
+
+internal static class FirmamentPatternRequiredFieldValidator
+{
+ public static KernelResult<bool> Validate(FirmamentParsedDocument parsedDocument)
+ {
+ ArgumentNullException.ThrowIfNull(parsedDocument);
+
+ for (var index = 0; index < parsedDocument.Ops.Entries.Count; index++)
+ {
+ var entry = parsedDocument.Ops.Entries[index];
+ if (entry.Family != FirmamentOpFamily.Pattern)
+ {
+ continue;
+ }
+
+ var result = entry.KnownKind switch
+ {
+ FirmamentKnownOpKind.PatternLinear => ValidateLinear(entry, index),
+ FirmamentKnownOpKind.PatternCircular => ValidateCircular(entry, index),
+ _ => KernelResult<bool>.Success(true)
+ };
+
+ if (!result.IsSuccess)
+ {
+ return result;
+ }
+ }
+
+ return KernelResult<bool>.Success(true);
+ }
+
+ private static KernelResult<bool> ValidateLinear(FirmamentParsedOpEntry entry, int opIndex)
+ {
+ if (!TryGetRequiredScalar(entry, "source", opIndex, out var sourceDiagnostic))
+ {
+ return KernelResult<bool>.Failure([sourceDiagnostic!]);
+ }
+
+ var countResult = ValidatePositiveIntegerField(entry, "count", opIndex);
+ if (!countResult.IsSuccess)
+ {
+ return countResult;
+ }
+
+ if (!entry.RawFields.TryGetValue("step", out var stepRaw) || string.IsNullOrWhiteSpace(stepRaw))
+ {
+ return MissingField("step", opIndex, entry.OpName);
+ }
+
+ if (!TryParseNumericVector(stepRaw, out var components) || components.Count != 3)
+ {
+ return InvalidFieldTypeOrShape("step", opIndex, entry.OpName, "expected exactly 3 numeric components");
+ }
+
+ return KernelResult<bool>.Success(true);
+ }
+
+ private static KernelResult<bool> ValidateCircular(FirmamentParsedOpEntry entry, int opIndex)
+ {
+ if (!TryGetRequiredScalar(entry, "source", opIndex, out var sourceDiagnostic))
+ {
+ return KernelResult<bool>.Failure([sourceDiagnostic!]);
+ }
+
+ var countResult = ValidatePositiveIntegerField(entry, "count", opIndex);
+ if (!countResult.IsSuccess)
+ {
+ return countResult;
+ }
+
+ if (!TryGetRequiredScalar(entry, "axis", opIndex, out var axisDiagnostic))
+ {
+ return KernelResult<bool>.Failure([axisDiagnostic!]);
+ }
+
+ var hasSpan = entry.RawFields.TryGetValue("angle_degrees", out var spanRaw) && !string.IsNullOrWhiteSpace(spanRaw);
+ var hasStep = entry.RawFields.TryGetValue("angle_step_degrees", out var stepRaw) && !string.IsNullOrWhiteSpace(stepRaw);
+
+ if (!hasSpan && !hasStep)
+ {
+ return MissingField("angle_degrees", opIndex, entry.OpName);
+ }
+
+ if (hasSpan && hasStep)
+ {
+ return InvalidFieldValue("angle_degrees", opIndex, entry.OpName, "specify either 'angle_degrees' (span) or 'angle_step_degrees', not both");
+ }
+
+ if (hasSpan && !TryParseNumeric(spanRaw!, out _))
+ {
+ return InvalidFieldTypeOrShape("angle_degrees", opIndex, entry.OpName, "expected a numeric scalar value");
+ }
+
+ if (hasStep && !TryParseNumeric(stepRaw!, out _))
+ {
+ return InvalidFieldTypeOrShape("angle_step_degrees", opIndex, entry.OpName, "expected a numeric scalar value");
+ }
+
+ return KernelResult<bool>.Success(true);
+ }
+
+ private static KernelResult<bool> ValidatePositiveIntegerField(FirmamentParsedOpEntry entry, string fieldName, int opIndex)
+ {
+ if (!entry.RawFields.TryGetValue(fieldName, out var raw) || string.IsNullOrWhiteSpace(raw))
+ {
+ return MissingField(fieldName, opIndex, entry.OpName);
+ }
+
+ if (!int.TryParse(raw, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value))
+ {
+ return InvalidFieldTypeOrShape(fieldName, opIndex, entry.OpName, "expected an integer scalar value");
+ }
+
+ if (value <= 0)
+ {
+ return InvalidFieldValue(fieldName, opIndex, entry.OpName, "expected an integer value greater than 0");
+ }
+
+ return KernelResult<bool>.Success(true);
+ }
+
+ private static bool TryGetRequiredScalar(FirmamentParsedOpEntry entry, string fieldName, int opIndex, out KernelDiagnostic? diagnostic)
+ {
+ diagnostic = null;
+
+ if (!entry.RawFields.TryGetValue(fieldName, out var raw) || string.IsNullOrWhiteSpace(raw))
+ {
+ diagnostic = MissingFieldDiagnostic(fieldName, opIndex, entry.OpName);
+ return false;
+ }
+
+ if (LooksLikeStructuredValue(raw))
+ {
+ diagnostic = InvalidFieldTypeOrShapeDiagnostic(fieldName, opIndex, entry.OpName, "expected a non-empty scalar/string-like value");
+ return false;
+ }
+
+ return true;
+ }
+
+ private static bool LooksLikeStructuredValue(string raw)
+ {
+ var trimmed = raw.Trim();
+ return trimmed.StartsWith("{", StringComparison.Ordinal)
+ || trimmed.StartsWith("[", StringComparison.Ordinal)
+ || trimmed.EndsWith(":", StringComparison.Ordinal);
+ }
+
+ private static bool TryParseNumericVector(string raw, out IReadOnlyList<double> values)
+ {
+ values = Array.Empty<double>();
+ var trimmed = raw.Trim();
+
+ if (!trimmed.StartsWith("[", StringComparison.Ordinal) || !trimmed.EndsWith("]", StringComparison.Ordinal))
+ {
+ return false;
+ }
+
+ try
+ {
+ using var doc = JsonDocument.Parse(trimmed);
+ if (doc.RootElement.ValueKind != JsonValueKind.Array)
+ {
+ return false;
+ }
+
+ var parsed = new List<double>();
+ foreach (var item in doc.RootElement.EnumerateArray())
+ {
+ var token = item.ToString();
+ if (!TryParseNumeric(token, out var value))
+ {
+ return false;
+ }
+
+ parsed.Add(value);
+ }
+
+ values = parsed;
+ return true;
+ }
+ catch (JsonException)
+ {
+ return false;
+ }
+ }
+
+ private static bool TryParseNumeric(string raw, out double value)
+ {
+ var trimmed = raw.Trim();
+ if (trimmed.StartsWith('"') && trimmed.EndsWith('"') && trimmed.Length >= 2)
+ {
+ trimmed = trimmed[1..^1];
+ }
+
+ return double.TryParse(trimmed, NumberStyles.Float, CultureInfo.InvariantCulture, out value);
+ }
+
+ private static KernelResult<bool> MissingField(string fieldName, int opIndex, string opName) =>
+ KernelResult<bool>.Failure([MissingFieldDiagnostic(fieldName, opIndex, opName)]);
+
+ private static KernelResult<bool> InvalidFieldTypeOrShape(string fieldName, int opIndex, string opName, string expectation) =>
+ KernelResult<bool>.Failure([InvalidFieldTypeOrShapeDiagnostic(fieldName, opIndex, opName, expectation)]);
+
+ private static KernelResult<bool> InvalidFieldValue(string fieldName, int opIndex, string opName, string expectation) =>
+ KernelResult<bool>.Failure([
+ CreateDiagnostic(
+ FirmamentDiagnosticCodes.PatternInvalidFieldValue,
+ $"Pattern op '{opName}' at index {opIndex} has invalid field '{fieldName}' value; {expectation}.")]);
+
+ private static KernelDiagnostic MissingFieldDiagnostic(string fieldName, int opIndex, string opName) =>
+ CreateDiagnostic(
+ FirmamentDiagnosticCodes.PatternMissingRequiredField,
+ $"Pattern op '{opName}' at index {opIndex} is missing required field '{fieldName}'.");
+
+ private static KernelDiagnostic InvalidFieldTypeOrShapeDiagnostic(string fieldName, int opIndex, string opName, string expectation) =>
+ CreateDiagnostic(
+ FirmamentDiagnosticCodes.PatternInvalidFieldTypeOrShape,
+ $"Pattern op '{opName}' at index {opIndex} has invalid field '{fieldName}'; {expectation}.");
+
+ private static KernelDiagnostic CreateDiagnostic(FirmamentDiagnosticCode code, string message) =>
+ new(
+ KernelDiagnosticCode.ValidationFailed,
+ KernelDiagnosticSeverity.Error,
+ $"[{code.Value}] {message}",
+ Source: FirmamentDiagnosticConventions.Source);
+}
diff --git a/docs/firmament-language-shape.md b/docs/firmament-language-shape.md
index 783a18e4..19f8ab29 100644
--- a/docs/firmament-language-shape.md
+++ b/docs/firmament-language-shape.md
@@ -241,6 +241,48 @@ op: expect_manifold
```
---
+# Built-in Pattern Operations (P2 subset)
+
+Firmament currently has exactly two built-in pattern ops:
+- `pattern_linear`
+- `pattern_circular`
+
+Anything outside this bounded subset (path/variable spacing/suppression/nested pattern systems) is intentionally deferred.
+
+## pattern_linear
+```
+op: pattern_linear
+source: hole_1
+count: 3
+step[3]:
+ 10
+ 0
+ 0
+```
+
+Rules:
+- `source` must reference an earlier feature id.
+- `count` must be an integer > 0.
+- `step` must be a 3-component numeric vector.
+- This op deterministically expands into repeated source-feature instances.
+
+## pattern_circular
+```
+op: pattern_circular
+source: bolt_hole_1
+count: 5
+axis: flange.side_face
+angle_degrees: 360
+```
+
+Rules:
+- `source` must reference an earlier feature id.
+- `count` must be an integer > 0.
+- `axis` must be a valid selector-shaped axis reference.
+- Use either `angle_degrees` (span distributed across instances) or `angle_step_degrees` (fixed per-instance step).
+- This op deterministically expands into repeated source-feature instances around the axis.
+---
+
# Scalar Style
Use simple scalars wherever possible.
diff --git a/testdata/firmament/examples/README.md b/testdata/firmament/examples/README.md
index 4c03a0aa..b6bf3e92 100644
--- a/testdata/firmament/examples/README.md
+++ b/testdata/firmament/examples/README.md
@@ -25,6 +25,8 @@ Other combinations may fail and are intentionally not supported yet.
- `p1_blind_hole_on_face_semantic.firmament` — minimal semantic placement subset example using `place.on_face` for a blind-hole tool placement.
- `p1_flange_radial_hole_semantic.firmament` — minimal semantic placement subset example using `place.around_axis` + `place.radial_offset` for flange radial hole placement.
- `p1_bracket_rib_on_face_semantic.firmament` — minimal semantic placement subset example using `place.on_face` for bracket rib authoring ergonomics.
+- `p2_linear_hole_row.firmament` — minimal built-in `pattern_linear` example for repeated hole rows.
+- `p2_flange_bolt_circle_pattern.firmament` — minimal built-in `pattern_circular` bolt-circle example for flange holes.
- `schema_box_basic.firmament` — minimal schema-present export example showing schema presence without changing export body semantics; helper export path: `testdata/firmament/exports/schema_box_basic.step`.
Unsupported boolean requests are tracked as fixtures/tests, not presented in this working example pack. The supported safe subtract family remains narrow and explicit: `subtract(box, cylinder)` and `subtract(box, cone)` still require a Z-aligned tool, full span through the current box shell, non-degenerate boundary circles for cones, and strict in-bounds clearance with no tangent/grazing contact. Sequential composition is limited to repeated document-order subtracts from that same safe family only: `box → subtract cylinder/cone → subtract cylinder/cone`, while the intermediate result must stay representable as one outer box shell plus non-interfering analytic through-holes. This is not general multi-feature boolean support. Box+cylinder `add`, box+cylinder `intersect`, rotated cylinders, partial-depth cuts, tangent/grazing cases, outside-footprint cuts, interfering multi-hole layouts, and unsupported subtract orderings remain unsupported. Box+cone `add`, box+cone `intersect`, tilted cones, partial-depth cone cuts, tangent/grazing cone cuts, apex-inside cases, outside-footprint cone cuts, and unsupported mixed-ordering requests remain unsupported. Box+sphere support is still narrow and truth-first: only `subtract(box, sphere)` with a strictly contained, non-tangent, fully enclosed cavity is supported, reconstructed via one outer shell plus one inner spherical shell. `add(box, sphere)`, `intersect(box, sphere)`, tangent cavity requests, and partially outside sphere requests remain unsupported. Box+torus booleans are currently unsupported in every audited form: `subtract(box, torus)`, `add(box, torus)`, and `intersect(box, torus)` all fail the real kernel boundary for centered, offset, fully contained, face-intersecting, and outside-footprint torus placements, so no box+torus example is included here. These files are intended to stay minimal, readable, and aligned with the implemented language surface. Export artifacts are kept separately under `testdata/firmament/exports/` so examples remain source-only and demo outputs stay easy to find.
diff --git a/testdata/firmament/examples/p2_flange_bolt_circle_pattern.firmament b/testdata/firmament/examples/p2_flange_bolt_circle_pattern.firmament
new file mode 100644
index 00000000..b205c335
--- /dev/null
+++ b/testdata/firmament/examples/p2_flange_bolt_circle_pattern.firmament
@@ -0,0 +1,39 @@
+firmament:
+ version: 1
+
+model:
+ name: p2_flange_bolt_circle_pattern
+ units: mm
+
+ops[4]:
+ -
+ op: cylinder
+ id: flange
+ radius: 36
+ height: 12
+
+ -
+ op: cylinder
+ id: bolt_marker_1
+ radius: 3
+ height: 12
+ place:
+ on_face: flange.top_face
+ around_axis: flange.side_face
+ radial_offset: 20
+ angle_degrees: 0
+ offset[3]:
+ 0
+ 0
+ 0
+
+ -
+ op: pattern_circular
+ source: bolt_marker_1
+ count: 5
+ axis: flange.side_face
+ angle_degrees: 360
+
+ -
+ op: expect_manifold
+ target: bolt_marker_1__cir5
diff --git a/testdata/firmament/examples/p2_linear_hole_row.firmament b/testdata/firmament/examples/p2_linear_hole_row.firmament
new file mode 100644
index 00000000..3e719b68
--- /dev/null
+++ b/testdata/firmament/examples/p2_linear_hole_row.firmament
@@ -0,0 +1,40 @@
+firmament:
+ version: 1
+
+model:
+ name: p2_linear_hole_row
+ units: mm
+
+ops[4]:
+ -
+ op: box
+ id: plate
+ size[3]:
+ 60
+ 20
+ 8
+
+ -
+ op: cylinder
+ id: hole_marker_1
+ radius: 2
+ height: 8
+ place:
+ on: origin
+ offset[3]:
+ -20
+ 0
+ 0
+
+ -
+ op: pattern_linear
+ source: hole_marker_1
+ count: 3
+ step[3]:
+ 10
+ 0
+ 0
+
+ -
+ op: expect_manifold
+ target: hole_marker_1__lin3
diff --git a/testdata/firmament/exports/p2_flange_bolt_circle_pattern.step b/testdata/firmament/exports/p2_flange_bolt_circle_pattern.step
new file mode 100644
index 00000000..60cab2cb
--- /dev/null
+++ b/testdata/firmament/exports/p2_flange_bolt_circle_pattern.step
@@ -0,0 +1,79 @@
+ISO-10303-21;
+HEADER;
+FILE_DESCRIPTION(('Aetheris AP242 subset export'),'2;1');
+FILE_NAME('aetheris_export.step','1970-01-01T00:00:00',('Aetheris'),('Aetheris'),'Aetheris.Kernel','Aetheris.Kernel','');
+FILE_SCHEMA(('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF'));
+ENDSEC;
+DATA;
+#1=CARTESIAN_POINT($,(20,-0.000000000000005,12));
+#2=DIRECTION($,(0,0,1));
+#3=DIRECTION($,(1,0,0));
+#4=AXIS2_PLACEMENT_3D($,#1,#2,#3);
+#5=CYLINDRICAL_SURFACE($,#4,3);
+#6=CARTESIAN_POINT($,(23,-0.000000000000005,12));
+#7=VERTEX_POINT($,#6);
+#8=CARTESIAN_POINT($,(23,-0.000000000000005,24));
+#9=VERTEX_POINT($,#8);
+#10=CARTESIAN_POINT($,(23,-0.000000000000005,12));
+#11=DIRECTION($,(0,0,1));
+#12=VECTOR($,#11,1);
+#13=LINE($,#10,#12);
+#14=EDGE_CURVE($,#7,#9,#13,.T.);
+#15=ORIENTED_EDGE($,$,$,#14,.T.);
+#16=CARTESIAN_POINT($,(23,-0.000000000000005,24));
+#17=VERTEX_POINT($,#16);
+#18=CARTESIAN_POINT($,(20,-0.000000000000005,24));
+#19=DIRECTION($,(0,0,1));
+#20=DIRECTION($,(1,0,0));
+#21=AXIS2_PLACEMENT_3D($,#18,#19,#20);
+#22=CIRCLE($,#21,3);
+#23=EDGE_CURVE($,#17,#17,#22,.T.);
+#24=ORIENTED_EDGE($,$,$,#23,.T.);
+#25=ORIENTED_EDGE($,$,$,#14,.F.);
+#26=CARTESIAN_POINT($,(23,-0.000000000000005,12));
+#27=VERTEX_POINT($,#26);
+#28=CARTESIAN_POINT($,(20,-0.000000000000005,12));
+#29=DIRECTION($,(0,0,1));
+#30=DIRECTION($,(1,0,0));
+#31=AXIS2_PLACEMENT_3D($,#28,#29,#30);
+#32=CIRCLE($,#31,3);
+#33=EDGE_CURVE($,#27,#27,#32,.T.);
+#34=ORIENTED_EDGE($,$,$,#33,.F.);
+#35=EDGE_LOOP($,(#15,#24,#25,#34));
+#36=FACE_OUTER_BOUND('',#35,.T.);
+#37=ADVANCED_FACE('',(#36),#5,.T.);
+#38=CARTESIAN_POINT($,(20,-0.000000000000005,24));
+#39=DIRECTION($,(0,0,1));
+#40=DIRECTION($,(1,0,0));
+#41=AXIS2_PLACEMENT_3D($,#38,#39,#40);
+#42=PLANE($,#41);
+#43=ORIENTED_EDGE($,$,$,#23,.F.);
+#44=EDGE_LOOP($,(#43));
+#45=FACE_OUTER_BOUND('',#44,.T.);
+#46=ADVANCED_FACE('',(#45),#42,.T.);
+#47=CARTESIAN_POINT($,(20,-0.000000000000005,12));
+#48=DIRECTION($,(0,0,-1));
+#49=DIRECTION($,(0,1,0));
+#50=AXIS2_PLACEMENT_3D($,#47,#48,#49);
+#51=PLANE($,#50);
+#52=ORIENTED_EDGE($,$,$,#33,.T.);
+#53=EDGE_LOOP($,(#52));
+#54=FACE_OUTER_BOUND('',#53,.T.);
+#55=ADVANCED_FACE('',(#54),#51,.T.);
+#56=CLOSED_SHELL($,(#37,#46,#55));
+#57=MANIFOLD_SOLID_BREP('AetherisBody',#56);
+#58=APPLICATION_CONTEXT('mechanical design');
+#59=PRODUCT_CONTEXT('',#58,'mechanical');
+#60=PRODUCT('AETHERIS','AetherisBody','',(#59));
+#61=PRODUCT_DEFINITION_FORMATION('','',#60);
+#62=PRODUCT_DEFINITION_CONTEXT('design',#58,'design');
+#63=PRODUCT_DEFINITION('','',#61,#62);
+#64=PRODUCT_DEFINITION_SHAPE('','',#63);
+#65=(LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.));
+#66=(NAMED_UNIT(*)PLANE_ANGLE_UNIT()SI_UNIT($,.RADIAN.));
+#67=(NAMED_UNIT(*)SI_UNIT($,.STERADIAN.)SOLID_ANGLE_UNIT());
+#68=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNIT_ASSIGNED_CONTEXT((#65,#66,#67))REPRESENTATION_CONTEXT('3','3D'));
+#69=SHAPE_REPRESENTATION('AetherisBody',(#57),#68);
+#70=SHAPE_DEFINITION_REPRESENTATION(#64,#69);
+ENDSEC;
+END-ISO-10303-21;
diff --git a/testdata/firmament/exports/p2_linear_hole_row.step b/testdata/firmament/exports/p2_linear_hole_row.step
new file mode 100644
index 00000000..58ec85cf
--- /dev/null
+++ b/testdata/firmament/exports/p2_linear_hole_row.step
@@ -0,0 +1,79 @@
+ISO-10303-21;
+HEADER;
+FILE_DESCRIPTION(('Aetheris AP242 subset export'),'2;1');
+FILE_NAME('aetheris_export.step','1970-01-01T00:00:00',('Aetheris'),('Aetheris'),'Aetheris.Kernel','Aetheris.Kernel','');
+FILE_SCHEMA(('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF'));
+ENDSEC;
+DATA;
+#1=CARTESIAN_POINT($,(10,0,0));
+#2=DIRECTION($,(0,0,1));
+#3=DIRECTION($,(1,0,0));
+#4=AXIS2_PLACEMENT_3D($,#1,#2,#3);
+#5=CYLINDRICAL_SURFACE($,#4,2);
+#6=CARTESIAN_POINT($,(12,0,0));
+#7=VERTEX_POINT($,#6);
+#8=CARTESIAN_POINT($,(12,0,8));
+#9=VERTEX_POINT($,#8);
+#10=CARTESIAN_POINT($,(12,0,0));
+#11=DIRECTION($,(0,0,1));
+#12=VECTOR($,#11,1);
+#13=LINE($,#10,#12);
+#14=EDGE_CURVE($,#7,#9,#13,.T.);
+#15=ORIENTED_EDGE($,$,$,#14,.T.);
+#16=CARTESIAN_POINT($,(12,0,8));
+#17=VERTEX_POINT($,#16);
+#18=CARTESIAN_POINT($,(10,0,8));
+#19=DIRECTION($,(0,0,1));
+#20=DIRECTION($,(1,0,0));
+#21=AXIS2_PLACEMENT_3D($,#18,#19,#20);
+#22=CIRCLE($,#21,2);
+#23=EDGE_CURVE($,#17,#17,#22,.T.);
+#24=ORIENTED_EDGE($,$,$,#23,.T.);
+#25=ORIENTED_EDGE($,$,$,#14,.F.);
+#26=CARTESIAN_POINT($,(12,0,0));
+#27=VERTEX_POINT($,#26);
+#28=CARTESIAN_POINT($,(10,0,0));
+#29=DIRECTION($,(0,0,1));
+#30=DIRECTION($,(1,0,0));
+#31=AXIS2_PLACEMENT_3D($,#28,#29,#30);
+#32=CIRCLE($,#31,2);
+#33=EDGE_CURVE($,#27,#27,#32,.T.);
+#34=ORIENTED_EDGE($,$,$,#33,.F.);
+#35=EDGE_LOOP($,(#15,#24,#25,#34));
+#36=FACE_OUTER_BOUND('',#35,.T.);
+#37=ADVANCED_FACE('',(#36),#5,.T.);
+#38=CARTESIAN_POINT($,(10,0,8));
+#39=DIRECTION($,(0,0,1));
+#40=DIRECTION($,(1,0,0));
+#41=AXIS2_PLACEMENT_3D($,#38,#39,#40);
+#42=PLANE($,#41);
+#43=ORIENTED_EDGE($,$,$,#23,.F.);
+#44=EDGE_LOOP($,(#43));
+#45=FACE_OUTER_BOUND('',#44,.T.);
+#46=ADVANCED_FACE('',(#45),#42,.T.);
+#47=CARTESIAN_POINT($,(10,0,0));
+#48=DIRECTION($,(0,0,-1));
+#49=DIRECTION($,(0,1,0));
+#50=AXIS2_PLACEMENT_3D($,#47,#48,#49);
+#51=PLANE($,#50);
+#52=ORIENTED_EDGE($,$,$,#33,.T.);
+#53=EDGE_LOOP($,(#52));
+#54=FACE_OUTER_BOUND('',#53,.T.);
+#55=ADVANCED_FACE('',(#54),#51,.T.);
+#56=CLOSED_SHELL($,(#37,#46,#55));
+#57=MANIFOLD_SOLID_BREP('AetherisBody',#56);
+#58=APPLICATION_CONTEXT('mechanical design');
+#59=PRODUCT_CONTEXT('',#58,'mechanical');
+#60=PRODUCT('AETHERIS','AetherisBody','',(#59));
+#61=PRODUCT_DEFINITION_FORMATION('','',#60);
+#62=PRODUCT_DEFINITION_CONTEXT('design',#58,'design');
+#63=PRODUCT_DEFINITION('','',#61,#62);
+#64=PRODUCT_DEFINITION_SHAPE('','',#63);
+#65=(LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.));
+#66=(NAMED_UNIT(*)PLANE_ANGLE_UNIT()SI_UNIT($,.RADIAN.));
+#67=(NAMED_UNIT(*)SI_UNIT($,.STERADIAN.)SOLID_ANGLE_UNIT());
+#68=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNIT_ASSIGNED_CONTEXT((#65,#66,#67))REPRESENTATION_CONTEXT('3','3D'));
+#69=SHAPE_REPRESENTATION('AetherisBody',(#57),#68);
+#70=SHAPE_DEFINITION_REPRESENTATION(#64,#69);
+ENDSEC;
+END-ISO-10303-21;
diff --git a/testdata/firmament/fixtures/p2_invalid_pattern_unknown_axis.firmament b/testdata/firmament/fixtures/p2_invalid_pattern_unknown_axis.firmament
new file mode 100644
index 00000000..cf39da4b
--- /dev/null
+++ b/testdata/firmament/fixtures/p2_invalid_pattern_unknown_axis.firmament
@@ -0,0 +1,35 @@
+firmament:
+ version: 1
+
+model:
+ name: p2_invalid_pattern_unknown_axis
+ units: mm
+
+ops[3]:
+ -
+ op: cylinder
+ id: flange
+ radius: 36
+ height: 12
+
+ -
+ op: cylinder
+ id: bolt_marker_1
+ radius: 3
+ height: 12
+ place:
+ on_face: flange.top_face
+ around_axis: flange.side_face
+ radial_offset: 20
+ angle_degrees: 0
+ offset[3]:
+ 0
+ 0
+ 0
+
+ -
+ op: pattern_circular
+ source: bolt_marker_1
+ count: 5
+ axis: missing.side_face
+ angle_degrees: 360