Example #1
0
 def test_concat(self):
     a,b,c,d,tx,ty = 1,2,3,4,5,6
     transform1 = affine.affine_from_values(a,b,c,d,tx,ty)
     a,b,c,d,tx,ty = 2,3,4,5,6,7
     transform2 = affine.affine_from_values(a,b,c,d,tx,ty)
     tot_transform = affine.concat(transform1,transform2)
     pt1 = array([1.,-1.,1.])
     actual = dot(pt1,tot_transform)
     # this does the first transform and the scaling separately
     desired = dot(dot(pt1,transform2),transform1)
     assert(alltrue( (actual - desired) < 1e-6 ))
 def test_concat(self):
     a, b, c, d, tx, ty = 1, 2, 3, 4, 5, 6
     transform1 = affine.affine_from_values(a, b, c, d, tx, ty)
     a, b, c, d, tx, ty = 2, 3, 4, 5, 6, 7
     transform2 = affine.affine_from_values(a, b, c, d, tx, ty)
     tot_transform = affine.concat(transform1, transform2)
     pt1 = array([1., -1., 1.])
     actual = dot(pt1, tot_transform)
     # this does the first transform and the scaling separately
     desired = dot(dot(pt1, transform2), transform1)
     assert (alltrue((actual - desired) < 1e-6))
Example #3
0
 def test_from_values(self):
     a,b,c,d,tx,ty = 1,2,3,4,5,6
     mat = affine.affine_from_values(a,b,c,d,tx,ty)
     desired = array([[a,  b, 0],
                      [c,  d, 0],
                      [tx,ty, 1]])
     assert(alltrue(ravel(mat)==ravel(desired)))
Example #4
0
    def get_ctm(self):
        """ Returns the current coordinate transform matrix.

            XXX: This should really return a 3x3 matrix (or maybe an affine
                 object?) like the other API's.  Needs thought.
        """
        return affine.affine_from_values(*copy.copy(self.gc._currentMatrix))
Example #5
0
    def get_ctm(self):
        """ Returns the current coordinate transform matrix.

            XXX: This should really return a 3x3 matrix (or maybe an affine
                 object?) like the other API's.  Needs thought.
        """
        return affine.affine_from_values(*copy.copy(self.gc._currentMatrix))
Example #6
0
 def test_is_identity(self):
     # a true case.
     m = affine.affine_identity()
     assert(affine.is_identity(m))
     # and a false one.
     a,b,c,d,tx,ty = 1,2,3,4,5,6
     m = affine.affine_from_values(a,b,c,d,tx,ty)
     assert(not affine.is_identity(m))
 def test_is_identity(self):
     # a true case.
     m = affine.affine_identity()
     assert (affine.is_identity(m))
     # and a false one.
     a, b, c, d, tx, ty = 1, 2, 3, 4, 5, 6
     m = affine.affine_from_values(a, b, c, d, tx, ty)
     assert (not affine.is_identity(m))
Example #8
0
 def test_scale(self):
     a,b,c,d,tx,ty = 1,2,3,4,5,6
     transform1 = affine.affine_from_values(a,b,c,d,tx,ty)
     transform2 = affine.scale(transform1,.5,1.5)
     pt1 = array([1.,-1.,1.])
     actual = dot(pt1,transform2)
     # this does the first transform and the scaling separately
     desired = dot(pt1,transform1) *array((.5,1.5,1.))
     assert(alltrue( (actual - desired) < 1e-6 ))
Example #9
0
 def test_invert(self):
     """ An matrix times its inverse should produce the identity matrix
     """
     a,b,c,d,tx,ty = 1,2,3,4,5,6
     transform1 = affine.affine_from_values(a,b,c,d,tx,ty)
     transform2 = affine.invert(transform1)
     desired = affine.affine_identity()
     actual = dot(transform2,transform1)
     assert(alltrue( (ravel(actual) - ravel(desired)) < 1e-6 ))
 def test_scale(self):
     a, b, c, d, tx, ty = 1, 2, 3, 4, 5, 6
     transform1 = affine.affine_from_values(a, b, c, d, tx, ty)
     transform2 = affine.scale(transform1, .5, 1.5)
     pt1 = array([1., -1., 1.])
     actual = dot(pt1, transform2)
     # this does the first transform and the scaling separately
     desired = dot(pt1, transform1) * array((.5, 1.5, 1.))
     assert (alltrue((actual - desired) < 1e-6))
 def test_invert(self):
     """ An matrix times its inverse should produce the identity matrix
     """
     a, b, c, d, tx, ty = 1, 2, 3, 4, 5, 6
     transform1 = affine.affine_from_values(a, b, c, d, tx, ty)
     transform2 = affine.invert(transform1)
     desired = affine.affine_identity()
     actual = dot(transform2, transform1)
     assert (alltrue((ravel(actual) - ravel(desired)) < 1e-6))
