Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
n = 20
n += n % 2
pts = g.np.transpose([g.np.zeros(n),
g.np.ones(n),
g.np.linspace(-1, 1, n)])
# the faces facing the points should differ for first and second half of the set
# check their indices for inequality
faceIdxsA, faceIdxsB = g.np.split(mesh.nearest.on_surface(pts)[-1], 2)
assert (g.np.all(faceIdxsA == faceIdxsA[0]) and
g.np.all(faceIdxsB == faceIdxsB[0]) and
faceIdxsA[0] != faceIdxsB[0])
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
def test_paths(self):
from trimesh.path import packing
paths = [g.trimesh.load_path(i) for i in self.nestable]
r, inserted = packing.pack_paths(paths)
# number of paths inserted
count = len(g.np.unique(inserted))
# should have inserted all our paths
assert count == len(paths)
# splitting should result in the right number of paths
assert count == len(r.split())
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
data = kwargs.pop('data')
for i in range(len(data)):
block = g.trimesh.grouping.blocks(
g.np.roll(data, -i), **kwargs)
# get result as a set of tuples with the rolling index
# removed through a modulus, so we can compare equality
check = set([tuple(((j + i) % len(data)).tolist())
for j in block])
if current is None:
current = check
# all values should be the same
assert current == check
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
for light_class in [g.trimesh.scene.lighting.DirectionalLight,
g.trimesh.scene.lighting.PointLight,
g.trimesh.scene.lighting.SpotLight]:
light = light_class()
assert isinstance(light.intensity, float)
assert light.color.shape == (4,)
assert light.color.dtype == g.np.uint8
def test_scene(self):
s = g.get_mesh('duck.dae')
assert len(s.lights) > 0
assert isinstance(s.camera, g.trimesh.scene.cameras.Camera)
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
g.trimesh.smoothing.filter_laplacian(s, 0.5, 10, lap)
g.trimesh.smoothing.filter_humphrey(f, 0.1, 0.5, 10, lap)
g.trimesh.smoothing.filter_taubin(d, 0.5, 0.53, 10, lap)
assert s.is_volume
assert f.is_volume
assert d.is_volume
assert g.np.isclose(s.volume, m.volume, rtol=0.1)
assert g.np.isclose(f.volume, m.volume, rtol=0.1)
assert g.np.isclose(d.volume, m.volume, rtol=0.1)
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
def test_empty(self):
"""
An icosphere has no facets so make sure
everything returns empty.
"""
m = g.trimesh.creation.icosphere()
assert len(m.facets) == 0
assert len(m.facets) == len(m.facets_boundary)
assert len(m.facets) == len(m.facets_normal)
assert len(m.facets) == len(m.facets_area)
assert len(m.facets) == len(m.facets_on_hull)
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
h = fromstring(html)
# should have some children
children = list(h.body.iterchildren())
assert len(children) >= 2
def test_inNB(self):
import trimesh.viewer.notebook as js
# should only return True inside
# jypyter/IPython notebooks
assert not js.in_notebook()
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
1.0)
def test_stl(self):
model = g.get_mesh('empty.stl')
assert model.is_empty
def test_ply_dtype(self):
# make sure all ply dtype strings are valid dtypes
dtypes = g.trimesh.exchange.ply.dtypes
for d in dtypes.values():
# will raise if dtype string not valid
g.np.dtype(d)
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
original = p.bounds.copy()
matrix = p.apply_obb()
assert matrix.shape == (4, 4)
assert not g.np.allclose(p.bounds, original)
def test_remove_close(self):
# create 100 unique points
p = g.np.arange(300).reshape((100, 3))
# should return the original 100 points
culled, mask = g.trimesh.points.remove_close(g.np.vstack((p, p)), radius=0.1)
assert culled.shape == (100, 3)
assert mask.shape == (200,)
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
g.log.warning(
'No binvox encoder found, skipping binvox export tests')
return
file_obj = BytesIO(binvox.export_binvox(base))
file_obj.seek(0)
loaded = binvox.load_binvox(file_obj)
np.testing.assert_equal(loaded.encoding.dense, base.encoding.dense)
self.assertTrue(isinstance(base, v.VoxelGrid))
self.assertTrue(isinstance(loaded, v.VoxelGrid))
np.testing.assert_equal(base.transform, loaded.transform)
np.testing.assert_equal(base.shape, loaded.shape)
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()