Skip to content

Boolean Operations

Differentiable Boolean operations with stratum-dispatched gradients.

brepax.boolean

Boolean operations on geometric primitives.

Provides a unified API for computing Boolean operations using different differentiation strategies. Method dispatch is handled internally.

union_area(a, b, *, method='stratum', **kwargs)

Compute the union area of two 2D primitives.

Source code in src/brepax/boolean/__init__.py
def union_area(
    a: Primitive,
    b: Primitive,
    *,
    method: BooleanMethod = "stratum",
    **kwargs: float | int | tuple[tuple[float, float], tuple[float, float]] | None,
) -> Float[Array, ""]:
    """Compute the union area of two 2D primitives."""
    if method == "smoothing":
        return union_area_smoothing(a, b, **kwargs)  # type: ignore[arg-type]
    elif method == "toi":
        raise NotImplementedError("TOI method not yet implemented")
    elif method == "stratum":
        return union_area_stratum(a, b)
    else:
        msg = f"unknown method: {method}"
        raise ValueError(msg)

union_volume(a, b, *, method='stratum', **kwargs)

Compute the union volume of two 3D primitives.

Source code in src/brepax/boolean/__init__.py
def union_volume(
    a: Primitive,
    b: Primitive,
    *,
    method: BooleanMethod = "stratum",
    **kwargs: float | int | None,
) -> Float[Array, ""]:
    """Compute the union volume of two 3D primitives."""
    if method == "stratum":
        return union_volume_stratum(a, b, **kwargs)  # type: ignore[arg-type]
    elif method == "toi":
        raise NotImplementedError("TOI method not yet implemented")
    elif method == "smoothing":
        raise NotImplementedError("3D smoothing not yet implemented")
    else:
        msg = f"unknown method: {method}"
        raise ValueError(msg)

subtract_volume(a, b, *, method='stratum', **kwargs)

Compute volume of a minus b (subtract b from a).

Source code in src/brepax/boolean/__init__.py
def subtract_volume(
    a: Primitive,
    b: Primitive,
    *,
    method: BooleanMethod = "stratum",
    **kwargs: float | int | None,
) -> Float[Array, ""]:
    """Compute volume of a minus b (subtract b from a)."""
    if method == "stratum":
        return subtract_volume_stratum(a, b, **kwargs)  # type: ignore[arg-type]
    else:
        msg = f"subtract not yet implemented for method: {method}"
        raise NotImplementedError(msg)

intersect_volume(a, b, *, method='stratum', **kwargs)

Compute intersection volume of a and b.

Source code in src/brepax/boolean/__init__.py
def intersect_volume(
    a: Primitive,
    b: Primitive,
    *,
    method: BooleanMethod = "stratum",
    **kwargs: float | int | None,
) -> Float[Array, ""]:
    """Compute intersection volume of a and b."""
    if method == "stratum":
        return intersect_volume_stratum(a, b, **kwargs)  # type: ignore[arg-type]
    else:
        msg = f"intersect not yet implemented for method: {method}"
        raise NotImplementedError(msg)