Repository navigation
render() in expression position: measure your own geometry - #269
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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:
Two things that will bite
renderis now a reserved keyword — it cannot be a variable, module, function, argument, or member name. Not a stylistic choice: LALR(1) cannot tellrender(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'schild_statementswallows the;, leaving the assignment unterminated. Userender() { 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
renderdeliberately stays ineditor.py's_BUILTIN_MODULESrather than moving to the highlighter'skeywordslist:echoandassertare 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-packageis 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 = 1for a through-hole, andpolyhedron(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=0and=1, ASan clean; 647 parser tests pass.🤖 Generated with Claude Code