Skip to content

Commit

Permalink
fix: removing the double conditioning
Browse files Browse the repository at this point in the history
- now if the indices are none it creates a list of the length of UVs and selects them all.
- added a test for 0 px image.
  • Loading branch information
TechyDaniel committed Nov 23, 2023
1 parent 01a9370 commit f1b6e3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/readyplayerme/meshops/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ def uv_to_texture_space(
return np.empty((0, 2), dtype=np.uint16)

try:
selected_uvs = uvs if indices is None else uvs[indices]
selected_uvs = uvs[indices]
except IndexError as error:
msg = f"Index {np.where(indices>=len(uvs))[0]} is out of bounds for UVs with shape {uvs.shape}."
raise IndexError(msg) from error

# Wrap UV coordinates within the range [0, 1]
wrapped_uvs = np.mod(selected_uvs, 1)

Expand Down
4 changes: 4 additions & 0 deletions tests/readyplayerme/meshops/unit/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def test_get_overlapping_vertices_error_handling(indices):
(np.array([[0.5, 0.5], [0.25, 0.75]]), 124, 10024, np.array([0]), np.array([[61, 5011]])),
# 1px image
(np.array([[0.5, 0.5], [-1, 1], [0, 0]]), 1, 1, np.array([0, 1, 2]), np.array([[0, 0], [0, 0], [0, 0]])),
# 0 px image
(np.array([[0.5, 0.5], [0.25, 0.75]]), 0, 0, np.array([0]), np.array([[0, 0]])),
],
)
def test_uv_to_texture_space(uvs: UVs, width: int, height: int, indices: Indices, expected: PixelCoord):
Expand All @@ -158,6 +160,8 @@ def test_uv_to_texture_space(uvs: UVs, width: int, height: int, indices: Indices
"uvs, width, height, indices",
[
(np.array([[0.5, 0.5], [0.25, 0.75]]), 100, 100, np.array([0, 1, 2])),
# No UV coord
(np.array([]), 1, 1, np.array([0, 1, 2])),
],
)
def test_uv_to_texture_space_exceptions(uvs: UVs, width: int, height: int, indices: Indices):
Expand Down

0 comments on commit f1b6e3f

Please sign in to comment.