Example #12
0
 def test_rotate(self):
     a,b,c,d,tx,ty = 1.,0,0,1.,0,0
     transform1 = affine.affine_from_values(a,b,c,d,tx,ty)
     tot_transform = affine.rotate(transform1,pi/4)
     pt1 = array([1.,0.,1.])
     actual = dot(pt1,tot_transform)
     # this does the first transform and the translate separately
     cos_pi_4 = 0.70710678118654757
     desired = array((cos_pi_4,cos_pi_4,1.))
     assert(alltrue( (actual - desired) < 1e-6 ))
 def test_rotate(self):
     a, b, c, d, tx, ty = 1., 0, 0, 1., 0, 0
     transform1 = affine.affine_from_values(a, b, c, d, tx, ty)
     tot_transform = affine.rotate(transform1, pi / 4)
     pt1 = array([1., 0., 1.])
     actual = dot(pt1, tot_transform)
     # this does the first transform and the translate separately
     cos_pi_4 = 0.70710678118654757
     desired = array((cos_pi_4, cos_pi_4, 1.))
     assert (alltrue((actual - desired) < 1e-6))
 def test_translate(self):
     a, b, c, d, tx, ty = 1, 2, 3, 4, 5, 6
     transform1 = affine.affine_from_values(a, b, c, d, tx, ty)
     translate_transform = array([[0, 0, 0], [0, 0, 0], [.5, 1.5, 1]])
     tot_transform = affine.translate(transform1, .5, 1.5)
     pt1 = array([1., -1., 1.])
     actual = dot(pt1, tot_transform)
     # this does the first transform and the translate separately
     desired = dot(dot(pt1, translate_transform), transform1)
     assert (alltrue((actual - desired) < 1e-6))
Example #15
0
 def test_translate(self):
     a,b,c,d,tx,ty = 1,2,3,4,5,6
     transform1 = affine.affine_from_values(a,b,c,d,tx,ty)
     translate_transform = array([[0,0,0],
                                  [0,0,0],
                                  [.5,1.5,1]])
     tot_transform = affine.translate(transform1,.5,1.5)
     pt1 = array([1.,-1.,1.])
     actual = dot(pt1,tot_transform)
     # this does the first transform and the translate separately
     desired = dot(dot(pt1,translate_transform),
                              transform1)
     assert(alltrue( (actual - desired) < 1e-6 ))
 def test_from_values(self):
     a, b, c, d, tx, ty = 1, 2, 3, 4, 5, 6
     mat = affine.affine_from_values(a, b, c, d, tx, ty)
     desired = array([[a, b, 0], [c, d, 0], [tx, ty, 1]])
     assert (alltrue(ravel(mat) == ravel(desired)))
 def test_affine_params(self):
     a, b, c, d, tx, ty = 1, 2, 3, 4, 5, 6
     trans = affine.affine_from_values(a, b, c, d, tx, ty)
     aa, bb, cc, dd, txx, tyy = affine.affine_params(trans)
     assert ((a, b, c, d, tx, ty) == (aa, bb, cc, dd, txx, tyy))
Example #18
0
 def get_text_matrix(self):
     """
     """
     a, b, c, d, tx, ty = self.gc._textMatrix
     return affine.affine_from_values(a, b, c, d, tx, ty)
Example #19
0
 def set_text_position(self, x, y):
     """
     """
     a, b, c, d, tx, ty = affine.affine_params(self.state.text_matrix)
     tx, ty = x, y
     self.state.text_matrix = affine.affine_from_values(a, b, c, d, tx, ty)
Example #20
0
 def test_affine_params(self):
     a,b,c,d,tx,ty = 1,2,3,4,5,6
     trans = affine.affine_from_values(a,b,c,d,tx,ty)
     aa,bb,cc,dd,txx,tyy = affine.affine_params(trans)
     assert( (a,b,c,d,tx,ty) == (aa,bb,cc,dd,txx,tyy))
Example #21
0
 def get_text_matrix(self):
     """
     """
     a, b, c, d, tx, ty = self.gc._textMatrix
     return affine.affine_from_values(a, b, c, d, tx, ty)
Example #22
0
 def set_text_position(self, x, y):
     """
     """
     a, b, c, d, tx, ty = affine.affine_params(self.state.text_matrix)
     tx, ty = x, y
     self.state.text_matrix = affine.affine_from_values(a, b, c, d, tx, ty)
Example #23
0
    def draw_image(self, img, rect=None, force_copy=False):
        """ Renders a GraphicsContextArray into this GC """
        xform = self.get_ctm()

        image = image_as_array(img)
        shape = image.shape
        if shape[2] == 4:
            fmt = "RGBA"
        else:
            fmt = "RGB"
        aii = ArrayImage(image, format=fmt)
        texture = aii.texture

        # The texture coords consists of (u,v,r) for each corner of the
        # texture rectangle.  The coordinates are stored in the order
        # bottom left, bottom right, top right, top left.
        x, y, w, h = rect
        texture.width = w
        texture.height = h
        t = texture.tex_coords
        points = array([[x, y + h], [x + w, y + h], [x + w, y], [x, y]])
        p = transform_points(affine_from_values(*xform), points)
        a = (gl.GLfloat * 32)(
            t[0],
            t[1],
            t[2],
            1.,
            p[0, 0],
            p[0, 1],
            0,
            1.,
            t[3],
            t[4],
            t[5],
            1.,
            p[1, 0],
            p[1, 1],
            0,
            1.,
            t[6],
            t[7],
            t[8],
            1.,
            p[2, 0],
            p[2, 1],
            0,
            1.,
            t[9],
            t[10],
            t[11],
            1.,
            p[3, 0],
            p[3, 1],
            0,
            1.,
        )
        gl.glPushAttrib(gl.GL_ENABLE_BIT)
        gl.glEnable(texture.target)
        gl.glBindTexture(texture.target, texture.id)
        gl.glPushClientAttrib(gl.GL_CLIENT_VERTEX_ARRAY_BIT)
        gl.glInterleavedArrays(gl.GL_T4F_V4F, 0, a)
        gl.glDrawArrays(gl.GL_QUADS, 0, 4)
        gl.glPopClientAttrib()
        gl.glPopAttrib()