Skip to content

compas_brep.brep ¤

Brep class — thin wrapper around a native backend geometry object.

_native_brep (a TopoDS_Shape or Rhino.Geometry.Brep) is the sole source of truth. All topology lists (_vertices, _edges, _loops, _faces) are lazy caches populated on first access via brep_extract_topology; they are never written as authoritative data. All operations delegate to the active backend (OCC or Rhino) via the COMPAS plugin system. All public interface inputs and outputs are COMPAS types — no backend types leak through.

Classes¤

Brep ¤

Brep(name: str | None = None)

Thin wrapper around a native backend geometry object (OCC or Rhino).

_native_brep is the sole source of truth. Topology lists are lazy caches populated on demand from native via _ensure_topology; they are never written as primary data. All public interface values are COMPAS types.

Attributes¤

aabb property ¤
aabb: Box

Axis-aligned bounding box of this Brep.

Methods:¤

__add__ ¤
__add__(other: Brep) -> list[Brep]

A + B. Same as :meth:from_boolean_union, so it returns a list.

__and__ ¤
__and__(other: Brep) -> list[Brep]

A & B. Same as :meth:from_boolean_intersection, so it returns a list.

__sub__ ¤
__sub__(other: Brep) -> list[Brep]

A - B. Same as :meth:from_boolean_difference, so it returns a list.

cap_planar_holes ¤
cap_planar_holes() -> None

Cap planar holes in this Brep in-place.

contains ¤
contains(obj: Point) -> bool

Check if a point is contained inside this solid Brep.

Parameters:

  • obj (Point) –

    The point to test.

contours ¤
contours(planes: list[Plane]) -> list[list[Polyline]]

Generate contour lines by slicing with multiple planes.

Parameters:

  • planes (list[Plane]) –

    The slicing planes.

copy ¤
copy() -> Brep

Return a deep copy of this Brep.

edge_loops ¤
edge_loops(edge: BrepEdge) -> list[BrepLoop]

Get all loops that contain this edge.

Parameters:

  • edge (BrepEdge) –

    The edge to query.

fillet ¤
fillet(radius: float, edges: list[int] | None = None) -> None

Fillet edges in-place.

Parameters:

  • radius (float) –

    The fillet radius.

  • edges (list[int] | None, default: None ) –

    Indices of edges to fillet. If None, fillets all edges.

filleted ¤
filleted(radius: float, edges: list[int] | None = None) -> Brep

Return a filleted copy of this Brep.

Parameters:

  • radius (float) –

    The fillet radius.

  • edges (list[int] | None, default: None ) –

    Indices of edges to fillet. If None, fillets all edges.

fix ¤
fix() -> None

Fix/repair this Brep in-place.

flip ¤
flip() -> None

Flip face orientations of this Brep in-place.

from_boolean_difference classmethod ¤
from_boolean_difference(brep_a: Brep, brep_b: Brep) -> list[Brep]

Boolean subtraction: A - B.

Returns one Brep per resulting piece — a subtraction can cut a shape into several disconnected ones. Empty when nothing is left.

from_boolean_intersection classmethod ¤
from_boolean_intersection(brep_a: Brep, brep_b: Brep) -> list[Brep]

Boolean intersection: A & B.

Returns one Brep per resulting piece. Empty when the two do not overlap.

from_boolean_union classmethod ¤
from_boolean_union(brep_a: Brep, brep_b: Brep) -> list[Brep]

Boolean union: A + B.

Returns one Brep per resulting piece — disjoint inputs stay disjoint.

from_boolean_union_multi classmethod ¤
from_boolean_union_multi(*breps: Brep) -> list[Brep]

Boolean union of multiple Breps, chained pairwise.

Only the first piece of each intermediate union is carried into the next step, so disjoint inputs are not all preserved. Union them pairwise if that matters.

Parameters:

  • *breps (Brep, default: () ) –

    Two or more Breps to union.

from_box classmethod ¤
from_box(box: Box) -> Brep

Create a Brep from a COMPAS Box.

from_brepfaces classmethod ¤
from_brepfaces(faces: list[BrepFace]) -> Brep

Build a Brep from a list of BrepFace objects.

from_breps classmethod ¤
from_breps(breps: list[Brep]) -> Brep

Join multiple Breps into one by sewing overlapping edges.

Parameters:

from_cone classmethod ¤
from_cone(cone: Any) -> Brep

Create a Brep from a COMPAS Cone.

from_curves classmethod ¤
from_curves(curves: list[Any]) -> Brep

Create a Brep from planar boundary curves.

Parameters:

  • curves (list[Any]) –

    List of curves defining a planar face boundary.

from_cylinder classmethod ¤
from_cylinder(cylinder: Cylinder) -> Brep

Create a Brep from a COMPAS Cylinder.

from_extrusion classmethod ¤
from_extrusion(profile: Any, vector: Vector, cap_ends: bool = True) -> Brep

Create a Brep by extruding a profile along a vector.

Parameters:

  • profile (Any) –

    The profile to extrude (BrepFace, Polygon, or curve).

  • vector (Vector) –

    The extrusion direction and magnitude.

  • cap_ends (bool, default: True ) –

    If True, cap the top and bottom. Passed to the backend where supported.

from_iges classmethod ¤
from_iges(filepath: str) -> Brep

Import a Brep from an IGES file.

Parameters:

  • filepath (str) –

    Path to the .igs or .iges file.

from_loft classmethod ¤
from_loft(curves: list[Any]) -> Brep

Create a Brep by lofting between profile curves.

Delegates to the active backend (OCC or Rhino) for exact NURBS lofting.

Parameters:

  • curves (list[Any]) –

    List of NurbsCurve profiles.

from_mesh classmethod ¤
from_mesh(mesh: Mesh) -> Brep

