Geometry API Reference¶
The opifex.geometry package provides tools for defining computational domains using Constructive Solid Geometry (CSG).
Shapes¶
Base Protocol¶
opifex.geometry.csg.Shape2D
¶
Basic Shapes¶
opifex.geometry.csg.Rectangle
¶
Bases: _EnhancedShapeBase
2D rectangle shape for computational domains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Point2D
|
Center point of the rectangle |
required |
width
|
float
|
Width of the rectangle (must be positive) |
required |
height
|
float
|
Height of the rectangle (must be positive) |
required |
Source code in opifex/geometry/csg.py
contains
¶
contains(point: Point2D) -> bool
Check if point is inside rectangle (inclusive of boundary).
distance
¶
distance(point: Point2D) -> Float[Array, '']
Compute signed distance to rectangle boundary (smooth and differentiable).
Source code in opifex/geometry/csg.py
sample_boundary
¶
Sample points uniformly on rectangle boundary.
Source code in opifex/geometry/csg.py
sample_interior
¶
Sample points uniformly from rectangle interior.
Source code in opifex/geometry/csg.py
compute_normal
¶
Compute outward normal at boundary point.
Source code in opifex/geometry/csg.py
opifex.geometry.csg.Circle
¶
Circle(center: Point2D, radius: float)
Bases: _EnhancedShapeBase
2D circle shape for computational domains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Point2D
|
Center point of the circle |
required |
radius
|
float
|
Radius of the circle (must be positive) |
required |
Source code in opifex/geometry/csg.py
contains
¶
contains(point: Point2D) -> bool
Check if point is inside circle (inclusive of boundary).
distance
¶
distance(point: Point2D) -> Float[Array, '']
Compute signed distance to circle boundary (smooth and differentiable).
Source code in opifex/geometry/csg.py
sample_boundary
¶
Sample points uniformly on circle boundary.
Source code in opifex/geometry/csg.py
sample_interior
¶
Sample points uniformly from circle interior.
Source code in opifex/geometry/csg.py
compute_normal
¶
Compute outward normal at boundary point.
Source code in opifex/geometry/csg.py
opifex.geometry.csg.Polygon
¶
Bases: _EnhancedShapeBase
2D polygon shape defined by vertices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
Points2D
|
Array of vertex coordinates, shape (N, 2) where N >= 3 |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than 3 vertices provided |
Source code in opifex/geometry/csg.py
contains
¶
contains(point: Point2D) -> bool
Check if point is inside polygon using ray casting algorithm.
Source code in opifex/geometry/csg.py
distance
¶
distance(point: Point2D) -> Float[Array, '']
Compute signed distance to polygon boundary (enhanced).
Source code in opifex/geometry/csg.py
sample_boundary
¶
Sample points uniformly on polygon boundary.
Source code in opifex/geometry/csg.py
sample_interior
¶
Sample points from polygon interior using rejection sampling.
Source code in opifex/geometry/csg.py
compute_normal
¶
Compute outward normal at boundary point.
Source code in opifex/geometry/csg.py
CSG Operations¶
Classes¶
opifex.geometry.csg.CSGUnion
¶
Bases: _EnhancedShapeBase
Union of two shapes (A ∪ B) with enhanced algorithms.
Source code in opifex/geometry/csg.py
contains
¶
contains(point: Point2D) -> bool
Point is in union if it's in either shape.
Source code in opifex/geometry/csg.py
distance
¶
distance(point: Point2D) -> Float[Array, '']
Compute signed distance to union boundary.
Source code in opifex/geometry/csg.py
sample_boundary
¶
Sample boundary points using enhanced filtering.
Source code in opifex/geometry/csg.py
sample_interior
¶
Sample points from union interior.
Source code in opifex/geometry/csg.py
compute_normal
¶
Compute normal (enhanced approach).
Source code in opifex/geometry/csg.py
opifex.geometry.csg.CSGIntersection
¶
Bases: _EnhancedShapeBase
Intersection of two shapes (A ∩ B) with enhanced algorithms.
Source code in opifex/geometry/csg.py
contains
¶
contains(point: Point2D) -> bool
Point is in intersection if it's in both shapes.
Source code in opifex/geometry/csg.py
distance
¶
distance(point: Point2D) -> Float[Array, '']
Compute signed distance to intersection boundary.
Source code in opifex/geometry/csg.py
sample_boundary
¶
Sample boundary points (enhanced approach).
Source code in opifex/geometry/csg.py
sample_interior
¶
Sample points from intersection interior.
Source code in opifex/geometry/csg.py
compute_normal
¶
Compute normal (enhanced approach).
Source code in opifex/geometry/csg.py
opifex.geometry.csg.CSGDifference
¶
Bases: _EnhancedShapeBase
Difference of two shapes (A - B) with enhanced algorithms.
Source code in opifex/geometry/csg.py
contains
¶
contains(point: Point2D) -> bool
Point is in difference if it's in A but not in B.
Source code in opifex/geometry/csg.py
distance
¶
distance(point: Point2D) -> Float[Array, '']
Compute signed distance to difference boundary.
Source code in opifex/geometry/csg.py
sample_boundary
¶
Sample points on difference boundary.
Source code in opifex/geometry/csg.py
sample_interior
¶
Sample points from difference interior (A - B).
Source code in opifex/geometry/csg.py
compute_normal
¶
Compute normal from shape A.
Source code in opifex/geometry/csg.py
Functional API¶
Boundary Analysis¶
Molecular Geometry¶
opifex.geometry.csg.MolecularGeometry
¶
3D molecular geometry with atomic coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atomic_symbols
|
list[str]
|
List of atomic symbols (e.g., ['H', 'H', 'O']) |
required |
positions
|
Array
|
Atomic positions in Bohr, shape (N, 3) |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If number of symbols doesn't match number of positions |
Source code in opifex/geometry/csg.py
project_to_2d
¶
Project 3D coordinates to 2D plane.
Source code in opifex/geometry/csg.py
from_molecular_system
classmethod
¶
from_molecular_system(molecular_system) -> MolecularGeometry
Create molecular geometry from MolecularSystem.