Skip to content

Commit fd55e92

Browse files
committed
Forgot about model tests
1 parent a6e1e64 commit fd55e92

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/flitter/render/window/models.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ cdef class Model:
437437
return VectorModel._get(vertices, faces)
438438

439439
@staticmethod
440-
def vector(vertices, faces):
440+
def vector(vertices, faces=None):
441441
return VectorModel._get(Vector._coerce(vertices), Vector._coerce(faces))
442442

443443
@staticmethod
@@ -1620,6 +1620,8 @@ cdef class VectorModel(Model):
16201620
cdef VectorModel _get(Vector vertices, Vector faces):
16211621
if vertices is None or vertices.numbers == NULL:
16221622
return None
1623+
if faces is not None and faces.numbers == NULL:
1624+
faces = None
16231625
cdef uint64_t id = VECTOR
16241626
id = HASH_UPDATE(id, vertices.hash(False))
16251627
if faces is not None:

tests/test_models.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ def test_bad_manifold(self):
163163
class TestVector(utils.TestCase):
164164
def test_bad(self):
165165
self.assertIsNone(Model.vector(None, None))
166-
self.assertIsNone(Model.vector('hello', 1))
167-
self.assertIsNone(Model.vector(1, 'hello'))
166+
self.assertIsNone(Model.vector(None, 1))
168167

169168
def test_basic(self):
170169
vertices = [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1]
@@ -179,6 +178,15 @@ def test_basic(self):
179178
self.assertAlmostEqual(mesh.area, 3+math.sqrt(2))
180179
self.assertAlmostEqual(mesh.volume, 0.5)
181180

181+
def test_convex(self):
182+
vertices = [-1, -1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1]
183+
model = Model.vector(vertices)
184+
self.assertIs(model, Model.vector(vertices))
185+
mesh = model.get_trimesh()
186+
self.assertEqual(mesh.bounds.tolist(), [[-1, -1, -1], [1, 1, 1]])
187+
self.assertAlmostEqual(mesh.area, 24)
188+
self.assertAlmostEqual(mesh.volume, 8)
189+
182190
def test_invalid(self):
183191
with unittest.mock.patch('flitter.render.window.models.logger') as mock_logger:
184192
model = Model.vector([0, 0, 0, 0, 0, 1, 0, 1], [0, 1, 2])

0 commit comments

Comments
 (0)