Skip to content

Commit

Permalink
autopep8 for identifier refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Feb 15, 2017
1 parent c8d7315 commit 80fbb64
Show file tree
Hide file tree
Showing 39 changed files with 141 additions and 111 deletions.
17 changes: 10 additions & 7 deletions tests/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
from io import BytesIO
_PY3 = True

dir_current = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
dir_current = os.path.dirname(os.path.abspath(
inspect.getfile(inspect.currentframe())))
dir_models = os.path.abspath(os.path.join(dir_current, '..', 'models'))
dir_2D = os.path.abspath(os.path.join(dir_current, '..', 'models', '2D'))
dir_data = os.path.abspath(os.path.join(dir_current, 'data'))
Expand Down Expand Up @@ -88,7 +89,8 @@ def get_meshes(count=None):
if len(meshes) >= count:
break
return list(meshes)



def get_2D(count=None):
ls = os.listdir(dir_2D)
if count is None:
Expand All @@ -97,12 +99,13 @@ def get_2D(count=None):
for file_name in ls:
location = os.path.join(dir_2D, file_name)
print(location)
try: paths.append(trimesh.load(location))
except:
log.warning('skipping path load', exc_info = True)
try:
paths.append(trimesh.load(location))
except:
log.warning('skipping path load', exc_info=True)
if len(paths) >= count:
break
return list(paths)


data = _load_data()
1 change: 1 addition & 0 deletions tests/test_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_boolean(self):

g.log.info('booleans succeeded with %s', engine)


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
1 change: 1 addition & 0 deletions tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def test_uv(self):
self.assertTrue(sphere.is_watertight)
self.assertTrue(sphere.is_winding_consistent)


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
1 change: 1 addition & 0 deletions tests/test_dxf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_dxf(self):
ratio)
raise ValueError('perimeter ratio too large')


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
1 change: 1 addition & 0 deletions tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_export(self):
g.log.info(
'Mesh vertices/faces consistent after export->import')


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
1 change: 1 addition & 0 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_engine_time(self):
str(g.np.column_stack((self.engines,
tic_diff))))


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
19 changes: 9 additions & 10 deletions tests/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class GroupTests(g.unittest.TestCase):

def test_unique_rows(self):
count = 100
subset = int(count/10)
data = g.np.arange(count*3).reshape((-1,3)).astype(g.np.float)
subset = int(count / 10)

data = g.np.arange(count * 3).reshape((-1, 3)).astype(g.np.float)
data[:subset] = data[0]

unique, inverse = g.trimesh.grouping.unique_rows(data)
Expand All @@ -19,7 +19,7 @@ def test_blocks(self):
blocks = g.trimesh.grouping.blocks

count = 100
subset = int(count/10)
subset = int(count / 10)
a = g.np.zeros(count, dtype=g.np.int)

result = blocks(a, min_len=0, only_nonzero=False)
Expand All @@ -29,13 +29,13 @@ def test_blocks(self):
result = blocks(a, min_len=0, only_nonzero=True)
assert len(result) == 0

result = blocks(a, min_len=count+1, only_nonzero=False)
result = blocks(a, min_len=count + 1, only_nonzero=False)
assert len(result) == 0

result = blocks(a, max_len=count-1, only_nonzero=False)
result = blocks(a, max_len=count - 1, only_nonzero=False)
assert len(result) == 0

result = blocks(a, max_len=count+1, only_nonzero=False)
result = blocks(a, max_len=count + 1, only_nonzero=False)
assert len(result) == 1
assert len(result[0]) == count

Expand All @@ -61,14 +61,13 @@ def test_blocks(self):
assert len(result) == 3
assert sum(len(i) for i in result) == count


a[2] = False
result = blocks(a, min_len=1, only_nonzero=True)
assert len(result) == 2
assert set(result[0]) == set([1])
assert all(a[i].all() for i in result)


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
15 changes: 9 additions & 6 deletions tests/test_identifier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import generic as g


class IdentifierTest(g.unittest.TestCase):

def test_identifier(self):
Expand All @@ -16,21 +17,23 @@ def test_identifier(self):
for i in range(count):
permutated = mesh.permutate.transform()
permutated = permutated.permutate.tesselation()

md5.append(permutated.identifier_md5)
idf.append(permutated.identifier)

result = g.np.array(md5)
ok = (result[0] == result[1:]).all()

if not ok:
debug = [g.np.append(*g.trimesh.util.sigfig_int(a, g.trimesh.comparison.identifier_sigfig)) for a in idf]


if not ok:
debug = [g.np.append(
*g.trimesh.util.sigfig_int(a, g.trimesh.comparison.identifier_sigfig)) for a in idf]

g.log.error('Hashes on %s differ after transform! diffs:\n %s\n',
mesh.metadata['file_name'],
str(g.np.array(debug)))
self.assertTrue(ok)


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
1 change: 1 addition & 0 deletions tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def test_fix_normals(self):
for mesh in g.get_meshes(5):
mesh.fix_normals()


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
1 change: 1 addition & 0 deletions tests/test_normals.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_face_normals(self):
mesh.face_normals = None
self.assertTrue(mesh.face_normals.shape == mesh.faces.shape)


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
1 change: 1 addition & 0 deletions tests/test_nsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_minball(self):
self.assertTrue(R > 0.0)
self.assertTrue(abs(R - R_check) < g.tol.merge)


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
48 changes: 21 additions & 27 deletions tests/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,27 @@ def test_center_random(self):
min_radius = .0001
count = 1000

