Regions¶
- class bosl2.regions.Region(paths=())[source]¶
Bases:
listA 2-D region: a list of
Pathoutlines, 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 subclasseslistand stays a drop-in for the raw region data the toolkit already passes toregion()/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()
- classmethod with_holes(outline, *holes)[source]¶
A region from an outline plus hole outlines.
This is what a concentric
DifferenceWithOffsetproduces: outline + inner hole, no clipping involved.- Parameters:
outline (Sequence)
holes (Sequence)
- Return type:
- 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:
- round_corners(radius=None, **kwargs)[source]¶
- Parameters:
radius (float | list[float] | None)
kwargs (Any)
- Return type:
- 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:
- 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:
- 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:
- linear_extrude(height, **kwargs)[source]¶
Extrude this region height along +Z into a 3-D solid (holes included), on whichever backend is active – a
Bosl2Solidunder the default CSG backend, aPyShapeunderuse_backend("sdf"). Seebosl2.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
UnsupportedByBackendthere.- 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:
- 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
agets labelsa0, a1, ..., pathbb0, b1, ...(BOSL2 debug_region()). A single-path region defers todebug_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.