Create a Brep from a COMPAS Mesh.

from_native classmethod ¤
from_native(native_brep: Any) -> Brep

Create a Brep from a native backend object (OCC TopoDS_Shape or Rhino.Geometry.Brep).

Parameters:

  • native_brep (Any) –

    A native OCC or Rhino brep object.

from_pipe classmethod ¤
from_pipe(path: Brep, radius: float) -> Brep

Create a pipe Brep by sweeping a circle along a path.

Parameters:

  • path (Brep) –

    The path curve (as a Brep with edges).

  • radius (float) –

    The pipe radius.

from_plane classmethod ¤
from_plane(
    plane: Plane,
    domain_u: tuple[float, float] = (-1, 1),
    domain_v: tuple[float, float] = (-1, 1),
) -> Brep

Create a single planar face Brep from a Plane with the given domain.

from_polygons classmethod ¤
from_polygons(polygons: list[Polygon]) -> Brep

Create a Brep from a list of COMPAS Polygons.

from_sphere classmethod ¤
from_sphere(sphere: Sphere) -> Brep

Create a Brep from a COMPAS Sphere.

from_step classmethod ¤
from_step(filepath: str) -> Brep

Import a Brep from a STEP file.

Parameters:

  • filepath (str) –

    Path to the .step or .stp file.

from_surface classmethod ¤
from_surface(
    surface: NurbsSurface,
    domain_u: tuple[float, float] | None = None,
    domain_v: tuple[float, float] | None = None,
) -> Brep

Create a Brep from a NURBS surface.

Parameters:

from_sweep classmethod ¤
from_sweep(profile: Brep, path: Brep) -> Brep

Create a Brep by sweeping a profile along a path.

Parameters:

  • profile (Brep) –

    The profile to sweep.

  • path (Brep) –

    The path to sweep along.

from_torus classmethod ¤
from_torus(torus: Any) -> Brep

Create a Brep from a COMPAS Torus.

heal ¤
heal() -> None

Heal this Brep in-place (fix + sew).

make_solid ¤
make_solid() -> None

Convert this Brep from a shell to a solid in-place.

offset ¤
offset(distance: float) -> Brep

Return an offset copy of this Brep.

Parameters:

  • distance (float) –

    The offset distance (positive = outward, negative = inward).

overlap ¤
overlap(other: Brep, deflection: float | None = None, tolerance: float = 0.0) -> Brep

Compute the overlap between this Brep and another.

Parameters:

  • other (Brep) –

    The other Brep.

  • deflection (float | None, default: None ) –

    Linear deflection for mesh approximation.

  • tolerance (float, default: 0.0 ) –

    Tolerance for overlap detection.

sew ¤
sew() -> None

Sew this Brep in-place.

slice ¤
slice(plane: Plane) -> list[Polyline]

Intersect the Brep with a plane, returning intersection polylines.

Parameters:

  • plane (Plane) –

    The cutting plane.

split ¤
split(cutter: Brep) -> list[Brep]

Split this Brep by a cutter Brep (typically a planar surface).

Parameters:

  • cutter (Brep) –

    The cutting Brep.

to_iges ¤
to_iges(filepath: str) -> None

Export this Brep to an IGES file.

Parameters:

  • filepath (str) –

    Path to the output .igs or .iges file.

to_meshes ¤
to_meshes(u: int = 16, v: int = 16) -> list[Mesh]

Convert the Brep to a list of meshes for visualization.

Returns a single mesh covering the whole Brep.

Parameters:

  • u (int, default: 16 ) –

    Resolution for tessellation.

  • v (int, default: 16 ) –

    Unused, kept for interface compatibility.

to_polygons ¤
to_polygons() -> list[Polygon]

Convert each face to a Polygon.

to_step ¤
to_step(filepath: str, **kwargs) -> None

Export this Brep to a STEP file.

Parameters:

  • filepath (str) –

    Path to the output .step or .stp file.

to_stl ¤
to_stl(filepath: str, **kwargs) -> None

Export this Brep to an STL file.

Parameters:

  • filepath (str) –

    Path to the output .stl file.

to_tesselation ¤
to_tesselation(
    linear_deflection: float = 0.1, n: int = 16, n_curves: int = 64
) -> tuple[Mesh, list[Polyline]]

Create a tessellation of the Brep for visualization.

Returns a triangulated mesh and a list of boundary polylines. Matches the interface expected by compas_viewer's BRepObject.

Uses cached tessellation when available. Otherwise delegates to the active backend via the brep_tessellate pluggable and caches the result.

Parameters:

  • linear_deflection (float, default: 0.1 ) –

    Linear deflection passed to the backend tessellator.

  • n (int, default: 16 ) –

    Resolution for face tessellation.

  • n_curves (int, default: 64 ) –

    Number of samples per curved edge for boundary polylines.

to_viewmesh ¤
to_viewmesh(precision: float = 1e-06, n: int = 16) -> Mesh

Convert the Brep to a single mesh for visualization.

Uses cached tessellation if available, otherwise delegates to the active backend via the brep_tessellate pluggable.

Parameters:

  • precision (float, default: 1e-06 ) –

    Unused, kept for interface compatibility.

  • n (int, default: 16 ) –

    Resolution for tessellation.

transform ¤
transform(transformation: Transformation) -> None

Transform this Brep in-place by a transformation matrix.

Parameters:

trim ¤
trim(plane: Plane) -> None

Trim the Brep in-place with a plane.

Parameters:

  • plane (Plane) –

    The trimming plane.

trimmed ¤
trimmed(plane: Plane) -> Brep

Trim the Brep with a plane, keeping the back side (opposite to normal).

Parameters:

  • plane (Plane) –

    The trimming plane. The side the normal points away from is kept.