Пример #1
0
    def test_surf_normalized(self):

        def assert_is_unit_norm(v):
            assert_almost_equal(1., np.sum(v*v))
            assert_equal(v.shape, (len(v),))

        def assert_same_direction(v,w):
            assert_almost_equal(v.dot(w),(v.dot(v)*w.dot(w))**.5)

        def helper_test_vec_normalized(v):
            v_norm=surf.normalized(v)
            assert_is_unit_norm(v_norm)
            assert_same_direction(v,v_norm)

            return v_norm

        sizes=[(8,),(7,4)]

        for size in sizes:
            v=np.random.normal(size=size)
            if len(size)==1:
                helper_test_vec_normalized(v)
            else:
                # test for vectors and for matrix
                v_n = surf.normalized(v)

                n_vecs=v.shape[1]
                for i in xrange(n_vecs):
                    v_n_i=helper_test_vec_normalized(v[i,:])
                    assert_array_almost_equal(v_n_i, v_n[i,:])
Пример #2
0
    def test_surface_face_normal(self, do_deterioriate_surface):
        vec1 = np.random.normal(size=(3,))
        vec2 = np.random.normal(size=(3,))

        vec_normal = -np.cross(vec1, vec2)

        plane = generate_plane((0, 0, 0), vec1, vec2, 10, 10)

        if do_deterioriate_surface:
            plane = SurfingSurfaceTests.deterioriate_surface(plane)

        plane_face_normals = plane.face_normals

        has_non_nan = False

        for f_n in plane_face_normals:
            if np.any(np.isnan(f_n)):
                continue

            assert_vector_direction_almost_equal(f_n, vec_normal, decimal=0)
            assert_almost_equal(f_n, surf.normalized(
                plane.nanmean_face_normal), decimal=0)

            has_non_nan = True

        if not has_non_nan:
            assert False, "Test should include faces with non-NaN normals"
Пример #3
0
        def helper_test_vec_normalized(v):
            v_norm=surf.normalized(v)
            assert_is_unit_norm(v_norm)
            assert_same_direction(v,v_norm)

            return v_norm