Skip to content

render() in expression position: measure your own geometry - #269

Merged
revarbat merged 4 commits into
mainfrom
render-expression
Aug 21, 2026
Merged

revarbat merged 4 commits into
mainfrom
render-expression

Conversation

@revarbat

Copy link
Copy Markdown
Member

Requires openscad_cpp_evaluator 0.38.0 (published), which is where the implementation lives — see BelfrySCAD/openscad_cpp_evaluator#104 and BelfrySCAD/openscad_cpp_parser#5. This PR is the pin, the lock, and the docs.

part = render() difference() {
    cube([60, 40, 20], center = true);
    cylinder(h = 40, r = 12, center = true, $fn = 48);
};

echo(part.volume, part.genus, part.boundingbox);   // 38978, 1, [[-30,-20,-10],[30,20,10]]
polyhedron(part);                                  // the mesh goes straight back in

A script can now measure its own geometry — volume, surface area, genus, bounding box, and the mesh itself. None of that was reachable before: the numbers only exist after the geometry is built, and the language had no way to reach them.

It draws nothing

The expression form builds its children, measures them, and discards the geometry. That is what keeps the semantics uniform — no side effects, so top level, module bodies, function bodies, list comprehensions and ternaries all behave identically, and function purity survives:

function fits(r) = (render() { sphere(r, $fn = 32); }).volume < 1000;

Two things that will bite

  • render is now a reserved keyword — it cannot be a variable, module, function, argument, or member name. Not a stylistic choice: LALR(1) cannot tell render( in expression position from a function call, and bison's shift-over-reduce would silently turn every function call in an expression into a module instantiation. BOSL2 uses none of these (checked).
  • obj = render() cube(1); does not parse. A bare call's child_statement swallows the ;, leaving the assignment unterminated. Use render() { cube(1); }. Inherent to OpenSCAD's grammar; asserted in tests rather than worked around.

Both documented in CLAUDE.md, flagged as a language extension — not part of upstream OpenSCAD.

Notes

render deliberately stays in editor.py's _BUILTIN_MODULES rather than moving to the highlighter's keywords list: echo and assert are grammar keywords too and live there, so moving only this one would be the inconsistent choice. Completion already works from _BUILTIN_MODULES.

The lock was verified to carry all 6 wheels plus the sdist before pushing — a partial set has slipped through twice before. Worth recording that uv cache clean <pkg> was not sufficient: it clears package artifacts but not the cached simple-index response, so the first lock attempt still resolved against 0.37.0. uv lock --refresh-package is what picked up the new release.

Verification

Ran end-to-end against the published 0.38.0 wheel (not a local editable build): measurements correct, genus = 1 for a through-hole, and polyhedron(part) round-trips to exactly 208 facets / 104 vertices with the same surface area and bounding box.

Upstream: 953 evaluator tests pass under both OSCAD_BYTECODE_VM=0 and =1, ASan clean; 647 parser tests pass.

🤖 Generated with Claude Code

revarbat and others added 4 commits August 20, 2026 15:51
    obj = render() difference() { cube(100); sphere(20); };
    echo(obj.volume, obj.genus, obj.boundingbox);
    polyhedron(obj);

A script can now measure its own geometry. The expression form of render()
builds its children, measures them, and DISCARDS the geometry -- nothing is
drawn -- so the same rule holds at top level, in a module body, in a
function body, in a list comprehension and in a ternary, and function
purity survives.

Documented in CLAUDE.md as a language EXTENSION, not part of upstream
OpenSCAD, with the two things that will actually bite someone: `render` is
now a reserved keyword, and `obj = render() cube(1);` does not parse
because a bare call's child_statement swallows the semicolon.

`render` deliberately stays in editor.py's _BUILTIN_MODULES rather than
moving to the syntax highlighter's `keywords` list: `echo` and `assert` are
grammar keywords too and live there, so moving only this one would be the
inconsistent choice. Completion already works from _BUILTIN_MODULES.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Verified the lock carries all 6 wheels plus the sdist before pushing -- a
partial wheel set has slipped through twice before.

Note `uv cache clean openscad_cpp_evaluator` was NOT sufficient here: it
clears the package artifacts but not the cached simple-index response, so
the first lock attempt still resolved against 0.37.0 and failed. `uv lock
--refresh-package openscad-cpp-evaluator` is what actually picked up the
new release.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Reported symptom: the bar's background stayed off-white while its text
followed the dark palette to white, so the whole panel was near-invisible.

The cause was one hardcoded QColor("#F3F3F3") -- but the same mistake
appeared four times in FindBar, and fixing only the reported one would have
left the user to rediscover the rest immediately:

- bar background: hardcoded light grey
- "No results" field: pale pink with NO foreground set
- current match: white on #FF9900 -- only ~2.3:1, poor even in light mode
- other matches: pale amber with NO foreground set

The last three share the reported bug's root cause: a pale background with
no explicit text colour, so the text follows the palette and vanishes the
moment the app goes dark. Both match formats and the no-match field now set
their foreground explicitly, which makes them theme-independent rather than
merely dark-corrected.

Colours live in ui_colors.py beside gutter_colors()/header_colors(),
following that module's light/dark-pair convention. The bar also registers
on_appearance_change() so a live theme switch repaints it (and re-runs the
highlights, which may already be on screen) instead of only painting once
at construction.

The current match's foreground changed from white to black. That is a
light-mode change the report did not ask for, but white on #FF9900 was
below any readable threshold; black measures 9.8:1.

Verified with a throwaway contrast script rather than by eye, since this
sandbox cannot screenshot -- which is what caught the first attempt at the
dark no-match red at 3.7:1. Every pair now measures above 7:1 in both
themes. User confirmed the result visually in the running app before this
commit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
0.38.0 silently produced a non-manifold solid with the wrong volume for any
mesh whose shells touch -- welding coincident vertices fused them. See
BelfrySCAD/openscad_cpp_evaluator#105.

The lock needed two attempts. The first, taken immediately after the wheels
workflow reported success, captured only 3 of the 7 files: PyPI's index had
not finished propagating, so Windows, manylinux x86_64 and the sdist were
missing and the lock would have failed to install on those platforms. Third
time this has bitten the project, and only the post-lock file-count check
catches it -- neither uv nor the workflow reports anything wrong.

So: wait until PyPI's simple index actually lists all 7, THEN lock, THEN
verify the count before pushing. Note `uv cache clean` alone is not enough
either -- it clears package artifacts but not the cached index response,
which is why --refresh-package is required.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@revarbat
revarbat merged commit 40324d9 into main Aug 21, 2026
4 checks passed
@revarbat
revarbat deleted the render-expression branch August 21, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant