Defaults¶
Ambient curve-resolution defaults (fn/fa/fs/res) for a block or a session
Ambient curve-resolution defaults (fn/fa/fs/res) for a block or a session.
-
class pybosl2.defaults.Resolution(fn=
None, fa=None, fs=None, res=None)[source]¶ Bases:
objectThe ambient curve-resolution settings.
Mirrors OpenSCAD’s
$fn/$fa/$fsspecial variables plus the SDF backend’sres. A field left atNonemeans “not set” – the renderer’s own default applies.- fn : int | None¶
Fixed number of fragments per full circle; overrides fa/fs when 3 or more, and
0means “ignore any ambient fn, use fa/fs” (SPEC R-5).
- fa : float | None¶
Minimum fragment angle in degrees.
- fs : float | None¶
Minimum fragment size in millimetres.
- res : int | None¶
Sampling resolution for the SDF backend.
- pybosl2.defaults.current_defaults()[source]¶
Return the resolution settings in effect right here.
- Returns:¶
The block-scoped settings if inside a
use_defaults()block, otherwise the ones fromset_defaults(), otherwise an all-NoneResolution.- Return type:¶
-
pybosl2.defaults.set_defaults(fn=
None, fa=None, fs=None, res=None)[source]¶ Set the process-wide resolution defaults.
Only the arguments given are changed; passing
Noneleaves that setting as it was, soset_defaults(fn=64)does not disturb an existingfs. Usereset_defaults()to clear. Preferuse_defaults()in library code – a global default reaches other people’s shapes too.
- pybosl2.defaults.reset_defaults()[source]¶
Clear the process-wide resolution defaults, restoring the renderer’s own behaviour.
- Return type:¶
None
-
pybosl2.defaults.use_defaults(fn=
None, fa=None, fs=None, res=None)[source]¶ Apply resolution defaults to every shape built inside the block.
Settings nest: an inner block inherits the outer one and overrides only what it names. The block is thread- and async-safe (a
ContextVarholds the value).- Parameters:¶
- Yields:¶
The
Resolutionin effect inside the block.- Return type:¶
Iterator[Resolution]
Note
A single call opts out of an ambient
fnby passingfn=0, which means “use fa/fs” exactly as OpenSCAD’s$fn=0does.Examples
from pybosl2 import cyl from pybosl2.defaults import use_defaults with use_defaults(fn=64): cyl(height=20, radius=8).show()Loading 3-D preview…
-
pybosl2.defaults.resolve_facets(fn=
None, fa=None, fs=None)[source]¶ Fill in whichever of fn, fa, fs the caller left unset from the ambient defaults.
- Parameters:¶
- Returns:¶
The three values with any
Nonereplaced by the ambient setting (stillNonewhen nothing is set anywhere).fn=0passes through unchanged: it is the caller opting out of an ambientfn, andfrag_count()reads anyfnbelow 3 as “use fa/fs” (SPEC R-5).- Return type:¶
tuple[int | None, float | None, float | None]
Note
The rule itself lives in
resolved(), which this andresolve_res()both call. They were two implementations of one rule (SPEC R-1).