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: object

The ambient curve-resolution settings.

Mirrors OpenSCAD’s $fn/$fa/$fs special variables plus the SDF backend’s res. A field left at None means “not set” – the renderer’s own default applies.

Parameters:
fn : int | None

fa : float | None

fs : float | None

res : int | None

fn : int | None

Fixed number of fragments per full circle; overrides fa/fs when 3 or more, and 0 means “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 from set_defaults(), otherwise an all-None Resolution.

Return type:

Resolution

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 None leaves that setting as it was, so set_defaults(fn=64) does not disturb an existing fs. Use reset_defaults() to clear. Prefer use_defaults() in library code – a global default reaches other people’s shapes too.

Parameters:
fn : int | None

Fixed number of fragments per full circle.

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.

Returns:

None.

Return type:

None

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 ContextVar holds the value).

Parameters:
fn : int | None

Fixed number of fragments per full circle.

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.

Yields:

The Resolution in effect inside the block.

Return type:

Iterator[Resolution]

Note

A single call opts out of an ambient fn by passing fn=0, which means “use fa/fs” exactly as OpenSCAD’s $fn=0 does.

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…

⬇ Download STL mesh

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:
fn : int | None

Caller-supplied fragment count, or None.

fa : float | None

Caller-supplied fragment angle, or None.

fs : float | None

Caller-supplied fragment size, or None.

Returns:

The three values with any None replaced by the ambient setting (still None when nothing is set anywhere). fn=0 passes through unchanged: it is the caller opting out of an ambient fn, and frag_count() reads any fn below 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 and resolve_res() both call. They were two implementations of one rule (SPEC R-1).

pybosl2.defaults.resolve_res(res=None)[source]

Fill in the SDF sampling resolution from the ambient defaults when the caller left it unset.

Parameters:
res : int | None

Caller-supplied resolution, or None.

Returns:

The resolution to use, or None when nothing is set anywhere.

Return type:

int | None