Regions

class bosl2.regions.Region(paths=())[source]

Bases: list

A 2-D region: a list of Path outlines, holes included.

BOSL2 represents a shape-with-holes as a list of paths (outline first, then the holes), and that is what this is – so, like Path, it subclasses list and stays a drop-in for the raw region data the toolkit already passes to region()/union().

Parameters:

paths (Sequence) – the outlines; each is coerced to a Path. A single flat point list is accepted and treated as one outline.

Examples

A rectangular plate with a rectangular hole (outline + one hole), extruded into a solid:

region = Region.with_holes(
    [[0, 0], [80, 0], [80, 60], [0, 60]],
    [[20, 20], [60, 20], [60, 40], [20, 40]],
)
region.geometry().linear_extrude(height=5).show()

⬇ Download STL mesh

classmethod with_holes(outline, *holes)[source]

A region from an outline plus hole outlines.

This is what a concentric DifferenceWithOffset produces: outline + inner hole, no clipping involved.

Parameters:
  • outline (Sequence)

  • holes (Sequence)

Return type:

Region

property outline: Path

The outer path.

property holes: list[Path]
offset(radius=None, delta=None, chamfer=False)[source]

Offset every path in the region.

Parameters:
  • radius (float | None)

  • delta (float | None)

  • chamfer (bool)

Return type:

Region

round_corners(radius=None, **kwargs)[source]
Parameters:
  • radius (float | list[float] | None)

  • kwargs (Any)

Return type:

Region

translate(v)[source]
Parameters:

v (Sequence[float])

Return type:

Region

bounds()[source]

[[min_x, min_y], [max_x, max_y]] over every path.

Return type:

ndarray

geometry()[source]

2-D geometry: the outline with the holes subtracted.

Returns:

A Bosl2Shape2D, so the result chains straight into the 2-D operators and the extruders.

Return type:

Bosl2Shape2D

fill()[source]

This region as 2-D geometry with its holes filled in – i.e. just the outline (OpenSCAD fill()).

Returns:

A Bosl2Shape2D.

Return type:

Bosl2Shape2D

hull(*others)[source]

The 2-D convex hull of this region, optionally together with others (more regions, paths, 2-D shapes or point lists) – OpenSCAD hull().

Returns:

A Bosl2Shape2D.

Parameters:

others (Shape2DLike)

Return type:

Bosl2Shape2D

linear_extrude(height, **kwargs)[source]

Extrude this region height along +Z into a 3-D solid (holes included), on whichever backend is active – a Bosl2Solid under the default CSG backend, a PyShape under use_backend("sdf"). See bosl2.paths.Path.linear_extrude() for the per-backend options.

The SDF backend’s prism is the union of the outlines’ fields, so it can only express a region of DISJOINT islands; a region with holes raises UnsupportedByBackend there.

Parameters:
  • height (float)

  • kwargs (Any)

Return type:

Solid

rotate_extrude(angle=360.0, **kwargs)[source]

Revolve this region about the Y axis into a 3-D solid; see rotate_extrude().

Returns:

A Bosl2Solid (csg backend only – the SDF backend has no revolve).

Parameters:
  • angle (float)

  • kwargs (Any)

Return type:

Bosl2Solid

debug_region(size=1, vertices=True)[source]

A debug view of this region: the filled region (as a thin flat solid) with every path’s vertices labelled in red – path a gets labels a0, a1, ..., path b b0, b1, ... (BOSL2 debug_region()). A single-path region defers to debug_polygon().

Returns:

A Bosl2Solid.

Parameters:
  • size (float)

  • vertices (bool)

stroke(width=1, **kwargs)[source]

Draw every path in this region as a closed solid line (see bosl2.drawing.stroke()).

Parameters:
  • width (float)

  • kwargs (Any)

dashed_stroke(dashpat=(3, 3), **kwargs)[source]

Break every path in this region into dash sub-paths (see bosl2.drawing.dashed_stroke()).

Parameters:
  • dashpat (Sequence[float])

  • kwargs (Any)

Return type:

list[Path | Path3D]

Path and Path3D are re-exported here for convenience but documented on the Paths page.