[util] add merge_polyhedra

This commit is contained in:
jan 2026-03-07 07:08:21 -08:00
commit 0bed641d08

View file

@ -29,6 +29,37 @@ def build_empty() -> poly_t:
} }
def merge_polyhedra(polys: Sequence[poly_t]) -> poly_t:
"""
Merge multiple polyhedra into a single representation.
Args:
polys: Sequence of polyhedra to merge.
Returns:
A single polyhedron containing all input polyhedra as separate components.
"""
if not polys:
return build_empty()
valid_polys = [p for p in polys if p['vertices'].shape[0] > 0]
if not valid_polys:
return build_empty()
all_vertices = numpy.vstack([p['vertices'] for p in valid_polys])
all_neighbors = []
offset = 0
for p in valid_polys:
all_neighbors.append(p['neighbors'] + offset)
offset += p['vertices'].shape[0]
return {
'vertices': all_vertices,
'neighbors': numpy.vstack(all_neighbors),
}
def find_components(neighbors: NDArray[numpy.integer]) -> NDArray[numpy.integer]: def find_components(neighbors: NDArray[numpy.integer]) -> NDArray[numpy.integer]:
""" """
Given an adjacency list, flood-fill to find and label connected components. Given an adjacency list, flood-fill to find and label connected components.