Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert s.shape[1] == 2
def test_color(self):
p = g.get_mesh('2D/wrench.dxf')
# make sure we have entities
assert len(p.entities) > 0
# make sure shape of colors is correct
assert p.colors.shape == (len(p.entities), 4)
color = [255, 0, 0, 255]
# assign a color to the entity
p.entities[0].color = color
# make sure this is reflected in the path color
assert g.np.allclose(p.colors[0], color)
class SplitTest(g.unittest.TestCase):
def test_split(self):
for fn in ['2D/ChuteHolderPrint.DXF',
'2D/tray-easy1.dxf',
'2D/sliding-base.dxf',
'2D/wrench.dxf',
'2D/spline_1.dxf']:
p = g.get_mesh(fn)
# make sure something was loaded
assert len(p.root) > 0
# split by connected
split = p.split()
try:
from . import generic as g
except BaseException:
import generic as g
TEST_DIM = (10000, 3)
class CacheTest(g.unittest.TestCase):
def test_hash(self):
setup = 'import numpy, trimesh;'
setup += 'd = numpy.random.random((10000,3));'
setup += 't = trimesh.caching.tracked_array(d)'
count = 10000
mt = g.timeit.timeit(setup=setup,
stmt='t._modified_m=True;t.md5()',
number=count)
ct = g.timeit.timeit(setup=setup,
stmt='t._modified_c=True;t.crc()',
number=count)
xt = g.timeit.timeit(setup=setup,
stmt='t._modified_x=True;t.fast_hash()',
try:
from . import generic as g
except BaseException:
import generic as g
from trimesh.scene.transforms import EnforcedForest
def random_chr():
return chr(ord('a') + int(round(g.np.random.random() * 25)))
class SceneTests(g.unittest.TestCase):
def test_scene(self):
for mesh in g.get_mesh('cycloidal.ply',
'sphere.ply'):
if mesh.units is None:
mesh.units = 'in'
scene_split = g.trimesh.scene.split_scene(mesh)
scene_split.convert_units('in')
scene_base = g.trimesh.Scene(mesh)
# save MD5 of scene before concat
pre = [scene_split.md5(), scene_base.md5()]
# make sure MD5's give the same result twice
assert scene_split.md5() == pre[0]
assert scene_base.md5() == pre[1]
try:
from . import generic as g
except BaseException:
import generic as g
class LightTests(g.unittest.TestCase):
def test_basic(self):
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)
try:
from . import generic as g
except BaseException:
import generic as g
class RegistrationTest(g.unittest.TestCase):
def test_procrustes(self):
# create random points in space
points_a = (g.np.random.random((1000, 3)) - .5) * 1000
# create a random transform
matrix = g.trimesh.transformations.random_rotation_matrix()
# add a translation component to transform
matrix[:3, 3] = g.np.random.random(3) * 100
# apply transform to points A
points_b = g.trimesh.transform_points(points_a, matrix)
# run the solver
(matrixN,
transformed,
cost) = g.trimesh.registration.procrustes(points_a, points_b)
# the points should be identical
try:
from . import generic as g
except BaseException:
import generic as g
class VisualTest(g.unittest.TestCase):
def test_visual(self):
mesh = g.get_mesh('featuretype.STL')
# stl shouldn't have any visual properties defined
assert not mesh.visual.defined
for facet in mesh.facets:
mesh.visual.face_colors[facet] = g.trimesh.visual.random_color()
assert mesh.visual.defined
assert not mesh.visual.transparency
mesh.visual.face_colors[0] = [10, 10, 10, 130]
assert mesh.visual.transparency
try:
from . import generic as g
except BaseException:
import generic as g
class NSphereTest(g.unittest.TestCase):
def test_minball(self):
# how close do we need to be
tol_fit = 1e-2
# get some assorted mesh geometries to test performance
# and a perfect sphere mesh to test the degenerate case
for m in g.np.append(list(g.get_meshes(5)),
g.trimesh.primitives.Sphere()):
s = m.bounding_sphere
R_check = ((m.vertices - s.primitive.center)
** 2).sum(axis=1).max() ** .5
assert len(s.primitive.center) == 3
assert s.primitive.radius > 0.0
"""
Copy meshes and make sure they do what we expect.
"""
try:
from . import generic as g
except BaseException:
import generic as g
class CopyTests(g.unittest.TestCase):
def test_copy(self):
for mesh in g.get_meshes(raise_error=True):
if not isinstance(mesh, g.trimesh.Trimesh):
continue
start = {mesh.md5(), mesh.crc()}
# make sure some stuff is populated
mesh.kdtree
mesh.triangles_tree
mesh.face_adjacency_angles
mesh.facets
assert 'triangles_tree' in mesh._cache
assert len(mesh._cache) > 0
# if you cache c-objects then deepcopy the mesh
try:
from . import generic as g
except BaseException:
import generic as g
class SmoothTest(g.unittest.TestCase):
def test_smooth(self):
"""
Load a collada scene with pycollada.
"""
m = g.trimesh.creation.icosahedron()
m.vertices, m.faces = g.trimesh.remesh.subdivide_to_size(
m.vertices, m.faces, 0.1)
s = m.copy()
f = m.copy()
d = m.copy()
assert m.is_volume
# Equal Weights
lap = g.trimesh.smoothing.laplacian_calculation(
try:
from . import generic as g
except BaseException:
import generic as g
class FacetTest(g.unittest.TestCase):
def test_facet(self):
m = g.get_mesh('featuretype.STL')
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)
# this mesh should have 8 facets on the convex hull
assert m.facets_on_hull.astype(int).sum() == 8
def test_empty(self):
"""
An icosphere has no facets so make sure