How to use the generic.unittest function in generic

To help you get started, we’ve selected a few generic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikedh / trimesh / tests / test_proximity.py View on Github external
try:
    from . import generic as g
except BaseException:
    import generic as g


class NearestTest(g.unittest.TestCase):

    def test_naive(self):
        """
        Test the naive nearest point function
        """

        # generate a unit sphere mesh
        sphere = g.trimesh.primitives.Sphere(subdivisions=4)

        # randomly sample surface of a unit sphere, then expand to radius 2.0
        points = g.trimesh.sample.sample_surface_sphere(100) * 2

        # use the triangles from the unit sphere
        triangles = sphere.triangles  # NOQA

        # do the check
github mikedh / trimesh / tests / test_camera.py View on Github external
try:
    from . import generic as g
except BaseException:
    import generic as g

import numpy as np


class CameraTests(g.unittest.TestCase):

    def test_K(self):
        resolution = (320, 240)
        fov = (60, 40)
        camera = g.trimesh.scene.Camera(
            resolution=resolution,
            fov=fov)

        # ground truth matrix
        K_expected = np.array([[277.128, 0, 160],
                               [0, 329.697, 120],
                               [0, 0, 1]],
                              dtype=np.float64)

        assert np.allclose(camera.K, K_expected, rtol=1e-3)
github mikedh / trimesh / tests / test_normals.py View on Github external
try:
    from . import generic as g
except BaseException:
    import generic as g


class NormalsTest(g.unittest.TestCase):

    def test_vertex_normal(self):
        mesh = g.trimesh.creation.icosahedron()
        # the icosahedron is centered at zero, so the true vertex
        # normal is just a unit vector of the vertex position
        truth = g.trimesh.util.unitize(mesh.vertices)

        # force fallback to loop normal summing by passing None
        # as the sparse matrix
        normals = g.trimesh.geometry.mean_vertex_normals(
            len(mesh.vertices),
            mesh.faces,
            mesh.face_normals)
        assert g.np.allclose(normals - truth, 0.0)

        # make sure the automatic sparse matrix generation works
github mikedh / trimesh / tests / test_binvox.py View on Github external
'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()
github mikedh / trimesh / tests / test_align.py View on Github external
align = g.trimesh.geometry.align_vectors
        T = align([0, 0, -1], [-1e-17, 1e-17, 1])
        assert g.np.isclose(g.np.linalg.det(T), 1.0)

        T = align([0, 0, -1], [-1e-4, 1e-4, 1])
        assert g.np.isclose(g.np.linalg.det(T), 1.0)

        vector_1 = g.np.array([7.12106798e-07, -7.43194705e-08, 1.00000000e+00])
        vector_2 = g.np.array([0, 0, -1])
        T, angle = align(vector_1, vector_2, return_angle=True)
        assert g.np.isclose(g.np.linalg.det(T), 1.0)


if __name__ == '__main__':
    g.trimesh.util.attach_to_log()
    g.unittest.main()
github mikedh / trimesh / tests / test_merge.py View on Github external
# check the copy with an int mask and see if inverse is created
        assert copied.referenced_vertices.sum() == 8
        assert copied.vertices.shape == (10008, 3)
        mask = g.np.nonzero(copied.referenced_vertices)[0]

        copied.update_vertices(mask)
        assert len(copied.vertices) == 8
        assert copied.is_volume
        assert copied.euler_number == 2
        assert copied.referenced_vertices.sum() == 8


if __name__ == '__main__':
    g.trimesh.util.attach_to_log()
    g.unittest.main()
github mikedh / trimesh / tests / test_trackball.py View on Github external
assert trackball.pose[0, 0] < 1
        assert trackball.pose[0, 1] == 0
        assert trackball.pose[0, 2] > 0
        assert trackball.pose[1, 0] == 0
        assert trackball.pose[1, 1] == 1
        assert trackball.pose[1, 2] == 0
        assert trackball.pose[2, 0] < 0
        assert trackball.pose[2, 1] == 0
        assert trackball.pose[2, 2] < 1
        g.np.testing.assert_allclose(trackball.pose[:, 3], [0, 0, 0, 1])
        g.np.testing.assert_allclose(trackball.pose[3, :], [0, 0, 0, 1])


if __name__ == '__main__':
    g.trimesh.util.attach_to_log()
    g.unittest.main()
github mikedh / trimesh / tests / test_integrate.py View on Github external
integrator_p, expr_p = symbolic_barycentric(str(f))

            g.log.debug('expression %s was integrated to %s',
                        str(f),
                        str(expr))

            summed = integrator(m).sum()
            summed_p = integrator_p(m).sum()
            self.assertTrue(g.np.allclose(summed,
                                          summed_p))
            self.assertFalse(g.np.allclose(summed, 0.0))


if __name__ == '__main__':
    g.trimesh.util.attach_to_log()
    g.unittest.main()
github mikedh / trimesh / tests / test_collision.py View on Github external
try:
    from . import generic as g
except BaseException:
    import generic as g


class CollisionTest(g.unittest.TestCase):

    def test_collision(self):
        # Ensure that FCL is importable
        try:
            g.trimesh.collision.CollisionManager()
        except ValueError:
            g.log.warning('skipping collision tests, no FCL installed')
            return

        cube = g.get_mesh('unit_cube.STL')

        tf1 = g.np.eye(4)
        tf1[:3, 3] = g.np.array([5, 0, 0])

        tf2 = g.np.eye(4)
        tf2[:3, 3] = g.np.array([-5, 0, 0])