more input validation

This commit is contained in:
Jan Petykiewicz 2026-04-01 20:53:38 -07:00
commit 031d93598d
4 changed files with 8 additions and 8 deletions

View file

@ -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)]

View file

@ -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:

View file

@ -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)

View file

@ -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]