[voxelize] Enforce 3 planes

This commit is contained in:
Jan Petykiewicz 2026-04-01 19:20:46 -07:00
commit 9ef471dadc
2 changed files with 27 additions and 1 deletions

View file

@ -102,3 +102,21 @@ def test_check_poly_rejects_row_count_mismatch() -> None:
with pytest.raises(adze.AdzeError, match='Neighbors must have shape'):
adze.util.check_poly(poly, check_connectivity=False)
def test_voxelize_requires_three_axes() -> None:
poly = adze.build_box([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]])
with pytest.raises(adze.AdzeError, match='exactly three plane axes'):
adze.voxelize(poly, [numpy.array([0.0, 1.0]), numpy.array([0.0, 1.0])], order=0)
def test_voxelize_requires_strictly_increasing_axes() -> None:
poly = adze.build_box([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]])
with pytest.raises(adze.AdzeError, match='strictly increasing'):
adze.voxelize(
poly,
[numpy.array([1.0, 0.0]), numpy.array([0.0, 1.0]), numpy.array([0.0, 1.0])],
order=0,
)

View file

@ -42,7 +42,15 @@ def voxelize(
correspond to portions of the polyhedron that protruded outside the outermost
planes. N is `number_of_moments(order)`.
"""
aplanes = [numpy.asarray(p) for p in planes]
if len(planes) != 3:
raise AdzeError(f'Need exactly three plane axes. Got {len(planes)}')
aplanes = [numpy.asarray(p, dtype=float) for p in planes]
for axis, axis_planes in enumerate(aplanes):
if axis_planes.ndim != 1:
raise AdzeError(f'Plane axis {axis} must be 1-dimensional. Got {axis_planes.shape}')
if numpy.any(numpy.diff(axis_planes) <= 0):
raise AdzeError(f'Plane axis {axis} must be strictly increasing')
num_planes = numpy.array([e.size for e in aplanes], dtype=int)
if (num_planes < 2).any():