def test_change_translation( self ): self.first_child[-1].translation = (-1,0,0) m2 = self.second_child.transformMatrix() assert allclose( m2, array([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],'f') ), m2
def test_rotation_array( self ): path = self.empty + [ Transform( rotation = (0,1,0,pi/2 )), ] matrix = path.transformMatrix() projected = dot( array([ 0,0,1,1],'f'),matrix ) assert allclose( projected, array([1,0,0,1],'f'),atol=.0001), projected
def testForwardHexidecimal(self): for name, value in cssColors.items(): representation = '#%02x%02x%02x' % tuple(map(toInt, value)) result = stringToColor(representation) assert arrays.allclose( result, value, 0.001), """Expected %r, got %r""" % (value, result)
def test_forward_back( self ): for child in (self.second_child,self.third_child,self.fourth_child): matrix = child.transformMatrix( ) inverse = child.transformMatrix( inverse=True ) test = array( [10,20,30,1], 'f') projected = dot( matrix, test ) back = dot( inverse, projected ) assert allclose( test, back ), (test,back, child[-1], matrix, inverse)
def test_nest_simple( self ): path = self.empty + [ Transform( translation=(0,0,1), DEF='translate', ), Transform( scale=(1,1,.5),DEF='scale'), ] matrix = path.transformMatrix() projected = dot( array([0,0,10,1],'f'), matrix ) assert allclose( projected, array([0,0,6,1]),atol=.0001), projected
def testSFColorString( self): color = SFColor( "test", 1, list) for value,expected in [ ((.2,.3,.4),(.2,.3,.4)), ('red', (1,0,0)), ('#ff0000',(1,0,0)), ]: result = color.coerce( value ) assert arrays.allclose( result,expected), """FAIL: color conversion for %(value)r\nExpected: %(expected)s\nGot:%(result)s"""%(locals())
def test_complex_transform( self ): test = array( [0,0,10,1], 'f' ) matrix = self.fourth_child.transformMatrix( ) #inverse = self.fourth_child.transformMatrix( inverse=True ) projected = dot( test, matrix ) # projecting out of the screen, then rotated # counter-clockwise 90deg (to go right), then scaled up 2x (to 20) # then translated 5 to the right... target = array([25,0,0,1],'f') assert allclose( projected, target, atol=0.0001), projected
def test_perspectiveMatrix( self ): """Test that perspective matrix calculation matches expected values""" result = transformmatrix.perspectiveMatrix( 59.999999999999993*DEGTORAD, 1.0, 0.29999999999999999, 50000 ) inverse = transformmatrix.perspectiveMatrix( 59.999999999999993*DEGTORAD, 1.0, 0.29999999999999999, 50000, inverse=True, ) expected = array([ [ 1.73205081, 0., 0., 0., ], [ 0., 1.73205081, 0., 0., ], [ 0., 0., -1.000012, -1., ], [ 0., 0., -0.6000036, 0., ],],'f') assert allclose(result,expected), result test = array([ 20,8,5,1.0 ],'f') projected = dot( result, test ) print(projected) unprojected = dot( inverse, projected ) assert allclose( unprojected, test ), (unprojected, test)
def testSFColorString(self): color = SFColor("test", 1, list) for value, expected in [ ((.2, .3, .4), (.2, .3, .4)), ('red', (1, 0, 0)), ('#ff0000', (1, 0, 0)), ]: result = color.coerce(value) assert arrays.allclose( result, expected ), """FAIL: color conversion for %(value)r\nExpected: %(expected)s\nGot:%(result)s""" % ( locals())
def test_calculations( self ): for (matrix,point, expected, name) in self._create_test_matrix( transformmatrix.transMatrix, transformmatrix.rotMatrix, transformmatrix.scaleMatrix, ): try: result = dot( point,matrix) except TypeError as err: sys.stderr.write("""\nF (TypeError):\n\tpoint=%(point)s\n\t%(matrix)s\n"""%(locals())) else: assert allclose( result, expected, 0, 0.000001 ),(name,matrix,point,expected,result)
def test_cross_check( self ): first = self._create_test_matrix( _transformmatrix_accel.transMatrix, _transformmatrix_accel.rotMatrix, _transformmatrix_accel.scaleMatrix, ) second = self._create_test_matrix( _transformmatrix.transMatrix, _transformmatrix.rotMatrix, _transformmatrix.scaleMatrix, ) for (firstmatrix,_,_,_),(secondmatrix,point, _, name) in zip(first,second): assert allclose(firstmatrix,secondmatrix, atol=0.000001), (firstmatrix,secondmatrix,name)
def testForwardHexidecimal (self): for name, value in cssColors.items (): representation = '#%02x%02x%02x'%tuple(map(toInt,value)) result = stringToColor( representation ) assert arrays.allclose( result, value, 0.001), """Expected %r, got %r"""%(value, result)
def testMFColorString (self): color = MFColor( "test", 1, list) result = color.coerce( [.2,.3,.4,'red'] ) assert arrays.allclose( result, ((.2,.3,.4),(1,0,0)))
def test_change_rotation( self ): self.first_child[-1].rotation = (0,1,0,3.14) m = self.second_child.transformMatrix( translate=False, scale=False) self.first_child[-1].rotation = (0,1,0,0.0) m2 = self.second_child.transformMatrix( translate=False, scale=False) assert not allclose( m,m2 ), (m,m2)
def testMFColorString(self): color = MFColor("test", 1, list) result = color.coerce([.2, .3, .4, 'red']) assert arrays.allclose(result, ((.2, .3, .4), (1, 0, 0)))
def test_second_child( self ): m = self.second_child.transformMatrix() assert allclose( m, array([[1,0,0,0],[0,1,0,0],[0,0,1,0],[2,0,0,1]],'f') ), m
def test_empty_matrix( self ): m = self.empty.transformMatrix() assert allclose( m, array([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],'f') ), m