How to use the generic.np 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_svg.py View on Github external
exported = d.export(file_type='svg')
            # load the exported SVG
            stream = g.trimesh.util.wrap_as_stream(exported)

            if g.np.isclose(d.area, 0.0):
                continue

            loaded = g.trimesh.load(stream, file_type='svg')

            # we only have line and arc primitives as SVG
            # export and import
            if all(i.__class__.__name__ in ['Line', 'Arc']
                   for i in d.entities):
                # perimeter should stay the same-ish
                # on export/import
                assert g.np.isclose(d.length,
                                    loaded.length,
                                    rtol=.01)
github mikedh / trimesh / tests / test_mutate.py View on Github external
def _test_not_mutated(self, mesh, verts, faces):
        verts = g.np.copy(verts)
        faces = g.np.copy(faces)
        lo, hi = mesh.bounds

        mesh.faces_sparse
        mesh.face_normals
        mesh.vertex_normals
        mesh.extents
        mesh.scale
        mesh.centroid
        mesh.center_mass
        mesh.density
        mesh.volume
        mesh.mass
        mesh.moment_inertia
        mesh.principal_inertia_components
        mesh.principal_inertia_vectors
        mesh.principal_inertia_transform
github mikedh / trimesh / tests / test_util.py View on Github external
def strips_to_faces(strips):
            """
            A slow but straightforward version of the function to test against
            """
            faces = g.collections.deque()
            for s in strips:
                s = g.np.asanyarray(s, dtype=g.np.int)
                # each triangle is defined by one new vertex
                tri = g.np.column_stack([g.np.roll(s, -i)
                                         for i in range(3)])[:-2]
                # we need to flip ever other triangle
                idx = (g.np.arange(len(tri)) % 2).astype(bool)
                tri[idx] = g.np.fliplr(tri[idx])
                faces.append(tri)
            # stack into one (m,3) array
            faces = g.np.vstack(faces)
            return faces
github mikedh / trimesh / tests / test_upstream.py View on Github external
def test_shapely(self):
        """
        conda installs of shapely started returning NaN on
        valid input so make sure our builds fail in that case
        """
        string = g.LineString([[0, 0], [1, 0]])
        assert g.np.isclose(string.length, 1.0)
github mikedh / trimesh / tests / test_scene.py View on Github external
assert isinstance(glb, bytes)

                for export_format in ['dict', 'dict64']:
                    # try exporting the scene as a dict
                    # then make sure json can serialize it
                    e = g.json.dumps(s.export(file_type=export_format))

                    # reconstitute the dict into a scene
                    r = g.trimesh.load(g.json.loads(e))

                    # make sure the extents are similar before and after
                    assert g.np.allclose(g.np.product(s.extents),
                                         g.np.product(r.extents))

                s.rezero()
                assert (g.np.abs(s.centroid) < 1e-3).all()

                # make sure explode doesn't crash
                s.explode()
github mikedh / trimesh / tests / test_collision.py View on Github external
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])

        # Test one-to-many collision checking
        m = g.trimesh.collision.CollisionManager()
        m.add_object('cube0', cube)
        m.add_object('cube1', cube, tf1)

        ret = m.in_collision_single(cube)
        assert ret is True

        ret, names, data = m.in_collision_single(cube,
                                                 tf1,
                                                 return_names=True,
github mikedh / trimesh / tests / test_render.py View on Github external
assert len(args) == 6
        assert len(args_auto) == len(args)

        P21 = g.get_mesh('2D/wrench.dxf')
        args = rendering.path_to_vertexlist(P21)
        args_auto = rendering.convert_to_vertexlist(P21)
        assert len(args) == 6
        assert len(args_auto) == len(args)

        P22 = g.np.random.random((100, 2))
        args = rendering.points_to_vertexlist(P22)
        args_auto = rendering.convert_to_vertexlist(P22)
        assert len(args) == 6
        assert len(args_auto) == len(args)

        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)
github mikedh / trimesh / tests / test_util.py View on Github external
def test_bounds_tree(self):
        for attempt in range(3):
            for dimension in [2, 3]:
                t = g.np.random.random((1000, 3, dimension))
                bounds = g.np.column_stack((t.min(axis=1), t.max(axis=1)))
                tree = g.trimesh.util.bounds_tree(bounds)
                self.assertTrue(0 in tree.intersection(bounds[0]))
github mikedh / trimesh / tests / test_section.py View on Github external
# Cut corner off of box and make sure the bounds and number of faces is correct
        # (Tests new triangles, but not new quads or triangles contained entirely)
        plane_origin = mesh.bounds[1] - 0.05
        plane_normal = mesh.bounds[1]

        sliced = mesh.slice_plane(plane_origin=plane_origin,
                                  plane_normal=plane_normal)

        assert g.np.isclose(sliced.bounds[0], mesh.bounds[1] - 0.15).all()
        assert g.np.isclose(sliced.bounds[1], mesh.bounds[1]).all()
        assert len(sliced.faces) == 5

        # Cut top off of box and make sure bounds and number of faces is correct
        # Tests new quads and entirely contained triangles
        plane_origin = mesh.bounds[1] - 0.05
        plane_normal = g.np.array([0, 0, 1])

        sliced = mesh.slice_plane(plane_origin=plane_origin,
                                  plane_normal=plane_normal)

        assert g.np.isclose(
            sliced.bounds[0], mesh.bounds[0] + g.np.array([0, 0, 0.95])).all()
        assert g.np.isclose(sliced.bounds[1], mesh.bounds[1]).all()
        assert len(sliced.faces) == 14

        # non- watertight more complex mesh
        bunny = g.get_mesh('bunny.ply')

        origin = bunny.bounds.mean(axis=0)
        normal = g.trimesh.unitize([1, 1, 2])

        sliced = bunny.slice_plane(plane_origin=origin,