center_3D = (g.np.random.random((count,3)) - .5) * 50
center_2D = center_3D[:,0:2]
radii = g.np.clip(g.np.random.random(count) * 100, min_angle, g.np.inf)
center_3D = (g.np.random.random((count, 3)) - .5) * 50
center_2D = center_3D[:, 0:2]
radii = g.np.clip(g.np.random.random(count) * 100, min_angle, g.np.inf)

angles = g.np.random.random((count,2)) * (g.np.pi - min_angle) + min_angle
angles = g.np.random.random((count, 2)) * \
(g.np.pi - min_angle) + min_angle
angles = g.np.column_stack((g.np.zeros(count),
g.np.cumsum(angles, axis=1)))
g.np.cumsum(angles, axis=1)))

points_2D = g.np.column_stack((g.np.cos(angles[:,0]), g.np.sin(angles[:,0]),
g.np.cos(angles[:,1]), g.np.sin(angles[:,1]),
g.np.cos(angles[:,2]), g.np.sin(angles[:,2]))).reshape((-1,6))
points_2D *= radii.reshape((-1,1))
points_2D = g.np.column_stack((g.np.cos(angles[:, 0]), g.np.sin(angles[:, 0]),
g.np.cos(angles[:, 1]), g.np.sin(
angles[:, 1]),
g.np.cos(angles[:, 2]), g.np.sin(angles[:, 2]))).reshape((-1, 6))
points_2D *= radii.reshape((-1, 1))

points_2D += g.np.tile(center_2D, (1,3))
points_2D = points_2D.reshape((-1,3,2))


points_3D = g.np.column_stack((points_2D.reshape((-1,2)),
g.np.tile(center_3D[:,2].reshape((-1,1)),
(1,3)).reshape(-1))).reshape((-1,3,3))
points_2D += g.np.tile(center_2D, (1, 3))
points_2D = points_2D.reshape((-1, 3, 2))

points_3D = g.np.column_stack((points_2D.reshape((-1, 2)),
g.np.tile(center_3D[:, 2].reshape((-1, 1)),
(1, 3)).reshape(-1))).reshape((-1, 3, 3))

for center, radius, three in zip(center_2D,
radii,
Expand All @@ -103,28 +103,21 @@ def test_center_random(self):
assert g.np.allclose(center, info['center'])
assert g.np.allclose(radius, info['radius'])



for center, radius, three in zip(center_3D,
radii,
points_3D):
transform = g.trimesh.transformations.random_rotation_matrix()
center = g.trimesh.transformations.transform_points([center], transform)[0]
three = g.trimesh.transformations.transform_points(three, transform)
center = g.trimesh.transformations.transform_points([center], transform)[
0]
three = g.trimesh.transformations.transform_points(
three, transform)

info = g.trimesh.path.arc.arc_center(three)

assert g.np.allclose(center, info['center'])
assert g.np.allclose(radius, info['radius'])









class PolygonsTest(g.unittest.TestCase):

def test_rasterize(self):
Expand All @@ -141,6 +134,7 @@ def test_rasterize(self):

self.assertTrue(contained.all())


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
1 change: 1 addition & 0 deletions tests/test_proximity.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def points_on_circle(count):

return result, result_distance


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
1 change: 1 addition & 0 deletions tests/test_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_contains(self):
self.assertTrue(test_in.all())
self.assertFalse(test_out.any())


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
Expand Down
1 change: 1 addition & 0 deletions tests/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_forest(self):
for i in range(5000):
g.add_edge(random_chr(), random_chr())


if __name__ == '__main__':
trimesh.util.attach_to_log()
unittest.main()
1 change: 1 addition & 0 deletions tests/test_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_planes(self):
self.assertTrue(valid.all())
self.assertTrue((g.np.abs(i[:, 2] - z) < g.tol.merge).all())


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
1 change: 1 addition & 0 deletions tests/test_triangles.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def test_closest(self):
self.assertTrue((comparison < 1e-8).all())
g.log.info('finished closest check on %d triangles', len(closest))


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
1 change: 1 addition & 0 deletions tests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def test_file_hash(self):

file_obj.close()


if __name__ == '__main__':
trimesh.util.attach_to_log()
unittest.main()
1 change: 1 addition & 0 deletions tests/test_voxel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_voxel(self):
m.volume,
v.volume)


if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
4 changes: 2 additions & 2 deletions trimesh/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ def moment_inertia(self):
inertia: (3,3) float, moment of inertia of the current mesh.
'''
inertia = np.array(self.mass_properties(skip_inertia=False)['inertia'])
return inertia
return inertia

@util.cache_decorator
def triangles(self):
'''
Expand Down
1 change: 1 addition & 0 deletions trimesh/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def boolean_automatic(meshes, operation):
raise ValueError('No backends available for boolean operations!')
return result


_engines = {None: boolean_automatic,
'auto': boolean_automatic,
'scad': interfaces.scad.boolean,
Expand Down
10 changes: 5 additions & 5 deletions trimesh/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from .constants import tol


identifier_sigfig = (4,2,1,5,2)
identifier_sigfig = (4, 2, 1, 5, 2)


def identifier_simple(mesh):
'''
Expand All @@ -29,11 +30,11 @@ def identifier_simple(mesh):
'''
identifier = np.array([mesh.volume,
mesh.area,
mesh.area/mesh.convex_hull_raw.area,
mesh.area / mesh.convex_hull_raw.area,
mesh.euler_number,
0.0],
dtype = np.float64)
dtype=np.float64)

if mesh.is_watertight:
origin = mesh.center_mass
else:
Expand Down Expand Up @@ -63,4 +64,3 @@ def identifier_hash(identifier, sigfig=None):
hashable = (as_int * (10 ** multiplier)).astype(np.int32)
md5 = util.md5_object(hashable)
return md5

Loading

0 comments on commit 80fbb64

Please sign in to comment.