Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
resigned = g.trimesh.util.vector_hemisphere(v)
# after resigning, negative vectors should equal positive
check = (abs(g.np.diff(resigned.reshape((-1, 2, dimension)),
axis=1).sum(axis=2)) <
g.trimesh.constants.tol.zero).all()
assert check
a, s = g.trimesh.util.vector_hemisphere(v, return_sign=True)
assert g.np.allclose(v, a * s.reshape((-1, 1)))
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
# count the number of filled pixels
fill_cnt = g.np.array(filled).sum()
both_cnt = g.np.array(both).sum()
outl_cnt = g.np.array(outline).sum()
# filled should have more than an outline
assert fill_cnt > outl_cnt
# filled+outline should have more than outline
assert both_cnt > outl_cnt
# filled+outline should have more than filled
assert both_cnt > fill_cnt
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
mesh.section(o, n)
mesh.section(mesh.center_mass, n)
# same with multiplane
mesh.section_multiplane(o, n, heights)
mesh.section_multiplane(mesh.center_mass, n, heights)
assert not mesh.vertices.flags['WRITEABLE']
assert not mesh.faces.flags['WRITEABLE']
assert g.np.all(g.np.isclose(verts, mesh.vertices))
assert g.np.all(g.np.isclose(faces, mesh.faces))
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
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()
P31 = g.np.random.random((100, 3))
args = rendering.points_to_vertexlist(P31)
args_auto = rendering.convert_to_vertexlist(P31)
assert len(args) == 6
assert len(args_auto) == len(args)
P32 = g.trimesh.points.PointCloud(P31)
args = rendering.convert_to_vertexlist(P32)
assert len(args) == 6
assert len(args_auto) == len(args)
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
# analytic primitive volume
tess = prim.to_mesh()
assert g.np.isclose(tess.convex_hull.volume,
tess.volume)
def test_projections(self):
# check the vertex projection onto adjacent face plane
# this is used to calculate convexity
for m in g.get_meshes(4):
assert (len(m.face_adjacency_projections) ==
(len(m.face_adjacency)))
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
m = s.geometry[geo].copy()
m.apply_transform(T)
meshes.append(m)
if not all(meshes[0].identifier_md5 == i.identifier_md5
for i in meshes):
raise ValueError(
'{} differs after transform!'.format(geom_name))
assert (scenes[0].geometry['disc_cam_B'].identifier_md5 !=
scenes[0].geometry['disc_cam_A'].identifier_md5)
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
# file name anyway, maybe something else can handle it
args = f(file_obj=nonexists, file_type='.ObJ')
assert len(args) == RET_COUNT
# should have cleaned up case
assert args[1] == 'obj'
# make sure overriding type works for string filenames
args = f(file_obj=exists, file_type='STL')
assert len(args) == RET_COUNT
# should have used manually passed type over .obj
assert args[1] == 'stl'
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
# create an SVG path string
svg = to_svg(seg)
# should be one move and one line per segment
assert svg.count('M') == len(seg)
assert svg.count('L') == len(seg)
try:
to_svg(g.random((100, 2, 3)))
except ValueError:
return
raise ValueError('to_svg accepted wrong input!')
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()
assert g.np.allclose(obb.bounds,
b.bounds)
# unordered extents and transforms
transform, extents = g.trimesh.bounds.oriented_bounds(b, ordered=False)
assert g.np.allclose(g.np.sort(extents), extents_ordered)
# create a box from the unordered OBB information
box = g.trimesh.creation.box(
extents=extents, transform=g.np.linalg.inv(transform))
# make sure it is a real OBB too
assert g.np.allclose(box.bounds, b.bounds)
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()