Commit Graph

35 Commits

Author SHA1 Message Date
NiJingzhe f448af37f4 fix: an OCCT failure while reading a geometry type or closedness makes the property absent, as in 2.2.6
2.2.6 wrote `except Exception: return MISSING` around the OCP calls (ql._geometry_property); OCP's Standard_Failure is an
Exception there. The C++ port caught std::exception, which OCCT's exceptions do not derive from, so an OCCT failure in
shape_geom_type (reactive/geo_selection.cpp) and in geom.closed (ql/property.cpp: is_wire_closed / shell_is_closed,
which are not under occt_guard) escaped instead of yielding no value. Both now catch Standard_Failure explicitly.

DEVIATIONS.md records (with a test) the other difference found in the same review of a real agent session: a
scad.var expression used as a ql predicate value is evaluated here and matched nothing in 2.2.6.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:53:53 +08:00
NiJingzhe fee292c3cd refactor(optional): the last unchecked optional access (selection.cpp) uses require_engaged
clang-tidy on the previous commit left one site of 70: reservation.value() on the line after if (reservation), which its
dataflow no longer follows across the calls in between. Same helper as the other 69 sites; behaviour unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 03:01:14 +08:00
NiJingzhe 971f42f9c0 refactor(optional): every optional access is dominated by a check or names its invariant
Behaviour is unchanged for valid inputs.  Accessors that an invariant guarantees engaged
(gear radii of a coupling, anchor geometry_ref/placement, Property key path, gear root
fillets, B-spline fit best, last_solve_, ...) go through the new scad::require_engaged
(core/engaged.hpp), which throws RuntimeError "internal invariant violated: ..." instead
of undefined behaviour.  Other sites bind the optional once (accessor results, at[i]
selector ends, residual maps) so the test dominates the dereference.  No site was found
where an empty optional is reachable from valid input.

Checked by: ninja build, ctest 14/14, src/cpp/tests/python 471 passed/1 skipped, the old
test/ suite (no failures), g++-16 -fsyntax-only on all 28 touched .cpp files.
clang-tidy itself could not be run locally.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 02:30:44 +08:00
NiJingzhe af2b6015e2 refactor(catch): every swallowed failure is an explicit, narrowed fallback
Behaviour is unchanged: each empty catch body now assigns/returns the value the code
already ended up with (nullopt, 0.0 term, skipped selector keys), and the caught type
is narrowed where the guarded call is known to throw only that type (Standard_Failure,
KernelError, scad::Exception, ValueError).  Sites whose type could not be proven
(ql loop_role/geomclosed, geo_selection shape_geom_type) keep std::exception and say so.
Session::~Session drops a try/catch around the noexcept stop().

Checked by: ninja build, ctest 14/14, src/cpp/tests/python 471 passed/1 skipped,
and the whole old test/ suite (no failures).  clang-tidy itself could not be run locally.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 02:21:47 +08:00
NiJingzhe 424a8121b4 ci: the C++ Release and ASan/UBSan jobs and the stub check are required
All three passed on Linux (14/14 doctest executables in both builds; the checked-in stubs, generated on macOS, are
reproduced). clang-tidy stays advisory: it fails on compile errors only, never on its warnings.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 01:23:00 +08:00
NiJingzhe 5d6b191c65 ci: LSan skips OCCT's process-lifetime singletons
The first run with the alignment check suppressed left only 112 bytes in 4 allocations (TPrsStd_DriverTable::Get and
TCollection_AsciiString allocated in static initialisation), with every doctest case of the io area passing.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 01:03:48 +08:00
NiJingzhe 674137dac1 ci: UBSan skips the alignment check for everything that comes from OCCT's headers
The first run reported TopoDS.hxx, the next TopoDS_Shape.hxx: one misaligned TopoDS_Shape read inside OCCT's mesher.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 00:44:32 +08:00
NiJingzhe b302ca8452 test/ci: the default bolt is held to 2.2.6's value on each platform; UBSan skips OCCT's own misaligned TopoDS read
- test_fastener: the modeled-thread topology depends on the platform's OCCT build. 2.2.6.post2 (OCP) gives 54 faces /
  116 edges on macOS arm64 and 56 / 117 on Linux x86-64 (measured in a linux/amd64 container; volume equal to 1e-8), and
  this engine gives the same on each. The doctest asserts the value 2.2.6 gives on the platform (Linux x86-64: 56 / 117;
  otherwise the macOS one) instead of failing on Linux.
