From 031d93598d5c36d181a9e99bddf9ed303843a39e Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Wed, 1 Apr 2026 20:53:38 -0700 Subject: [PATCH] more input validation --- adze/boundary.py | 6 +++++- adze/split.py | 2 +- adze/test/test_edge_cases.py | 6 ------ adze/transform.py | 2 ++ 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/adze/boundary.py b/adze/boundary.py index afab4b5..7369c73 100644 --- a/adze/boundary.py +++ b/adze/boundary.py @@ -313,9 +313,13 @@ def boundary_from_poly(poly: poly_t) -> list[dict[str, Any]]: vertices = poly['vertices'] if vertices.shape[0] == 0: return [] + check_poly(poly, check_connectivity=False) owning_component = find_components(neighbors) - faces = find_faces(neighbors) + try: + faces = find_faces(neighbors) + except (IndexError, ValueError) as exc: + raise AdzeError('Polyhedron has invalid neighbor ordering and cannot be converted to a boundary representation') from exc num_components = owning_component.max() + 1 components: list[list[NDArray[numpy.integer]]] = [[] for _ in range(num_components)] diff --git a/adze/split.py b/adze/split.py index 57d9ae6..591eae1 100644 --- a/adze/split.py +++ b/adze/split.py @@ -35,7 +35,7 @@ def _normalize_plane(plane: plane_t) -> plane_t: raise AdzeError(f'Plane distance must be a scalar. Got {distance_shape}') from exc if not math.isfinite(distance): raise AdzeError('Plane distance must be finite') - return normal, distance + return normal, float(distance) def clip(poly: poly_t, plane: plane_t, atol: float = 1e-12) -> poly_t: diff --git a/adze/test/test_edge_cases.py b/adze/test/test_edge_cases.py index 91f6141..f611f65 100644 --- a/adze/test/test_edge_cases.py +++ b/adze/test/test_edge_cases.py @@ -237,7 +237,6 @@ def test_voxelize_requires_strictly_increasing_axes() -> None: ) -<<<<<<< HEAD def test_clip_rejects_zero_normal_plane() -> None: poly = adze.build_box([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]]) @@ -280,8 +279,6 @@ def test_boundary_from_poly_rejects_invalid_graph() -> None: adze.boundary_from_poly(poly) -======= ->>>>>>> 34c60fa ([clip / _split] always return a new poly) def test_clip_noop_returns_independent_poly() -> None: poly = adze.build_box([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]]) @@ -303,7 +300,6 @@ def test_split_noop_returns_independent_poly() -> None: assert kept_poly['vertices'] is not poly['vertices'] kept_poly['vertices'][0, 0] = 999.0 assert poly['vertices'][0, 0] == 0.0 -<<<<<<< HEAD def test_split_handles_disconnected_components_without_cut_edges() -> None: @@ -343,5 +339,3 @@ def test_tetrahedron_helpers_reject_negative_winding(tetra_fun) -> None: [1.0, 0.0, 0.0], [0.0, 0.0, 1.0], ]) -======= ->>>>>>> 34c60fa ([clip / _split] always return a new poly) diff --git a/adze/transform.py b/adze/transform.py index f833d9c..0f72f08 100644 --- a/adze/transform.py +++ b/adze/transform.py @@ -78,6 +78,8 @@ def affine(poly: poly_t, xform: ArrayLike) -> poly_t: xform = numpy.array(xform, copy=False) if xform.shape != (4, 4): raise AdzeError(f'Affine transform matrix must have shape (4, 4). Got {xform.shape}') + if not numpy.isfinite(xform).all(): + raise AdzeError('Affine transform matrix must contain only finite values') mat4x3 = xform[:, :3] mat4x1 = xform[:, 3]