This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
BOSL2 (Belfry OpenSCAD Library v2) is a comprehensive OpenSCAD library providing modeling tools, transformations, shapes, attachments, and parts. It requires OpenSCAD 2021.01 or later. The library is in beta status.
Run all regression tests:
./scripts/run_tests.shRun a single test file:
./scripts/run_tests.sh tests/test_shapes3d.scadOn macOS, the test runner uses /Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD. On Linux, it uses openscad from PATH.
Tests pass when OpenSCAD exits with code 0 and produces no output. Any output or non-zero exit indicates failure.
./scripts/check_for_tabs.shAll .scad files must use spaces only (no tabs). Indentation: 4 spaces.
Requires the openscad-docsgen Python package (pip install openscad-docsgen):
openscad-docsgen -Tmfpython3 scripts/func_coverage.pystd.scad is the main include file. Users write include <BOSL2/std.scad> to get the standard library. It includes files in a specific dependency order:
version → constants → transforms → distributors → miscellaneous → color → attachments → beziers → shapes3d → shapes2d → drawing → masks → math → paths → lists → comparisons → linalg → trigonometry → vectors → affine → coords → geometry → regions → strings → vnf → structs → rounding → skin → utility → partitions
Specialized modules (gears, screws, threading, hinges, etc.) are not included by std.scad and must be included separately by users.
- Attachment system (
attachments.scad): Core mechanism for positioning children relative to parents using anchor points, without manual coordinate tracking. Most shapes supportanchor,spin, andorientparameters. - VNF (
vnf.scad): Vertices 'N' Faces representation for polyhedra manipulation. Many functions can return VNF data via function form. - Paths/Regions (
paths.scad,regions.scad): 2D point-list operations for curves and polygon regions. - Skinning/Sweeping (
skin.scad): Creates 3D objects by sweeping profiles along paths. - Rounding (
rounding.scad): Edge rounding, filleting, and offset_sweep operations.
Many BOSL2 items exist as both OpenSCAD functions and modules (documented as Function&Module). The function form returns data (VNF, path, matrix), while the module form creates geometry. Example: cube() as a module creates a shape; as a function it returns a VNF.
Each file has a guard at the top that warns if included without std.scad:
_BOSL2_FILENAME = is_undef(_BOSL2_STD) && ... ?
echo("Warning: filename.scad included without std.scad") true : true;Test files go in tests/ named test_<module>.scad. Pattern:
include <../std.scad>
module test_function_name() {
assert(function_name(args) == expected);
}
test_function_name();Each test is a module containing assert() calls, immediately invoked after definition. Tests must produce zero output to pass.
Every public function/module must have documentation comments following the custom block syntax parsed by openscad-docsgen. Required blocks:
// Function&Module: name()
// Synopsis: One-line summary.
// Topics: Topic1, Topic2
// See Also: related_func()
// Usage: As Module
// name(arg1, arg2);
// Usage: As Function
// result = name(arg1, arg2);
// Description:
// Detailed description. Supports markdown.
// Link to other items with {{other_func()}} syntax.
// Arguments:
// arg1 = Description of arg1
// arg2 = Description of arg2
// Example:
// name(10, 20);See WRITING_DOCS.md for the full documentation syntax reference. Configuration is in .openscad_docsgen_rc.
- Private functions/modules: prefix with underscore (
_helper_func()) - Public names: lowercase with underscores
- Constants: UPPERCASE (
UP,DOWN,LEFT,RIGHT,FRONT,BACK) - Special variables use
$prefix ($slop,$fn) - Files end with:
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap - No tabs in
.scadfiles; use 4-space indentation
Pull requests run three checks:
- Regressions: Runs
scripts/run_tests.sh(fast, under a minute) - CheckTutorials: Validates tutorial markdown and images (~8 minutes)
- CheckDocs: Validates all documentation blocks with
openscad-docsgen -Tmf(35-40 minutes)