From 9ef471dadc719c5c98c9957f0c851bb2aed9e0d8 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Wed, 1 Apr 2026 19:20:46 -0700 Subject: [PATCH] [voxelize] Enforce 3 planes --- adze/test/test_edge_cases.py | 18 ++++++++++++++++++ adze/voxel.py | 10 +++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/adze/test/test_edge_cases.py b/adze/test/test_edge_cases.py index 156d1d7..5c8e0f3 100644 --- a/adze/test/test_edge_cases.py +++ b/adze/test/test_edge_cases.py @@ -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, + ) diff --git a/adze/voxel.py b/adze/voxel.py index ac84d76..11d81ca 100644 --- a/adze/voxel.py +++ b/adze/voxel.py @@ -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():