Beispiel #1
0
 def test_scale_ctm(self):
     gc = basecore2d.GraphicsContextBase()
     ident = affine.affine_identity()
     sx, sy = 2.0, 3.0
     desired = affine.scale(ident, sx, sy)
     gc.scale_ctm(sx, sy)
     actual = gc.get_ctm()
     self.assertTrue(alltrue(ravel(actual == desired)))
 def test_scale_ctm(self):
     gc = basecore2d.GraphicsContextBase()
     ident = affine.affine_identity()
     sx, sy = 2., 3.
     desired = affine.scale(ident, sx, sy)
     gc.scale_ctm(sx, sy)
     actual = gc.get_ctm()
     self.assert_(alltrue(ravel(actual == desired)))
Beispiel #3
0
 def test_trs_factor(self):
     trans = affine.affine_identity()
     trans = affine.translate(trans,5,5)
     trans = affine.rotate(trans,2.4)
     trans = affine.scale(trans,10,10)
     tx,ty,sx,sy,angle = affine.trs_factor(trans)
     assert( (tx,ty) == (5,5))
     assert( (sx,sy) == (10,10))
     assert( angle == 2.4)
 def test_tsr_factor(self):
     trans = affine.affine_identity()
     trans = affine.translate(trans, 6, 5)
     trans = affine.scale(trans, 0.2, 10)
     trans = affine.rotate(trans, 2.4)
     tx, ty, sx, sy, angle = affine.tsr_factor(trans)
     assert ((tx, ty) == (6, 5))
     assert ((sx, sy) == (0.2, 10))
     assert (angle == 2.4)
 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))
Beispiel #6
0
 def test_tsr_factor(self):
     trans = affine.affine_identity()
     trans = affine.translate(trans,6,5)
     trans = affine.scale(trans,0.2,10)
     trans = affine.rotate(trans,2.4)
     tx,ty,sx,sy,angle = affine.tsr_factor(trans)
     assert( (tx,ty) == (6,5))
     assert( (sx,sy) == (0.2,10))
     assert( angle == 2.4)
Beispiel #7
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 ))
Beispiel #8
0
    def scale_ctm(self, sx, sy):
        """ Sets the coordinate system scale to the given values, (sx, sy).

            Parameters
            ----------
            sx : float
                The new scale factor for the x axis
            sy : float
                The new scale factor for the y axis
        """
        self.state.ctm = affine.scale(self.state.ctm, sx, sy)
        self.active_subpath.append((SCALE_CTM, (sx, sy)))
        self.path_transform_indices.append(len(self.active_subpath)-1)
Beispiel #9
0
    def scale_ctm(self, sx, sy):
        """ Sets the coordinate system scale to the given values, (sx, sy).

            Parameters
            ----------
            sx : float
                The new scale factor for the x axis
            sy : float
                The new scale factor for the y axis
        """
        self.state.ctm = affine.scale(self.state.ctm, sx, sy)
        self.active_subpath.append((SCALE_CTM, (sx, sy)))
        self.path_transform_indices.append(len(self.active_subpath) - 1)
    def test_transform_point(self):
        pt = array((1, 1))
        ctm = affine.affine_identity()
        ctm = affine.translate(ctm, 5, 5)
        new_pt = affine.transform_point(ctm, pt)
        assert (alltrue(new_pt == array((6, 6))))

        ctm = affine.rotate(ctm, pi)
        new_pt = affine.transform_point(ctm, pt)
        assert (sum(new_pt - array((4., 4.))) < 1e-15)

        ctm = affine.scale(ctm, 10, 10)
        new_pt = affine.transform_point(ctm, pt)
        assert (sum(new_pt - array((-5., -5.))) < 1e-15)
Beispiel #11
0
    def test_transform_point(self):
        pt = array((1,1))
        ctm = affine.affine_identity()
        ctm = affine.translate(ctm,5,5)
        new_pt = affine.transform_point(ctm, pt)
        assert(alltrue(new_pt == array((6,6))))

        ctm = affine.rotate(ctm,pi)
        new_pt = affine.transform_point(ctm, pt)
        assert(sum(new_pt - array((4.,4.))) < 1e-15)

        ctm = affine.scale(ctm,10,10)
        new_pt = affine.transform_point(ctm, pt)
        assert(sum(new_pt - array((-5.,-5.))) < 1e-15)
    def test_transform_points(self):
        # not that thorough...
        pt = array(((1, 1), ))
        ctm = affine.affine_identity()
        ctm = affine.translate(ctm, 5, 5)
        new_pt = affine.transform_points(ctm, pt)
        assert (alltrue(new_pt[0] == array((6, 6))))

        ctm = affine.rotate(ctm, pi)
        new_pt = affine.transform_points(ctm, pt)
        assert (sum(new_pt[0] - array((4., 4.))) < 1e-15)

        ctm = affine.scale(ctm, 10, 10)
        new_pt = affine.transform_points(ctm, pt)
        assert (sum(new_pt[0] - array((-5., -5.))) < 1e-15)
