From b1d9076570f92947c54dbc0ef84781d6d0b89125 Mon Sep 17 00:00:00 2001 From: Wisdom International Date: Fri, 2 Oct 2026 00:15:05 -0400 Subject: [PATCH 1/4] Add planar face and straight edge measurement angles --- FEATURES.md | 2 +- README.md | 8 +- Sources/ForgeApp/PMPages.swift | 15 ++- .../Commands/QueryCommands.swift | 66 ++++++++++++- Sources/ForgeUI/PanelSpec.swift | 12 ++- Sources/ForgeUI/PropertyManager.swift | 10 +- .../ForgeCommandsTests/MeasurementTests.swift | 97 +++++++++++++++++++ Tests/ForgeUITests/MeasureWorkflowTests.swift | 30 ++++++ Tests/IntegrationTests/test_mcp_stdio.py | 19 ++++ docs/research/modeling-workflow-gaps.md | 6 +- 10 files changed, 251 insertions(+), 14 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 9f70d63..3e6cb4c 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -736,7 +736,7 @@ MCP, tests) · `verified` (done + golden/e2e coverage + reviewed on macOS). | ID | Feature | Status | Module | Test | MCP tool | Notes | |---|---|---|---|---|---|---| -| `7.12/measure` | Measure | in progress | ForgeKernel | Tests/ForgeCommandsTests/MeasurementTests.swift, Tests/ForgeUITests/MeasureWorkflowTests.swift | measure | bodies/faces/edges/vertices: size, radius, coordinates, minimum distance, closest points and XYZ deltas; angles/max/normal-distance modes pending | +| `7.12/measure` | Measure | in progress | ForgeCommands / ForgeUI | Tests/ForgeCommandsTests/MeasurementTests.swift, Tests/ForgeUITests/MeasureWorkflowTests.swift | measure | bodies/faces/edges/vertices: size, radius, coordinates, minimum distance, closest points and XYZ deltas; explicit angle mode for planar faces/straight edges (mixed pairs, unoriented 0–90°); curved angles/max/normal-distance modes pending | | `7.12/measure/all-modes` | ↳ all modes | not started | ForgeModel | — | — | | | `7.12/measure/point-to-point` | ↳ point-to-point | not started | ForgeModel | — | — | | | `7.12/measure/min-max-normal` | ↳ min/max/normal | not started | ForgeModel | — | — | | diff --git a/README.md b/README.md index 27d85a9..184ea50 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,13 @@ accounts for all 1,000 matrix entries and documents remaining work. **Measure** accepts one face, edge, vertex or body for its size/coordinates, or two for minimum distance and closest points. The MCP `measure` tool uses `from` and an -optional `to`; results use millimeters. Angle and maximum-distance modes remain pending. +optional `to`; sizes and distances use millimeters. Choose **Angle (0–90°)** for two +planar faces or straight edges, including mixed pairs. MCP `measure` and `query.measure` +accept `mode: "angle"` and return `angle_degrees`. Angles use unoriented supporting +planes/lines: parallel or antiparallel geometry gives 0°, perpendicular geometry gives +90°; a line normal to a plane gives 90°. Curved faces/edges, degenerate edges, bodies +and vertices produce explicit unsupported-geometry errors in angle mode. Omit `mode` +or use `"distance"` for the existing behavior. Maximum/normal-distance modes remain pending. Use the body tree or **Features → Visibility** to hide/show bodies, isolate a selection, exit isolation or show all bodies. Hidden bodies are excluded from drawing and picking; diff --git a/Sources/ForgeApp/PMPages.swift b/Sources/ForgeApp/PMPages.swift index 34cd039..06d0888 100644 --- a/Sources/ForgeApp/PMPages.swift +++ b/Sources/ForgeApp/PMPages.swift @@ -506,11 +506,24 @@ struct OperationPage: View { } } case .massProperties, .measure, .check: + if op == .measure { + PMSection("Mode") { + PMPicker(label: "Mode", selection: $model.form.measureMode) { + Text("Size / Minimum Distance").tag("distance") + Text("Angle (0–90°)").tag("angle") + } + PMNote(text: "Angles require two planar faces or straight edges; supporting planes/lines are unoriented.") + } + .onChange(of: model.form.measureMode) { _, _ in + model.form.result = nil + Task { await model.computeMeasure() } + } + } PMSection(op == .measure ? "Measure" : "Results") { if let r = model.form.result { KeyValueList(value: r) } else { - Text(op == .measure ? "Select one entity for its size, or two for their minimum distance." : "Select a body.") + Text(op == .measure ? (model.form.measureMode == "angle" ? "Select two planar faces or straight edges for their angle." : "Select one entity for its size, or two for their minimum distance.") : "Select a body.") .font(.system(size: 12)).foregroundStyle(Theme.text2) } } diff --git a/Sources/ForgeCommands/Commands/QueryCommands.swift b/Sources/ForgeCommands/Commands/QueryCommands.swift index 8326ccb..43a237b 100644 --- a/Sources/ForgeCommands/Commands/QueryCommands.swift +++ b/Sources/ForgeCommands/Commands/QueryCommands.swift @@ -198,12 +198,17 @@ public enum QueryMassProperties: Command { } public enum QueryMeasure: Command { + public enum Mode: String, Codable, Sendable, CaseIterable, SchemaEnum { + case distance, angle + } public struct Params: Codable, Sendable, SchemaDocumented { public var from: String public var to: String? + public var mode: Mode? public static let fieldDocs: [String: FieldDoc] = [ "from": "Body, face, edge or vertex reference (including persistent face/edge names)", - "to": "Optional second reference; return minimum distance and closest points when supplied", + "to": "Optional second reference for distance; required for angle", + "mode": FieldDoc("distance or angle; angle accepts planar faces and straight edges", default: "distance"), ] } public struct EntityMeasurement: Codable, Sendable { @@ -222,6 +227,7 @@ public enum QueryMeasure: Command { } } public struct Output: Codable, Sendable { + public var angleDegrees: Double? public var distanceMM: Double? public var pointFrom: [Double]? public var pointTo: [Double]? @@ -229,20 +235,22 @@ public enum QueryMeasure: Command { public var fromEntity: EntityMeasurement public var toEntity: EntityMeasurement? enum CodingKeys: String, CodingKey { + case angleDegrees = "angle_degrees" case distanceMM = "distance_mm", pointFrom = "point_from", pointTo = "point_to", deltaMM = "delta_mm" case fromEntity = "from_entity", toEntity = "to_entity" } } public static let name = "query.measure" - public static let summary = "Measure bodies, faces, edges or vertices, with minimum distance between two selections" - public static let discussion = "One selection returns its length, area, volume, circular radius or vertex position as applicable. Two selections also return exact B-rep minimum distance, closest points and their signed XYZ displacement, all in millimeters. Named references must identify a single face or edge. Angles, maximum distances and normal-distance modes are not implemented." + public static let summary = "Measure entity sizes, minimum distances, or angles between planar faces and straight edges" + public static let discussion = "One selection returns its length, area, volume, circular radius or vertex position as applicable. In distance mode, two selections also return exact B-rep minimum distance, closest points and their signed XYZ displacement, all in millimeters. Named references must identify a single face or edge. mode=angle requires two planar faces or straight edges (including mixed pairs), returning angle_degrees in [0, 90] between their unoriented supporting planes/lines. Parallel or antiparallel planes/lines measure 0; a line normal to a plane measures 90. Curved, degenerate and body/vertex angle selections are rejected. Maximum distances and normal-distance modes are not implemented." public static let category = CommandCategory.query public static let undo = UndoBehavior.none - public static let errors: [ErrorCode] = [.unknownEntity, .invalidParams, .referenceLost, .kernelFailure] + public static let errors: [ErrorCode] = [.unknownEntity, .invalidParams, .referenceLost, .kernelFailure, .notImplemented] public static let examples: [JSONValue] = [ ["from": "body-1", "to": "body-2"], ["from": "body-1/edge-0"], ["from": "body-1/face-0", "to": "body-1/vertex-2"], + ["from": "body-1/face-0", "to": "body-1/edge-0", "mode": "angle"], ] static func resolve(_ reference: String, in doc: Document) throws -> (Shape, EntityMeasurement) { @@ -280,11 +288,61 @@ public enum QueryMeasure: Command { } } + /// Resolve through the same single-entity/persistent-name rules used by distance. + static func angleDirection(_ reference: String, in doc: Document) throws -> (Vec3, Bool) { + let ref = try EntityRef.parse(reference) + let body = try doc.body(ref.body) + let direction: Vec3 + let isPlane: Bool + switch ref.kind { + case .face: + let face = try body.shape.face(doc.faceIndices([reference], of: body, sets: false)[0]) + guard face.surfaceType == .plane else { + throw ForgeError(.notImplemented, "angle measurement requires a planar face", entities: [reference]) + } + direction = face.normal + isPlane = true + case .edge: + let indices = try doc.edgeIndices([reference], of: body) + guard indices.count == 1 else { + throw ForgeError(.invalidParams, "angle measurement requires one edge", entities: [reference]) + } + let edge = try body.shape.edge(indices[0]) + guard edge.curveType == .line, !edge.isDegenerate else { + throw ForgeError(.notImplemented, "angle measurement requires a nondegenerate straight edge", entities: [reference]) + } + direction = edge.end - edge.start + isPlane = false + case .body, .vertex: + throw ForgeError(.notImplemented, "angle measurement supports planar faces and straight edges", entities: [reference]) + } + guard direction.length.isFinite, direction.length > 0 else { + throw ForgeError(.invalidParams, "angle measurement has no defined direction", entities: [reference]) + } + return (direction.normalized, isPlane) + } + + static func angleDegrees(_ a: Vec3, _ b: Vec3, mixed: Bool) -> Double { + // atan2 avoids acos/asin domain errors and cancellation near 0 and 90 degrees. + let dot = abs(a.dot(b)) + let cross = a.cross(b).length + return (mixed ? atan2(dot, cross) : atan2(cross, dot)) * 180 / .pi + } + public static func run(_ p: Params, _ ctx: inout CommandContext) throws -> Output { + if p.mode == .angle && p.to == nil { + throw ForgeError(.invalidParams, "angle measurement requires two selections") + } let doc = try ctx.requireDocument() let (a, first) = try resolve(p.from, in: doc) guard let to = p.to else { return Output(fromEntity: first) } let (b, second) = try resolve(to, in: doc) + if p.mode == .angle { + let (u, firstPlane) = try angleDirection(p.from, in: doc) + let (v, secondPlane) = try angleDirection(to, in: doc) + return Output(angleDegrees: angleDegrees(u, v, mixed: firstPlane != secondPlane), + fromEntity: first, toEntity: second) + } let distance = try Kernel.distance(a, b) return Output(distanceMM: distance.distance, pointFrom: distance.pointA.array, pointTo: distance.pointB.array, deltaMM: (distance.pointB - distance.pointA).array, fromEntity: first, toEntity: second) diff --git a/Sources/ForgeUI/PanelSpec.swift b/Sources/ForgeUI/PanelSpec.swift index 54776ed..59ca185 100644 --- a/Sources/ForgeUI/PanelSpec.swift +++ b/Sources/ForgeUI/PanelSpec.swift @@ -374,9 +374,19 @@ extension AppModel { } s.append(PanelSection("Results", controls: controls)) case .massProperties, .measure, .check: + if op == .measure { + s.append(PanelSection("Mode", controls: [ + PanelControl(id: "measureMode", kind: .choice(label: "Mode", options: [("distance", "Size / Minimum Distance"), ("angle", "Angle (0–90°)")], get: { [unowned self] in form.measureMode }, set: { [unowned self] in + form.measureMode = $0 + form.result = nil + Task { await computeMeasure() } + })), + note("angleScope", "Angles require two planar faces or straight edges; supporting planes/lines are unoriented."), + ])) + } let rows = form.result.map(Self.keyValues) ?? [] s.append(PanelSection(op == .measure ? "Measure" : "Results", controls: rows.isEmpty - ? [note("empty", op == .measure ? "Select one entity for its size, or two for their minimum distance." : "Select a body.")] + ? [note("empty", op == .measure ? (f.measureMode == "angle" ? "Select two planar faces or straight edges for their angle." : "Select one entity for its size, or two for their minimum distance.") : "Select a body.")] : rows.enumerated().map { i, kv in PanelControl(id: "r\(i)", kind: .value(label: kv.0, value: kv.1)) })) case .addRelation: s += [selectedEntitiesSection, relationsSection(all: false), relationButtonsSection].compactMap { $0 } diff --git a/Sources/ForgeUI/PropertyManager.swift b/Sources/ForgeUI/PropertyManager.swift index 0f97fa5..2318c72 100644 --- a/Sources/ForgeUI/PropertyManager.swift +++ b/Sources/ForgeUI/PropertyManager.swift @@ -36,6 +36,7 @@ package enum EndConditionUI: String, CaseIterable { /// Values being edited in the PropertyManager. Lengths are text so units work ("0.5 in"). package struct OperationForm { + package var measureMode = "distance" package var bodyDX = "0", bodyDY = "0", bodyDZ = "0", bodyCopy = false package var bodyCustomAxis: [JSONValue] = [0, 0, 1] package var bodyRotation = false, bodyAngle = "90", bodyAxis = "z" @@ -821,19 +822,20 @@ extension AppModel { return } let requestedSelection = selection - var params: [String: JSONValue] = ["from": .string(refs[0])] + let requestedMode = form.measureMode + var params: [String: JSONValue] = ["from": .string(refs[0]), "mode": .string(requestedMode)] if refs.count == 2 { params["to"] = .string(refs[1]) } do { let result = try await engine.execute("query.measure", .object(params)).result - guard selection == requestedSelection, operation == .measure else { return } + guard selection == requestedSelection, form.measureMode == requestedMode, operation == .measure else { return } form.result = result lastError = nil } catch let error as ForgeError { - guard selection == requestedSelection, operation == .measure else { return } + guard selection == requestedSelection, form.measureMode == requestedMode, operation == .measure else { return } form.result = nil lastError = error } catch { - guard selection == requestedSelection, operation == .measure else { return } + guard selection == requestedSelection, form.measureMode == requestedMode, operation == .measure else { return } form.result = nil lastError = ForgeError(.internalError, error.localizedDescription) } diff --git a/Tests/ForgeCommandsTests/MeasurementTests.swift b/Tests/ForgeCommandsTests/MeasurementTests.swift index 209b6ab..1f696a6 100644 --- a/Tests/ForgeCommandsTests/MeasurementTests.swift +++ b/Tests/ForgeCommandsTests/MeasurementTests.swift @@ -98,6 +98,103 @@ struct MeasurementTests { #expect(abs(result["from_entity"]!["length_mm"]!.doubleValue! - 10 * .pi) < 1e-8) } + func edge(_ engine: Engine, body id: String = "body-1", direction: Vec3) async throws -> String { + let body = try #require(await engine.activeDocument?.bodies[id]) + for i in 0..<(try body.shape.topology().edges) { + let edge = try body.shape.edge(i) + if abs((edge.end - edge.start).normalized.dot(direction)) > 1 - 1e-10 { return "\(id)/edge-\(i)" } + } + throw ForgeError(.internalError, "test edge missing") + } + + @Test func angleMathRemainsFiniteNearParallelAndPerpendicularDirections() { + for degrees in [0.0, 1e-10, 30, 89.9999999999, 90, 120, 180] { + let radians = degrees * .pi / 180 + let b = Vec3(cos(radians), sin(radians), 0) + let expected = min(degrees, 180 - degrees) + let angle = QueryMeasure.angleDegrees(.unitX, b, mixed: false) + #expect(angle.isFinite) + #expect(abs(angle - expected) < 1e-9) + #expect(abs(QueryMeasure.angleDegrees(-.unitX, b, mixed: false) - expected) < 1e-9) + #expect(abs(QueryMeasure.angleDegrees(.unitX, b, mixed: true) - (90 - expected)) < 1e-9) + } + } + + @Test func planarAndStraightAnglesAreUnorientedAndSymmetric() async throws { + let e = try await engine() + let top = try await face(e, normal: .unitZ) + let bottom = try await face(e, normal: -.unitZ) + let side = try await face(e, normal: .unitX) + let x = try await edge(e, direction: .unitX) + let z = try await edge(e, direction: .unitZ) + let before = try await e.execute("document.state").result + for (a, b, expected) in [(top, bottom, 0.0), (top, side, 90.0), (x, x, 0.0), (x, z, 90.0), (top, x, 0.0), (top, z, 90.0)] { + for (from, to) in [(a, b), (b, a)] { + let r = try await e.execute("query.measure", ["from": .string(from), "to": .string(to), "mode": "angle"]).result + #expect(abs(r["angle_degrees"]!.doubleValue! - expected) < 1e-9) + #expect(r["distance_mm"] == nil) + #expect(r["point_from"] == nil) + #expect(r["from_entity"]?["reference"]?.stringValue == from) + } + } + #expect(try await e.execute("document.state").result == before) + let implicit = try await e.execute("query.measure", ["from": .string(top), "to": .string(bottom)]).result + let explicit = try await e.execute("query.measure", ["from": .string(top), "to": .string(bottom), "mode": "distance"]).result + #expect(implicit == explicit) + } + + @Test func obliqueAndPersistentAnglesSurviveRebuild() async throws { + let e = try await engine() + let top = try await face(e, normal: .unitZ) + let x = try await edge(e, direction: .unitX) + try await e.execute("body.create_box", ["width": 10, "height": 20, "depth": 30]) + try await e.execute("body.transform", ["body": "body-2", "rotate": ["axis": [0, 1, 0], "angle": "30 deg"], "translate": [100, 0, 0]]) + let tilted = Vec3(cos(.pi / 6), 0, -sin(.pi / 6)) + let otherEdge = try await edge(e, body: "body-2", direction: tilted) + let doc = try #require(await e.activeDocument) + let b = try doc.body("body-2") + let ref = try EntityRef.parse(otherEdge) + let name = try #require(b.naming?.edges[try #require(ref.index)]) + let namedEdge = "body-2/edge@\(name)" + var tiltedFace = "" + for i in 0..<(try b.shape.topology().faces) { + if (try b.shape.face(i).normal - Vec3(sin(.pi / 6), 0, cos(.pi / 6))).length < 1e-9 { + tiltedFace = "body-2/face@\(try #require(b.naming?.faces[i]))" + } + } + #expect(!tiltedFace.isEmpty) + for rebuild in [false, true] { + if rebuild { try await e.execute("document.regenerate") } + for (a, b) in [(x, namedEdge), (top, namedEdge), (top, tiltedFace)] { + let r = try await e.execute("query.measure", ["from": .string(a), "to": .string(b), "mode": "angle"]).result + #expect(abs(r["angle_degrees"]!.doubleValue! - 30) < 1e-8) + } + } + } + + @Test func rejectsUnsupportedAngleGeometryAndInvalidModes() async throws { + let e = try await engine() + let top = try await face(e, normal: .unitZ) + try await e.execute("body.create_cylinder", ["radius": 5, "height": 10]) + let b = try #require(await e.activeDocument?.bodies["body-2"]) + let curvedFace = try #require((0..<(try b.shape.topology().faces)).first { (try? b.shape.face($0).surfaceType) == .cylinder }) + let curvedEdge = try #require((0..<(try b.shape.topology().edges)).first { (try? b.shape.edge($0).curveType) == .circle }) + let before = try await e.execute("document.state").result + for unsupported in ["body-1", "body-1/vertex-0", "body-2/face-\(curvedFace)", "body-2/edge-\(curvedEdge)"] { + do { + try await e.execute("query.measure", ["from": .string(top), "to": .string(unsupported), "mode": "angle"]) + Issue.record("unsupported angle geometry accepted") + } catch let error as ForgeError { + #expect(error.code == .notImplemented) + #expect(error.entities.contains(unsupported)) + } + } + for params: JSONValue in [["from": .string(top), "mode": "angle"], ["from": .string(top), "to": .string(top), "mode": "maximum"], ["from": .string(top), "to": "body-1/edge@missing", "mode": "angle"]] { + await #expect(throws: ForgeError.self) { try await e.execute("query.measure", params) } + } + #expect(try await e.execute("document.state").result == before) + } + @Test func rejectsMissingAndOutOfRangeSelectionsWithoutMutatingDocument() async throws { let engine = try await engine() let before = try await engine.execute("document.state").result diff --git a/Tests/ForgeUITests/MeasureWorkflowTests.swift b/Tests/ForgeUITests/MeasureWorkflowTests.swift index 0e52f6f..92c03ff 100644 --- a/Tests/ForgeUITests/MeasureWorkflowTests.swift +++ b/Tests/ForgeUITests/MeasureWorkflowTests.swift @@ -1,4 +1,5 @@ import ForgeCore +import ForgeCommands import Testing @testable import ForgeUI @@ -41,6 +42,35 @@ struct MeasureWorkflowTests { #expect(m.lastError != nil) } + @Test func angleModeSwitchesResultsAndReportsUnsupportedSelections() async throws { + let m = AppModel() + await m.bootstrap() + await m.run("body.create_box", ["width": 10, "height": 20, "depth": 30]) + let faces = try await m.engine.execute("query.faces", ["body": "body-1"]).result["faces"]!.arrayValue! + let side = try #require(faces.first { $0["normal"] == [1, 0, 0] }?["persistent_id"]?.stringValue) + let top = try #require(faces.first { $0["normal"] == [0, 0, 1] }?["persistent_id"]?.stringValue) + m.selection = [side, top] + m.begin(.measure) + m.form.measureMode = "angle" + await m.computeMeasure() + #expect(abs((m.form.result?["angle_degrees"]?.doubleValue ?? -1) - 90) < 1e-9) + #expect(m.form.result?["distance_mm"] == nil) + #expect(m.lastError == nil) + m.form.measureMode = "distance" + await m.computeMeasure() + #expect(m.form.result?["distance_mm"] != nil) + #expect(m.form.result?["angle_degrees"] == nil) + m.form.measureMode = "angle" + m.selection = ["body-1"] + await m.computeMeasure() + #expect(m.form.result == nil) + #expect(m.lastError?.code == .invalidParams) + m.selection = ["body-1", top] + await m.computeMeasure() + #expect(m.form.result == nil) + #expect(m.lastError?.code == .notImplemented) + } + @Test func invalidReferenceReportsErrorInsteadOfBlankResults() async throws { let m = AppModel() await m.bootstrap() diff --git a/Tests/IntegrationTests/test_mcp_stdio.py b/Tests/IntegrationTests/test_mcp_stdio.py index 037973b..3f06173 100644 --- a/Tests/IntegrationTests/test_mcp_stdio.py +++ b/Tests/IntegrationTests/test_mcp_stdio.py @@ -45,6 +45,25 @@ def test_step_interference_history_and_persistence(self): ]) self.assertTrue(reopened[-1]["result"]["structuredContent"]["passed"]) + def test_angle_measurement_and_structured_errors(self): + executable = os.environ.get("FORGE_CLI", ".build/debug/forge-cli") + responses = self.run_calls(executable, [ + ("new_document", {}), + ("execute", {"command": "body.create_box", "params": {"width": 10, "height": 20, "depth": 30}}), + ("measure", {"from": "body-1/face@feature-1:+x", "to": "body-1/face@feature-1:+z", "mode": "angle"}), + ("measure", {"from": "body-1/face@feature-1:+x", "to": "body-1/face@feature-1:+z"}), + ("measure", {"from": "body-1", "to": "body-1/face@feature-1:+z", "mode": "angle"}), + ("measure", {"from": "body-1/face@feature-1:+x", "mode": "angle"}), + ]) + for response in responses[:4]: + self.assertFalse(response["result"]["isError"], response) + angle = responses[2]["result"]["structuredContent"] + self.assertAlmostEqual(angle["angle_degrees"], 90) + self.assertNotIn("distance_mm", angle) + self.assertIn("distance_mm", responses[3]["result"]["structuredContent"]) + for response in responses[4:]: + self.assertTrue(response["result"]["isError"], response) + def test_invalid_step_keeps_stdout_valid_json(self): executable = os.environ.get("FORGE_CLI", ".build/debug/forge-cli") with tempfile.TemporaryDirectory() as temporary: diff --git a/docs/research/modeling-workflow-gaps.md b/docs/research/modeling-workflow-gaps.md index 5cb081c..ab7fe61 100644 --- a/docs/research/modeling-workflow-gaps.md +++ b/docs/research/modeling-workflow-gaps.md @@ -42,8 +42,10 @@ independent all-tests-passed claim. The next implementation adds `query.measure` for bodies and individual faces, edges and vertices, including persistent face/edge names. One selection reports its physical size or coordinates; two report B-rep minimum distance, closest points and XYZ deltas. -The desktop accepts either selection count and displays command errors. Angles, -maximum/normal distances and sketch-entity measurement remain pending. +The desktop accepts either selection count and displays command errors. Angle mode now +supports two planar faces/straight edges, including mixed pairs, using unoriented +supporting geometry in 0–90°. Curved angle geometry, maximum/normal distances and +sketch-entity measurement remain pending. Body visibility now has registered show/hide/isolate/exit/show-all commands. Hidden bodies remain in modeling and export, but are excluded from rendering, picking and From 0e7aa1881cb371bfb146f97bbcfdfd4da6e5d99c Mon Sep 17 00:00:00 2001 From: Wisdom International Date: Fri, 2 Oct 2026 00:15:58 -0400 Subject: [PATCH 2/4] Document agent angle semantics and test degenerate edge rejection --- Sources/ForgeCommands/Commands/QueryCommands.swift | 2 +- Tests/ForgeCommandsTests/MeasurementTests.swift | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/ForgeCommands/Commands/QueryCommands.swift b/Sources/ForgeCommands/Commands/QueryCommands.swift index 43a237b..7ba9a14 100644 --- a/Sources/ForgeCommands/Commands/QueryCommands.swift +++ b/Sources/ForgeCommands/Commands/QueryCommands.swift @@ -208,7 +208,7 @@ public enum QueryMeasure: Command { public static let fieldDocs: [String: FieldDoc] = [ "from": "Body, face, edge or vertex reference (including persistent face/edge names)", "to": "Optional second reference for distance; required for angle", - "mode": FieldDoc("distance or angle; angle accepts planar faces and straight edges", default: "distance"), + "mode": FieldDoc("distance or angle; angle requires two planar faces/straight edges (mixed pairs allowed), returning angle_degrees in [0, 90] between unoriented supporting planes/lines", default: "distance"), ] } public struct EntityMeasurement: Codable, Sendable { diff --git a/Tests/ForgeCommandsTests/MeasurementTests.swift b/Tests/ForgeCommandsTests/MeasurementTests.swift index 1f696a6..48cbeb6 100644 --- a/Tests/ForgeCommandsTests/MeasurementTests.swift +++ b/Tests/ForgeCommandsTests/MeasurementTests.swift @@ -179,8 +179,11 @@ struct MeasurementTests { let b = try #require(await e.activeDocument?.bodies["body-2"]) let curvedFace = try #require((0..<(try b.shape.topology().faces)).first { (try? b.shape.face($0).surfaceType) == .cylinder }) let curvedEdge = try #require((0..<(try b.shape.topology().edges)).first { (try? b.shape.edge($0).curveType) == .circle }) + try await e.execute("body.create_sphere", ["radius": 5]) + let sphere = try #require(await e.activeDocument?.bodies["body-3"]) + let degenerate = try #require((0..<(try sphere.shape.topology().edges)).first { (try? sphere.shape.edge($0).isDegenerate) == true }) let before = try await e.execute("document.state").result - for unsupported in ["body-1", "body-1/vertex-0", "body-2/face-\(curvedFace)", "body-2/edge-\(curvedEdge)"] { + for unsupported in ["body-1", "body-1/vertex-0", "body-2/face-\(curvedFace)", "body-2/edge-\(curvedEdge)", "body-3/edge-\(degenerate)"] { do { try await e.execute("query.measure", ["from": .string(top), "to": .string(unsupported), "mode": "angle"]) Issue.record("unsupported angle geometry accepted") From 9f667a5f2c1eff579b6d6d2cf071a836957cfd6f Mon Sep 17 00:00:00 2001 From: Wisdom International Date: Fri, 2 Oct 2026 00:22:30 -0400 Subject: [PATCH 3/4] Avoid nested Swift Testing requirement macros --- Tests/ForgeCommandsTests/MeasurementTests.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/ForgeCommandsTests/MeasurementTests.swift b/Tests/ForgeCommandsTests/MeasurementTests.swift index 48cbeb6..09c7b84 100644 --- a/Tests/ForgeCommandsTests/MeasurementTests.swift +++ b/Tests/ForgeCommandsTests/MeasurementTests.swift @@ -154,7 +154,8 @@ struct MeasurementTests { let doc = try #require(await e.activeDocument) let b = try doc.body("body-2") let ref = try EntityRef.parse(otherEdge) - let name = try #require(b.naming?.edges[try #require(ref.index)]) + let index = try #require(ref.index) + let name = try #require(b.naming?.edges[index]) let namedEdge = "body-2/edge@\(name)" var tiltedFace = "" for i in 0..<(try b.shape.topology().faces) { From f78c4d62ebb80574bbc8917df5011c686ebbc46c Mon Sep 17 00:00:00 2001 From: Wisdom International Date: Fri, 2 Oct 2026 00:29:52 -0400 Subject: [PATCH 4/4] Record angle measurement scope and verified validation --- PROGRESS.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/PROGRESS.md b/PROGRESS.md index 6e5c1b5..1709daf 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -1,5 +1,35 @@ # Progress +## Session 13 — 2026-10-02 — Planar face and straight edge measurement angles + +- `query.measure` and MCP `measure` accept `mode: "angle"` for two planar faces or + straight edges, including mixed pairs, and return `angle_degrees`. Default single + entity properties and minimum distance behavior remain unchanged. +- Angles use unoriented supporting planes/lines in 0–90°: parallel or antiparallel + geometry gives 0°, perpendicular planes/lines give 90°, and a line normal to a plane + gives 90°. Stable atan2 formulas cover near-parallel/perpendicular cases. Curved + faces/edges, degenerate edges, bodies and vertices fail with structured errors. +- macOS and shared Windows/Linux PropertyManagers offer a mode picker with scope and + degree labels. Mode changes clear old results; async results check both selection and + requested mode before display. Persistent names keep the existing single-entity rules. +- Added analytic cardinal/oblique/near-boundary angles, reversed directions, mixed-pair + symmetry, persistent face/edge references after rebuild, explicit unsupported-geometry + errors (including spherical degenerate edges), read-only/default-distance checks, + desktop mode switching and a real MCP angle/error subprocess workflow. + +Validation: isolated Apple Silicon checkout with Xcode/Swift **6.4** and locally built +pinned **OCCT 8.0.1**, limited to three build jobs. Native app + test build and all +**384 Swift tests** pass; all **33 golden models** and **six MCP subprocess workflows** +pass. CI validates Linux headless (including **three packaging regressions** and shared +Windows frontend type checking), CachyOS, native macOS and Windows builds/runtime +checks. Matrix synchronization and whitespace checks pass. No app windows were opened +on the live desktop. Local macOS packaging checks pass 2/3: the existing Windows fetch +script's GNU `find -printf` requirement prevents its DLL-path fixture from passing with +BSD find; those unrelated files are unchanged and all three pass in Linux CI. + +Remaining scope: curved/tangent/directed/reflex angle measurements, maximum/normal +and projected distances, sketch-entity measurements and broader SolidWorks parity. + ## Session 12 — 2026-09-30 — Selected contours, planar limits and selection filters - Added `sketch.regions` with stable complete-curve selectors, holes, nested islands,