diff --git a/src/readyplayerme/meshops/mesh.py b/src/readyplayerme/meshops/mesh.py index 6c3caf7..e528867 100644 --- a/src/readyplayerme/meshops/mesh.py +++ b/src/readyplayerme/meshops/mesh.py @@ -60,7 +60,11 @@ def get_overlapping_vertices( :param precision: Tolerance for considering positions as overlapping. :return: A list of grouped vertices that share position. """ - selected_vertices = vertices_pos if indices is None else vertices_pos[indices] + try: + selected_vertices = vertices_pos if indices is None else vertices_pos[indices] + except IndexError as error: + msg = "Indices must be within bounds of vertices array." + raise IndexError(msg) from error tree = cKDTree(selected_vertices) diff --git a/tests/readyplayerme/meshops/unit/test_mesh.py b/tests/readyplayerme/meshops/unit/test_mesh.py index 7ea892e..25098d3 100644 --- a/tests/readyplayerme/meshops/unit/test_mesh.py +++ b/tests/readyplayerme/meshops/unit/test_mesh.py @@ -103,3 +103,12 @@ def test_get_overlapping_vertices( assert len(grouped_vertices) == len(expected), "Number of groups doesn't match expected" for group, exp_group in zip(grouped_vertices, expected, strict=False): assert np.array_equal(group, exp_group), f"Grouped vertices {group} do not match expected {exp_group}" + + +def test_get_overlapping_vertices_index_error(): + """Test the get_overlapping_vertices function with indices that are out of bounds for the vertices.""" + vertices = np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]) + indices = np.array([2, 3, -4]) + + with pytest.raises(IndexError): + mesh.get_overlapping_vertices(vertices, indices)