- tools/ubsan.supp: the alignment reports of the sanitizer job are all inside OCCT's mesher (BRepMesh_* ->
  TopoDS::Face); only that check, only for OCCT's TopoDS.hxx, is suppressed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 00:26:49 +08:00
NiJingzhe 4f5bcd7bc8 test: the verifier-bridge test follows shape.wrapped becoming an OCP shape
PR #67's test_the_sdk_wrapped_shape_is_not_an_ocp_shape asserted that OCP rejects shape.wrapped; with OCP installed
wrapped is now an OCP shape (a deliberate change of this branch). The original assertion is kept for the SDK's own
binding (SCA_WRAPPED=native), and a new test pins the new default: OCP measures solid.wrapped.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 22:54:38 +08:00
NiJingzhe 0ae7e58fb0 fix(tests): the reference interpreter is never this repository
ref.py defaulted to <repo parent>/SimpleCADAPI/.venv; in a CI checkout (<work>/SimpleCADAPI/SimpleCADAPI) that is the
repository itself, so the SDK under test became its own 2.2.6 reference and test_the_reference_sdk_accepts_our_snapshot
failed on every Python version. The default is now absent in that case (the test skips), as before.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 22:40:40 +08:00
NiJingzhe cc9c347027 Merge PR #67 (simplecadapi.verify, the verify extra) into the serve branch
verify.to_ocp / from_ocp now delegate to the bridge of this branch (_glue.bridge), which also backs shape.wrapped when
OCP is installed: one conversion, one place. The verifier-scripts skill reference and the CHANGELOG say that
shape.wrapped is an OCP shape with the extra (PR #67 described it as the SDK's own binding). CI: the verifier-bridge
step is kept next to the C++ parity and stub steps.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 20:23:53 +08:00
NiJingzhe 497db134e2 Merge PR #66 (fillet, chamfer and ql failure pictures) into the serve branch
#66 implements the same pictures as this branch's d54d0d0 and also shades highlighted faces with the standard
material, which makes test_ql_evidence_highlight_is_visible pass (it was listed as open here). Resolution: #66's
blend diagnosis, blends.cpp, diagnostics.hpp and evidence.py win; this branch's DiagnosticImage.highlight_edges field
and provider argument are dropped (unused); raster.cpp keeps this branch's split draw_panel with #66's shade() change
re-applied; the open entry of the ql test is removed; evidence.py compares native shapes (_native_wrapped) because
.wrapped is an OCP shape here, and says on stderr when a 2D picture cannot be drawn.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 20:22:29 +08:00
NiJingzhe 53cbdc8ba0 fix: CI stub step quoting; stubs without test-only modules; the sanitize and stub jobs are advisory; dead nested workflows removed
- gen_stubs.sh: the interpreter word-splits (CI sets PYTHON="uv run --no-sync python"); the stubs of the test-only
  modules and two unresolvable builtins imports are left out.
- ci.yml: the ASan/UBSan job and the stub-freshness step are continue-on-error until each has run green once.
- src/cpp/.github/workflows (never read by GitHub) is deleted; CONTRIBUTING/READING_ORDER/LANDING_PLAN corrected.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 17:44:08 +08:00
NiJingzhe ee96102f9c build: make the generated stubs reproducible
pybind11-stubgen emits the re-export imports in set order; gen_stubs.sh sorts each run of import lines, so --check
(run in CI) is stable: three consecutive checks after generating are fresh.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 17:35:18 +08:00
NiJingzhe 01ab3ca2bb refactor(io,reactive): glb_json and Session::recompute below the 80-line limit
Behaviour is unchanged: the accessor/bufferView JSON and the input gathering
moved into named helpers with the same statement order. Verified with the 14
ctest targets, the 471 Python tests in tests/python and the old mesh export,
notebook, editor, cache and expr_graph suites.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 17:30:11 +08:00
NiJingzhe eeb312c5d6 refactor(ql,std,semantic,sketch,surface,reactive,topo): split the remaining long functions
cardinality_failure, ShapeSelector::from_value, build_gear_profile_sketch,
apply_tracking_tags, Shape::to_string, assemble_solution, Sketch::add_bspline,
make_cylindrical_surface_rface, geo_selector_score, make_geo_exact_selector.
Behaviour is unchanged: validation and OCCT call order are kept; float sums
keep their operation order. Verified with the 14 ctest targets, the 471
Python tests in tests/python and the old ql, gear, sketch, surface,
tagging, serialization and inspect suites.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 17:25:52 +08:00
NiJingzhe 954ec58da0 refactor(render,std,io,semantic,reactive,product,ops): split render_scene, make_ball_bearing_rassembly, glb_bytes, assign_tag, resolve_recorded_delta, solve_assembly_constraints, ExpressionGraph::from_value, loft diagnosis, Session::recompute
Behaviour is unchanged: statement order, throws, recorded params and OCCT
call order are kept; helpers only carry code out of the long functions.
Verified with the 14 ctest targets, the 471 Python tests in tests/python
and the old stdlib, product, assembly, tagging, expr_graph, cache, editor,
ql, notebook and diagnostics suites.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 17:17:50 +08:00
NiJingzhe e792c0efb2 refactor(render,reactive,io,std,sketch,semantic): split draw_panel, OperationGraph::from_value, validate_manifest, decode_artifact, make_bolt_rsolid, raise_sketch_solve_failure, tracked_twisted_sweep
Behaviour is unchanged: each function became an outline over named helpers with
the same statement order, throws and OCCT call order; lookup table in
entity_type_of left as is (commented). Verified with the 14 ctest targets,
the 471 Python tests in tests/python and the old brep_region, render,
fastener, sketch diagnostics, graph and serialization suites.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 17:09:42 +08:00
NiJingzhe b4f8067f26 refactor: name the tolerances (scad::tol) instead of repeating their numbers
include/scad/core/tolerance.hpp holds 38 constants, each named for what it is a tolerance for, with a how-to-choose
comment and a table. 116 sites in 56 files use them; every constant has exactly the value of the literal it replaces,
so nothing computes differently (ctest and the golden parity tests unchanged). About 110 literals stay where they
are on purpose: OCCT mirror bindings, solver constants that already have local names, relative-times-floor
combinations, raster/render epsilons.

Six ambiguous sites are listed in the CHANGELOG-free note of the commit for the owner:
extrude_until.cpp:68 (1e-8 sine test), :193 (extent below 1e-12 uses kDegenerateNorm), probes.cpp:207,228,
bind_surface.cpp:75 (interpolation default 1e-5 vs kSplineInterpolation 1e-6), tracking.hpp:148 (tracked_shell tol),
BuildCurves3d at 1e-6 (kernel/curves.cpp:177) and 1e-7 (tracking_lofts.cpp:254).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 16:58:17 +08:00
NiJingzhe 764e4a3324 docs: a human README, CONTRIBUTING, reading order and landing plan; the agent notes are retired
- CONTRIBUTING.md: build, the test layers, golden policy, format, error, GIL, thread-safety and parity rules.
- docs/READING_ORDER.md and docs/LANDING_PLAN.md (+ tools/landing_plan.py): how to read the tree, and 10 PRs that
  account for every file of the port (a plan: the stacked branches were not created or built one by one).
- README.md replaced; ARCHITECTURE.md and NATIVE_PROGRESS.md corrected; AGENTS.md and HANDOFF.md removed (what was
  still true moved into the human docs); PORTING_STATUS.md marked as a stale snapshot.
- tests/python/ref.py no longer hard-codes the maintainer's home: SCAD_REF_PYTHON, else the checkout next to this one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 16:50:41 +08:00
NiJingzhe 7345e01453 refactor(bindings): one exception translator ordered by priority; the OCCT guard audit is clean and strict
- The four py::register_exception_translator calls (common, reactive graph, reactive units, raw OCCT shim) become
  handlers of one translator that asks them most specific first (ExceptionPriority), so the result no longer depends
  on the order the areas are bound in (UnitValidationError is an Error, StaleLineageError a ValueError).
- check_occt_guard.py accepts operator_scope and a one-line claim that the one caller runs the helper inside
  occt_guard; the 7 reported sites were helpers of guarded operators and now say so. CI runs it with --strict.
- Tests: Standard_Failure, UnitValidationError and StaleLineageError each keep their own Python class.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 16:48:22 +08:00
NiJingzhe a4c39a341d ci: format check, ASan/UBSan job, golden strictness, stub freshness, occt-guard audit
- format job (clang-format 18.1.8, no OCCT needed); sanitize job (ASan+UBSan, ctest, LSan suppression file);
  advisory clang-tidy on changed files; occt-guard audit (tools/check_occt_guard.py, non-blocking until clean).
- tests/python/ref.py: SCAD_GOLDEN_STRICT=1 (set in CI) makes a missing golden an error and refuses SCAD_REGOLDEN.
- src/cpp/tests/python now runs in CI (it was not in pytest testpaths).
- tools/gen_stubs.sh generates the .pyi of the extension; CI fails when the checked-in stubs are stale.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 16:36:04 +08:00
NiJingzhe 7edd550f29 style: add .clang-format and format the C++ tree with it
One mechanical pass (clang-format 18.1.8, Google base, 120 columns, T& x, includes untouched). Nothing but whitespace and
line breaks moves; tools/check_format.sh lists what would change and CI runs it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 16:28:29 +08:00
NiJingzhe d54d0d0baa fix: a failing fillet/chamfer and a failing ql exactly() attach their evidence picture again
2.2.6 drew one picture for each (the failing edge as an orange line; the matched faces orange and the near misses
purple). The native port attached none, and the old test file that asserts them was one of those the port deleted.

- BlendDiagnosis carries the edges and the caption of the six probes (the old ones); raise_blend_failure asks for
  the picture through DiagnosticImage (new field highlight_edges), the provider call gets the edges.
- evidence.py draws it, and the ql picture through the existing ql evidence hook, on a clone of the scope: the
  user's shape is not tagged.
- test_error_diagnostics_blend_ql.py is restored (13 tests). 12 pass; test_ql_evidence_highlight_is_visible is
  listed as open: the picture is right but the soft renderer's shading leaves 302 sampled orange pixels where the
  test asks for more than 400.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 03:36:37 +08:00
NiJingzhe ebe892a465 test: restore test_rearchitecture_2_0_kernel_builders; record the old tests that do not apply
The file was deleted by the C++ port; its 5 tests pass on native (one is in the known-failures list as an internal).
DEVIATIONS.md lists the old tests of the removed VTK render pipeline and of the py-slvs default, each with the reason.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 02:05:58 +08:00
NiJingzhe 609e2bc895 perf(editor): fewer kernel round trips per settle, background tessellation, vectorised edge keys
A settle lists the cells in the call that publishes the preview (one call into the kernel, not three), the boot's
duplicate settle is dropped, the debounce is 0.12 s, parts are tessellated on a background thread while the next
cell computes (cached_mesh releases the GIL; a failure is recorded on the shape under the GIL), and the edge
position keys are computed with numpy (byte-identical).  Six-axis arm, last cell to preview event: ~0.83 s -> ~0.36 s.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 04:27:02 +08:00
NiJingzhe b626269ecf feat(verify): simplecadapi.verify and the verify extra for verifier scripts; drop the fem extra
shape.wrapped is the SDK's own binding, so OCP functions reject it and verifier scripts that did
BRepGProp.VolumeProperties_s(solid.wrapped, ...) stopped working with the C++ engine. simplecadapi.verify.to_ocp / from_ocp
bridge through OpenCASCADE's binary format; the verify extra installs OCP 7.9 without VTK. The SDK itself never imports OCP.
The skill gets references/discipline/verifier-scripts.md, whose code the tests execute.

The fem extra (gmsh, ccx2paraview[VTK]) is removed with the README steps that used it; vtk is out of the lock file.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 01:13:18 +08:00
NiJingzhe 476511bf9c fix(diagnostics): fillet, chamfer and ql failures carry their picture again
2.2.7b1 requested a failure picture for booleans only. The blend diagnoses now name the edges to mark and the
operator asks for the render; the ql evidence provider (the C++ hook existed, nothing registered it) renders the
scope with matched faces orange and near misses purple. Highlighted faces use the standard material as the VTK path did.
Restores test_error_diagnostics_blend_ql.py and test_rearchitecture_2_0_kernel_builders.py, deleted when the engine was ported.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-27 15:30:33 +08:00
NiJingzhe 3788f03de1 feat(inspect): inspect.brep is part of the default install
matplotlib moves to the core dependencies; the inspect extra stays as an empty alias so older
install commands work. The wheel smoke test renders a STEP through inspect.brep.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 16:28:55 +08:00
NiJingzhe bd36d584f0 feat(ops): cut_rsolid_list keeps every piece; cut_rsolid refuses to drop pieces
A cut that splits the body returned only the first solid from cut_rsolid, silently losing the rest
(a slot through a bar reported half the volume). cut_rsolid_list returns all pieces (empty when the
body is consumed), is recorded as make_cut_rsolid_list and replays. cut_rsolid now raises when the
result is not exactly one solid and names cut_rsolid_list. Tests that relied on the dropped sliver
of a tangent cut use a tool that does not touch the walls.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 03:28:28 +08:00
NiJingzhe f3936f5844 test(std): modeled-thread phase is a search result, not a contract
The builders keep the first candidate angle whose Boolean is valid; which one that is
depends on last-bit floating point of the helix sweep, so it differs between platforms.
The angle and the topology counts it implies are dropped from the comparison.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 02:02:15 +08:00
NiJingzhe 9333290fa1 test: one geometric tolerance for the parity tests (1e-4), not one exception per case
Areas, volumes and bounding boxes of the parity tests come out of OpenCASCADE's numerical integration and
optimisation, which differ between OCCT builds at the 1e-5 level.  GEOMETRY_REL (ref.py) is the default of every
comparison helper; counts, names, ids and strings are still compared exactly.  Replaces the per-name exception for
the modeled-thread areas.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 23:14:10 +08:00
NiJingzhe 34c74e7685 test: modeled-thread areas are compared at 1e-4
OpenCASCADE's integration over the B-spline thread faces differs between builds at the 1e-5 level (the static OCCT of
the Linux wheels against the reference's); the geometry is the same.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 23:07:10 +08:00
NiJingzhe e770913e57 fix: build with Apple clang 15 and MSVC; the release workflow selects platforms and keeps the OCCT cache
First runs of the release workflow on GitHub found portability errors that the local toolchains accept:
- Apple clang 15 (Xcode 15.4) cannot capture a structured binding in a lambda (role_tags.cpp);
- windows.h defines near and far as empty macros: parameters and locals named near/far/small are renamed
  (probes.cpp, sketch/diagnostics.cpp and the C++ tests).
Checked the whole C++ tree with clang 15 + libc++ 15: no other failure.

Workflow: a platforms input for dry runs, Ninja with -k 0 on Windows (all compiler errors in one run), the static
OCCT cache is saved even when the wheel build fails, setup-uv without a cache where nothing is cached.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 12:37:07 +08:00
NiJingzhe 8971279494 feat: the geometry engine is C++ on OpenCASCADE, one package, prebuilt wheels
The modeling API (shapes, operators, sketches, products, queries, the reactive graph) is implemented in
C++20 on OpenCASCADE (src/cpp) and ships inside the wheel as simplecadapi._cpp.  The Python layers that stay
Python (runtime, build, artifacts, editor, inspect, exporter, translators, scene) run on it unchanged; the
previous Python test suite passes on the new engine.

Layout: src/cpp and src/simplecadapi side by side, one distribution built by scikit-build-core.
simplecadapi.core, .operators.*, .ql, .std.* and the other legacy modules are real forwarding modules; the
Python adapter layer is simplecadapi/_glue.  OCP is no longer a dependency and nothing imports it.

Release: .github/workflows/release.yml builds wheels for Linux x86_64 and aarch64, macOS arm64 and Windows
x86_64 (Python 3.10-3.13) against one static OCCT, runs the test suite on the Linux wheels and publishes to
GitHub and PyPI; ci.yml caches the static OCCT for the test jobs.

Errors: every message the library writes is English; the tag-validation and semantic-query errors render in
full with possible causes and fixes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 02:55:35 +08:00