Beispiel #13
0
    def test_transform_points(self):
        # not that thorough...
        pt = array(((1,1),))
        ctm = affine.affine_identity()
        ctm = affine.translate(ctm,5,5)
        new_pt = affine.transform_points(ctm, pt)
        assert(alltrue(new_pt[0] == array((6,6))))

        ctm = affine.rotate(ctm,pi)
        new_pt = affine.transform_points(ctm, pt)
        assert(sum(new_pt[0] - array((4.,4.))) < 1e-15)

        ctm = affine.scale(ctm,10,10)
        new_pt = affine.transform_points(ctm, pt)
        assert(sum(new_pt[0] - array((-5.,-5.))) < 1e-15)
Beispiel #14
0
    def device_transform_device_ctm(self, func, args):
        """ Default implementation for handling scaling matrices.

            Many implementations will just use this function.  Others, like
            OpenGL, can benefit from overriding the method and using
            hardware acceleration.
        """
        if func == SCALE_CTM:
            self.device_ctm = affine.scale(self.device_ctm, args[0], args[1])
        elif func == ROTATE_CTM:
            self.device_ctm = affine.rotate(self.device_ctm, args[0])
        elif func == TRANSLATE_CTM:
            self.device_ctm = affine.translate(self.device_ctm, args[0],
                                               args[1])
        elif func == CONCAT_CTM:
            self.device_ctm = affine.concat(self.device_ctm, args[0])
        elif func == LOAD_CTM:
            self.device_ctm = args[0].copy()
Beispiel #15
0
    def get_event_transform(self, event=None, suffix=""):
        transform = affine.affine_identity()

        if isinstance(self.component, Component):
            # If we have zoom enabled, scale events.  Since affine transforms
            # multiply from the left, we build up the transform from the
            # inside of the viewport outwards.
            if self.enable_zoom and self.zoom != 1.0:
                transform = affine.translate(transform, *self.view_position)
                transform = affine.scale(transform, 1/self.zoom, 1/self.zoom)
                transform = affine.translate(transform, -self.outer_position[0],
                                                        -self.outer_position[1])
            else:
                x_offset = self.view_position[0] - self.outer_position[0]
                y_offset = self.view_position[1] - self.outer_position[1]
                transform = affine.translate(transform, x_offset, y_offset)

        return transform
Beispiel #16
0
    def device_transform_device_ctm(self, func, args):
        """ Default implementation for handling scaling matrices.

            Many implementations will just use this function.  Others, like
            OpenGL, can benefit from overriding the method and using
            hardware acceleration.
        """
        if func == SCALE_CTM:
            self.device_ctm = affine.scale(self.device_ctm, args[0], args[1])
        elif func == ROTATE_CTM:
            self.device_ctm = affine.rotate(self.device_ctm, args[0])
        elif func == TRANSLATE_CTM:
            self.device_ctm = affine.translate(self.device_ctm, args[0],
                                               args[1])
        elif func == CONCAT_CTM:
            self.device_ctm = affine.concat(self.device_ctm, args[0])
        elif func == LOAD_CTM:
            self.device_ctm = args[0].copy()
Beispiel #17
0
    def get_event_transform(self, event=None, suffix=""):
        transform = affine.affine_identity()

        if isinstance(self.component, Component):
            # If we have zoom enabled, scale events.  Since affine transforms
            # multiply from the left, we build up the transform from the
            # inside of the viewport outwards.
            if self.enable_zoom and self.zoom != 1.0:
                transform = affine.translate(transform, *self.view_position)
                transform = affine.scale(transform, 1 / self.zoom,
                                         1 / self.zoom)
                transform = affine.translate(transform,
                                             -self.outer_position[0],
                                             -self.outer_position[1])
            else:
                x_offset = self.view_position[0] - self.outer_position[0]
                y_offset = self.view_position[1] - self.outer_position[1]
                transform = affine.translate(transform, x_offset, y_offset)

        return transform