2012-05-08 23:32:34 -07:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from surf.geometry import PolygonMesh
|
|
|
|
from surf.subd import cc
|
|
|
|
|
|
|
|
|
|
|
|
class TestCC(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
path, file_name = os.path.split(__file__)
|
|
|
|
self.samples_dir = os.path.join(path, os.pardir, os.pardir, os.pardir,
|
|
|
|
'blender', 'samples')
|
|
|
|
self.cube_file_name = os.path.join(self.samples_dir, 'cube.json')
|
|
|
|
self.cube = json.load(open(self.cube_file_name, 'r'))
|
2012-05-15 21:57:44 -07:00
|
|
|
self.cube_file_name = os.path.join(self.samples_dir, 'cube-blender-cc-1.json')
|
|
|
|
self.cube1 = json.load(open(self.cube_file_name, 'r'))
|
2012-05-08 23:32:34 -07:00
|
|
|
|
2012-05-15 21:57:44 -07:00
|
|
|
def test_refined_vertex_location(self):
|
2012-05-08 23:32:34 -07:00
|
|
|
p = PolygonMesh(**self.cube)
|
|
|
|
p2 = cc.refine(p)
|
2012-05-15 21:57:44 -07:00
|
|
|
v2 = [list(i) for i in p2.vertices]
|
|
|
|
for a, b in zip(sorted(self.cube1['vertices']), sorted(v2)):
|
|
|
|
for i in xrange(len(a)):
|
|
|
|
self.assertAlmostEqual(a[i], b[i])
|
2012-05-08 23:32:34 -07:00
|
|
|
|
2012-05-15 22:51:48 -07:00
|
|
|
def test_vert_count(self):
|
|
|
|
p = PolygonMesh(**self.cube)
|
|
|
|
p2 = cc.refine(p)
|
|
|
|
self.assertEqual(len(p2.vertices), 26)
|
|
|
|
|
|
|
|
def test_edge_count(self):
|
|
|
|
p = PolygonMesh(**self.cube)
|
|
|
|
p2 = cc.refine(p)
|
|
|
|
self.assertEqual(len(p2.edges), 48)
|
|
|
|
|
|
|
|
def test_face_count(self):
|
|
|
|
p = PolygonMesh(**self.cube)
|
|
|
|
p2 = cc.refine(p)
|
|
|
|
self.assertEqual(len(p2.faces), 24)
|
|
|
|
|
2012-05-08 23:32:34 -07:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(verbosity=3)
|