<s> import numpy as np <EOL> from os import path as op <EOL> from numpy . testing import assert_allclose , assert_array_equal <EOL> from vispy . io import write_mesh , read_mesh , load_data_file <EOL> from vispy . geometry import _fast_cross_3d <EOL> from vispy . util import _TempDir <EOL> from vispy . testing import run_tests_if_main , assert_equal , assert_raises <EOL> temp_dir = _TempDir ( ) <EOL> def test_wavefront ( ) : <EOL> """<STR_LIT>""" <EOL> fname_mesh = load_data_file ( '<STR_LIT>' ) <EOL> fname_out = op . join ( temp_dir , '<STR_LIT>' ) <EOL> mesh1 = read_mesh ( fname_mesh ) <EOL> assert_raises ( IOError , read_mesh , '<STR_LIT>' ) <EOL> assert_raises ( ValueError , read_mesh , op . abspath ( __file__ ) ) <EOL> assert_raises ( ValueError , write_mesh , fname_out , * mesh1 , format = '<STR_LIT:foo>' ) <EOL> write_mesh ( fname_out , mesh1 [ <NUM_LIT:0> ] , mesh1 [ <NUM_LIT:1> ] , mesh1 [ <NUM_LIT:2> ] , mesh1 [ <NUM_LIT:3> ] ) <EOL> assert_raises ( IOError , write_mesh , fname_out , * mesh1 ) <EOL> write_mesh ( fname_out , * mesh1 , overwrite = True ) <EOL> mesh2 = read_mesh ( fname_out ) <EOL> assert_equal ( len ( mesh1 ) , len ( mesh2 ) ) <EOL> for m1 , m2 in zip ( mesh1 , mesh2 ) : <EOL> if m1 is None : <EOL> assert_equal ( m2 , None ) <EOL> else : <EOL> assert_allclose ( m1 , m2 , rtol = <NUM_LIT> ) <EOL> assert_allclose ( mesh1 [ <NUM_LIT:2> ] , _slow_calculate_normals ( mesh1 [ <NUM_LIT:0> ] , mesh1 [ <NUM_LIT:1> ] ) , <EOL> rtol = <NUM_LIT> , atol = <NUM_LIT> ) <EOL> def _slow_calculate_normals ( rr , tris ) : <EOL> """<STR_LIT>""" <EOL> rr = rr . astype ( np . float64 ) <EOL> r1 = rr [ tris [ : , <NUM_LIT:0> ] , : ] <EOL> r2 = rr [ tris [ : , <NUM_LIT:1> ] , : ] <EOL> r3 = rr [ tris [ : , <NUM_LIT:2> ] , : ] <EOL> tri_nn = np . cross ( ( r2 - r1 ) , ( r3 - r1 ) ) <EOL> size = np . sqrt ( np . sum ( tri_nn * tri_nn , axis = <NUM_LIT:1> ) ) <EOL> zidx = np . where ( size == <NUM_LIT:0> ) [ <NUM_LIT:0> ] <EOL> size [ zidx ] = <NUM_LIT:1.0> <EOL> tri_nn /= size [ : , np . newaxis ] <EOL> nn = np . zeros ( ( len ( rr ) , <NUM_LIT:3> ) ) <EOL> for p , verts in enumerate ( tris ) : <EOL> nn [ verts ] += tri_nn [ p , : ] <EOL> size = np . sqrt ( np . sum ( nn * nn , axis = <NUM_LIT:1> ) ) <EOL> size [ size == <NUM_LIT:0> ] = <NUM_LIT:1.0> <EOL> nn /= size [ : , np . newaxis ] <EOL> return nn <EOL> def test_huge_cross ( ) : <EOL> """<STR_LIT>""" <EOL> x = np . random . rand ( <NUM_LIT> , <NUM_LIT:3> ) <EOL> y = np . random . rand ( <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> z = np . cross ( x , y ) <EOL> zz = _fast_cross_3d ( x , y ) <EOL> assert_array_equal ( z , zz ) <EOL> run_tests_if_main ( ) </s>
