Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
g.log.error('discrete %s not ccw!',
d.metadata['file_name'])
for i in range(len(d.paths)):
assert d.polygons_closed[i].is_valid
assert d.polygons_closed[i].area > g.tol_path.zero
export_dict = d.export(file_type='dict')
to_dict = d.to_dict()
assert isinstance(to_dict, dict)
assert isinstance(export_dict, dict)
assert len(to_dict) == len(export_dict)
export_svg = d.export(file_type='svg') # NOQA
simple = d.simplify() # NOQA
split = d.split()
g.log.info('Split %s into %d bodies, checking identifiers',
d.metadata['file_name'],
len(split))
for body in split:
body.identifier
if len(d.root) == 1:
d.apply_obb()
# store the X values of bounds
ori = d.bounds.copy()
# apply a translation
d.apply_translation([10, 0])
# X should have translated by 10.0
assert g.np.allclose(d.bounds[:, 0] - 10, ori[:, 0])
# Y should not have moved
assert g.np.allclose(d.bounds[:, 1], ori[:, 1])
def test_engine_time(self):
for mesh in g.get_meshes():
tic = [g.time.time()]
for engine in self.engines:
mesh.split(engine=engine, only_watertight=False)
g.trimesh.graph.facets(mesh=mesh, engine=engine)
tic.append(g.time.time())
tic_diff = g.np.diff(tic)
tic_min = tic_diff.min()
tic_diff /= tic_min
g.log.info('graph engine on %s (scale %f sec):\n%s',
mesh.metadata['file_name'],
tic_min,
str(g.np.column_stack((self.engines,
tic_diff))))
def typical_application():
# make sure we can load everything we think we can
# while getting a list of meshes to run tests on
meshes = g.get_meshes(raise_error=True)
g.log.info('Running tests on %d meshes', len(meshes))
for mesh in meshes:
g.log.info('Testing %s', mesh.metadata['file_name'])
assert len(mesh.faces) > 0
assert len(mesh.vertices) > 0
assert len(mesh.edges) > 0
assert len(mesh.edges_unique) > 0
assert len(mesh.edges_sorted) > 0
assert len(mesh.edges_face) > 0
assert isinstance(mesh.euler_number, int)
if not mesh.is_volume:
continue
assert len(mesh.facets) == len(mesh.facets_area)
if len(mesh.facets) == 0:
continue
surface.sparse_indices, (-1, 3))
assert len(
solid.sparse_indices) >= len(
surface.sparse_indices)
assert solid.sparse_indices.shape == solid.points.shape
outside = m.bounds[1] + m.scale
for vox in surface, solid:
assert vox.sparse_indices.shape == vox.points.shape
assert g.np.all(vox.is_filled(vox.points))
assert not vox.is_filled(outside)
try:
cubes = surface.marching_cubes
assert cubes.area > 0.0
except ImportError:
g.log.info('no skimage, skipping marching cubes test')
g.log.info('Mesh volume was %f, voxelized volume was %f',
m.volume,
surface.volume)
def test_vhacd(self):
# exit if no VHACD
if not g.trimesh.interfaces.vhacd.exists and not g.all_dep:
g.log.warning(
'not testing convex decomposition (no vhacd)!')
return
g.log.info('testing convex decomposition using vhacd')
mesh = g.get_mesh('bunny.ply')
# run a convex decomposition using vhacd
decomposed = mesh.convex_decomposition(maxhulls=10, debug=True)
if len(decomposed) != 10:
# it should return the correct number of meshes
raise ValueError('{} != 10'.format(len(decomposed)))
# make sure everything is convex
# also this will fail if the type is returned incorrectly
assert all(i.is_convex for i in decomposed)
# make sure every result is actually a volume
# ie watertight, consistent winding, positive nonzero volume
assert path.md5() == md5_pre
for garbage in range(2):
# the simplified version shouldn't have lost area
assert g.np.allclose(path.area,
simplified.area,
rtol=1e-3)
# see if we fit as many arcs as existed in the original drawing
new_count = sum(int(type(i).__name__ == 'Arc')
for i in simplified.entities)
if new_count != arc_count:
print(new_count, arc_count)
if arc_count > 1:
g.log.info('originally were {} arcs, simplify found {}'.format(
arc_count,
new_count))
assert new_count > 0
assert new_count <= arc_count
# dump the cache to make sure bookkeeping wasn't busted or wrong
simplified._cache.clear()
# make sure the simplify call didn't alter our original mesh
assert path.md5() == md5_pre
def test_identifier(self):
count = 25
meshes = g.np.append(list(g.get_meshes(10)),
g.get_mesh('fixed_top.ply'))
for mesh in meshes:
if not mesh.is_volume:
g.log.warning('Mesh %s is not watertight!',
mesh.metadata['file_name'])
continue
g.log.info('Trying hash at %d random transforms', count)
md5 = g.deque()
idf = g.deque()
for i in range(count):
permutated = mesh.permutate.transform()
permutated = permutated.permutate.tessellation()
md5.append(permutated.identifier_md5)
idf.append(permutated.identifier)
result = g.np.array(md5)
ok = (result[0] == result[1:]).all()
if not ok:
debug = []
for a in idf:
as_int, exp = g.trimesh.util.sigfig_int(
tic = [g.time.time()]
for i in funs:
p, d = self.check_nearest_point_function(i)
data_points.append(p)
data_dist.append(d)
tic.append(g.time.time())
assert g.np.ptp(data_points, axis=0).max() < g.tol.merge
assert g.np.ptp(data_dist, axis=0).max() < g.tol.merge
log_msg = '\n'.join("{}: {}s".format(i, j)
for i, j in zip(
[i.__name__ for i in funs],
g.np.diff(tic)))
g.log.info(
'Compared the following nearest point functions:\n' +
log_msg)