Skip to content

Commit d51d250

Browse files
CopilotpaulmelnikowCopilotsyoyo
authored
Add regression test for numpy_num_face_vertices() fix (issue #400) (#418)
* Test Python + NumPy in CI * Add comments * Add more tests * Add more Python tests * assert_array_almost_equal * Try decimal=5 * Try to fix vertex test * Update a comment * Upgrade cibuildwheel * Fix toml * Match the types and call buf.release() * Rm buf.release() * Try to clear license warning on build * Fix license specifier * Move python tests out of python so they don’t end up in the wheel * Add some excludes * Reformat and exclude some python files * Update .github/workflows/python.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add a note about local numpy install * Reset a few files * Initial plan * Add regression test and .obj file for issue-400 numpy_num_face_vertices() Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com> * Fix black formatting with line-length=140 from pyproject.toml Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com> --------- Co-authored-by: Paul Melnikow <email@paulmelnikow.com> Co-authored-by: Paul Melnikow <github@paulmelnikow.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com> Co-authored-by: Syoyo Fujita <syoyo@lighttransport.com>
1 parent ff228a9 commit d51d250

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Regression test model for issue #400 - numpy_num_face_vertices()
2+
# Mixed quad and triangle faces to verify correct uint type handling.
3+
# With the bug (unsigned char instead of unsigned int in the numpy binding),
4+
# numpy_num_face_vertices() returned all zeros for quad (4-vertex) faces.
5+
v 0.0 0.0 0.0
6+
v 1.0 0.0 0.0
7+
v 1.0 1.0 0.0
8+
v 0.0 1.0 0.0
9+
v 0.5 0.5 1.0
10+
# quad face (num_face_vertices = 4)
11+
f 1 2 3 4
12+
# triangle face (num_face_vertices = 3)
13+
f 1 2 5
14+
# triangle face (num_face_vertices = 3)
15+
f 2 3 5

tests/python/tinyobjloader_tests/test_loader.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from pathlib import Path
2+
13
import numpy as np
24

35
from .loader import Loader, LoadException
46

7+
MODELS_DIR = Path(__file__).parent.parent.parent.parent / "models"
8+
59
TWO_QUADS = """
610
v 0 0 0
711
v 0 0 0
@@ -130,7 +134,32 @@ def test_numpy_index_array_two_quads():
130134
assert [x.vertex_index for x in shape.mesh.indices] == expected_vertex_index
131135

132136
# Test.
133-
expected_numpy_indices = [0, -1, -1, 1, -1, -1, 2, -1, -1, 3, -1, -1, 4, -1, -1, 5, -1, -1, 6, -1, -1, 7, -1, -1]
137+
expected_numpy_indices = [
138+
0,
139+
-1,
140+
-1,
141+
1,
142+
-1,
143+
-1,
144+
2,
145+
-1,
146+
-1,
147+
3,
148+
-1,
149+
-1,
150+
4,
151+
-1,
152+
-1,
153+
5,
154+
-1,
155+
-1,
156+
6,
157+
-1,
158+
-1,
159+
7,
160+
-1,
161+
-1,
162+
]
134163
np.testing.assert_array_equal(shape.mesh.numpy_indices(), expected_numpy_indices)
135164

136165

@@ -174,3 +203,33 @@ def test_numpy_vertex_array_two_quads():
174203

175204
# Test.
176205
np.testing.assert_array_almost_equal(loader.attrib.numpy_vertices(), expected_vertices, decimal=6)
206+
207+
208+
def test_numpy_num_face_vertices_from_file():
209+
"""
210+
Regression test for https://github.com/tinyobjloader/tinyobjloader/issues/400
211+
212+
Loads a mixed quad/triangle mesh from a .obj file and checks that
213+
numpy_num_face_vertices() returns correct unsigned int values.
214+
With the bug (unsigned char element type), values were read as zeros.
215+
"""
216+
217+
# Set up.
218+
obj_path = str(MODELS_DIR / "issue-400-num-face-vertices.obj")
219+
loader = Loader(triangulate=False)
220+
loader.load(obj_path)
221+
222+
shapes = loader.shapes
223+
assert len(shapes) == 1
224+
225+
(shape,) = shapes
226+
# The file has one quad face (4 vertices) and two triangle faces (3 vertices each).
227+
expected_num_face_vertices = [4, 3, 3]
228+
229+
# Confidence check using the non-numpy accessor.
230+
assert shape.mesh.num_face_vertices == expected_num_face_vertices
231+
232+
# Test: numpy_num_face_vertices() must return the same values with the correct dtype.
233+
result = shape.mesh.numpy_num_face_vertices()
234+
np.testing.assert_array_equal(result, expected_num_face_vertices)
235+
assert result.dtype == np.dtype("uint32")

0 commit comments

Comments
 (0)