surfaces/surf/test/test_polymesh.py

57 lines
1.8 KiB
Python
Raw Normal View History

2012-05-07 22:17:46 -07:00
import json
import os
import unittest
from surf.geometry import PolygonMesh
class TestPM(unittest.TestCase):
def setUp(self):
path, file_name = os.path.split(__file__)
self.samples_dir = os.path.join(path, os.pardir, os.pardir,
'blender', 'samples')
full_cube_file_name = os.path.join(self.samples_dir, 'cube.json')
with open(full_cube_file_name) as cube_file:
self.full_cube = json.load(cube_file)
cube_file_name = os.path.join(self.samples_dir, 'cube-no-connectivity.json')
2012-05-29 16:33:28 -07:00
with open(cube_file_name) as cube_file:
self.skeleton_cube = json.load(cube_file)
self.skel = PolygonMesh(**self.skeleton_cube)
self.cube = PolygonMesh(**self.full_cube)
2012-05-07 22:17:46 -07:00
def test_cube_load(self):
p = PolygonMesh(**self.full_cube)
2012-05-07 22:17:46 -07:00
v = p.vertices[0]
self.assertAlmostEqual(v.x, -1.0)
self.assertAlmostEqual(v.y, -1.0)
self.assertAlmostEqual(v.z, -1.0)
2012-05-07 22:17:46 -07:00
def test_connectivity(self):
self.skel.faces_for_vert
self.skel.edges_for_vert
self.skel.edges_for_face
self.skel.faces_for_edge
def test_faces_for_vert(self):
for pi, qi in zip(self.skel.faces_for_vert, self.cube.faces_for_vert):
self.assertEqual(sorted(pi), sorted(qi))
def test_edges_for_vert(self):
for pi, qi in zip(self.skel.edges_for_vert, self.cube.edges_for_vert):
self.assertEqual(sorted(pi), sorted(qi))
def test_edges_for_face(self):
for pi, qi in zip(self.skel.edges_for_face, self.cube.edges_for_face):
self.assertEqual(sorted(pi), sorted(qi))
def test_faces_for_edge(self):
for pi, qi in zip(self.skel.faces_for_edge, self.cube.faces_for_edge):
self.assertEqual(sorted(pi), sorted(qi))
2012-05-07 22:17:46 -07:00
if __name__ == '__main__':
unittest.main(verbosity=3)