def __init__(self): # Line state default values. line_color = array((0.0, 0.0, 0.0, 1.0)) line_width = 1 line_cap = CAP_ROUND line_join = JOIN_MITER line_dash = (0, array([0])) # This will draw a solid line # FIXME: This is a very wierd class. The following code is here to # make the basecore2d and the PS, SVG context managers happy super(GraphicsState, self).__init__( line_color, line_width, line_cap, line_join, line_dash) self.line_state = self # All other default values. self.ctm = affine.affine_identity() self.fill_color = array((0.0, 0.0, 0.0, 1.0)) self.alpha = 1.0 self.font = Font() self.text_matrix = affine.affine_identity() self.clipping_path = None # Not sure what the default should be? # Technically uninitialized in the PDF spec, but 0,0 seems fine to me: self.current_point = array((0, 0), dtype=float64) self.antialias = True self.miter_limit = 1.0 self.flatness = 1.0 self.character_spacing = 0.0 self.text_drawing_mode = TEXT_FILL self.alpha = 1.0
def __init__(self): # Line state default values. line_color = array((0.0, 0.0, 0.0, 1.0)) line_width = 1 line_cap = CAP_ROUND line_join = JOIN_MITER line_dash = (0, array([0])) # This will draw a solid line # FIXME: This is a very wierd class. The following code is here to # make the basecore2d and the PS, SVG context managers happy super(GraphicsState, self).__init__(line_color, line_width, line_cap, line_join, line_dash) self.line_state = self # All other default values. self.ctm = affine.affine_identity() self.fill_color = array((0.0, 0.0, 0.0, 1.0)) self.alpha = 1.0 self.font = Font() self.text_matrix = affine.affine_identity() self.clipping_path = None # Not sure what the default should be? # Technically uninitialized in the PDF spec, but 0,0 seems fine to me: self.current_point = array((0, 0), dtype=float64) self.antialias = True self.miter_limit = 1.0 self.flatness = 1.0 self.character_spacing = 0.0 self.text_drawing_mode = TEXT_FILL self.alpha = 1.0
def test_rotate_ctm(self): gc = basecore2d.GraphicsContextBase() ident = affine.affine_identity() angle = 2.0 desired = affine.rotate(ident, angle) gc.rotate_ctm(angle) actual = gc.get_ctm() self.assertTrue(alltrue(ravel(actual == desired)))
def test_translate_ctm(self): gc = basecore2d.GraphicsContextBase() ident = affine.affine_identity() x, y = 2.0, 3.0 desired = affine.translate(ident, x, y) gc.translate_ctm(x, y) actual = gc.get_ctm() self.assertTrue(alltrue(ravel(actual == desired)))
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))
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)))
def test_rotate_ctm(self): gc = basecore2d.GraphicsContextBase() ident = affine.affine_identity() angle = 2. desired = affine.rotate(ident, angle) gc.rotate_ctm(angle) actual = gc.get_ctm() self.assert_(alltrue(ravel(actual == desired)))
def test_translate_ctm(self): gc = basecore2d.GraphicsContextBase() ident = affine.affine_identity() x, y = 2., 3. desired = affine.translate(ident, x, y) gc.translate_ctm(x, y) actual = gc.get_ctm() self.assert_(alltrue(ravel(actual == desired)))
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_concat_ctm(self): gc = basecore2d.GraphicsContextBase() ident = affine.affine_identity() trans = affine.affine_from_rotation(2.0) desired = affine.concat(ident, trans) gc.concat_ctm(trans) actual = gc.get_ctm() self.assertTrue(alltrue(ravel(actual == desired)))
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_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_concat_ctm(self): gc = basecore2d.GraphicsContextBase() ident = affine.affine_identity() trans = affine.affine_from_rotation(2.) x, y = 2., 3. desired = affine.concat(ident, trans) gc.concat_ctm(trans) actual = gc.get_ctm() self.assert_(alltrue(ravel(actual == desired)))
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_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_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 net_transform(self): """ Returns a single transformation (currently only (dx,dy)) that reflects the total amount of change from the original coordinates to the current offset coordinates stored in self.x and self.y. """ if len(self._transform_stack) == 0: return affine.affine_identity() else: return sm.reduce(dot, self._transform_stack[::-1])
def net_transform(self): """ Returns a single transformation (currently only (dx,dy)) that reflects the total amount of change from the original coordinates to the current offset coordinates stored in self.x and self.y. """ if len(self._transform_stack) == 0: return affine.affine_identity() else: return reduce(dot, self._transform_stack[::-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)
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)
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)
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
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
def test_get_ctm(self): gc = basecore2d.GraphicsContextBase() # default ctm should be identity matrix. desired = affine.affine_identity() actual = gc.get_ctm() self.assertTrue(alltrue(ravel(actual == desired)))
def get_event_transform(self, event=None, suffix=""): """ Returns the 3x3 transformation matrix that this interactor will apply to the event (if any). """ return affine_identity()
def device_prepare_device_ctm(self): self.device_ctm = affine.affine_identity()
def test_get_ctm(self): gc = basecore2d.GraphicsContextBase() # default ctm should be identity matrix. desired = affine.affine_identity() actual = gc.get_ctm() self.assert_(alltrue(ravel(actual == desired)))
def test_identity(self): i = affine.affine_identity() self.assertTrue(allclose(identity(3), i))