## [PyX-checkins] commit 3572: trunk/pyx/pyx/trafo.py: remove invalid trafos

 [PyX-checkins] commit 3572: trunk/pyx/pyx/trafo.py: remove invalid trafos From: - 2013-12-19 21:09:51 ```Revision: 3572 https://sourceforge.net/p/pyx/code/3572/ Author: wobsta Date: 2013-12-19 21:09:47 +0000 (Thu, 19 Dec 2013) Log Message: ----------- remove invalid trafos Modified Paths: -------------- trunk/pyx/pyx/trafo.py Modified: trunk/pyx/pyx/trafo.py =================================================================== --- trunk/pyx/pyx/trafo.py 2013-12-19 21:09:28 UTC (rev 3571) +++ trunk/pyx/pyx/trafo.py 2013-12-19 21:09:47 UTC (rev 3572) @@ -23,15 +23,6 @@ import math from . import attr, baseclasses, unit -# global epsilon (used to judge whether a matrix is singular) -_epsilon = (1e-5)**2 - -def set(epsilon=None): - global _epsilon - if epsilon is not None: - _epsilon = epsilon - - # some helper routines def _rmatrix(angle): @@ -55,13 +46,7 @@ (-2*math.sin(phi)*math.cos(phi), math.sin(phi)*math.sin(phi)-math.cos(phi)*math.cos(phi) ) ) -class _marker: pass -# Exception - -class TrafoException(Exception): - pass - # trafo: affine transformations class trafo_pt(baseclasses.deformer): @@ -74,29 +59,14 @@ """ - def __init__(self, matrix=((1, 0), (0, 1)), vector=(0, 0), epsilon=_marker): - """Return trafo with given transformation matrix and vector. If epsilon - is passed it is used instead of the global epsilon defined in the module to - check whether the matrix is singular or not. Use epsilon=None to turn of this - checking. + def __init__(self, matrix=((1, 0), (0, 1)), vector=(0, 0)): + """Return trafo with given transformation matrix and vector. """ - if epsilon is _marker: - epsilon = _epsilon - self.epsilon = epsilon - if epsilon is not None and abs(matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]) < epsilon: - raise TrafoException("transformation matrix must not be singular") - else: - self.matrix = matrix + self.matrix = matrix self.vector = vector def __mul__(self, other): if isinstance(other, trafo_pt): - if self.epsilon is None or other.epsilon is None: - epsilon = None - elif self.epsilon <= other.epsilon: - epsilon = self.epsilon - else: - epsilon = other.epsilon matrix = ( ( self.matrix[0][0]*other.matrix[0][0] + self.matrix[0][1]*other.matrix[1][0], self.matrix[0][0]*other.matrix[0][1] + @@ -114,7 +84,7 @@ self.matrix[1][1]*other.vector[1] + self.vector[1] ) - return trafo_pt(matrix=matrix, vector=vector, epsilon=epsilon) + return trafo_pt(matrix=matrix, vector=vector) else: raise NotImplementedError("can only multiply two transformations") @@ -153,45 +123,44 @@ det = 1.0*(self.matrix[0][0]*self.matrix[1][1] - self.matrix[0][1]*self.matrix[1][0]) matrix = ( ( self.matrix[1][1]/det, -self.matrix[0][1]/det), (-self.matrix[1][0]/det, self.matrix[0][0]/det) ) - return ( trafo_pt(matrix=matrix, epsilon=self.epsilon) * - trafo_pt(vector=(-self.vector[0], -self.vector[1]), epsilon=self.epsilon) ) + return ( trafo_pt(matrix=matrix) * + trafo_pt(vector=(-self.vector[0], -self.vector[1])) ) def mirrored(self, angle): - return mirror(angle, epsilon=self.epsilon) * self + return mirror(angle) * self def rotated_pt(self, angle, x=None, y=None): - return rotate_pt(angle, x, y, epsilon=self.epsilon) * self + return rotate_pt(angle, x, y) * self def rotated(self, angle, x=None, y=None): - return rotate(angle, x, y, epsilon=self.epsilon) * self + return rotate(angle, x, y) * self def scaled_pt(self, sx, sy=None, x=None, y=None): - return scale_pt(sx, sy, x, y, epsilon=self.epsilon) * self + return scale_pt(sx, sy, x, y) * self def scaled(self, sx, sy=None, x=None, y=None): - return scale(sx, sy, x, y, epsilon=self.epsilon) * self + return scale(sx, sy, x, y) * self def slanted_pt(self, a, angle=0, x=None, y=None): - return slant_pt(a, angle, x, y, epsilon=self.epsilon) * self + return slant_pt(a, angle, x, y) * self def slanted(self, a, angle=0, x=None, y=None): - return slant(a, angle, x, y, epsilon=self.epsilon) * self + return slant(a, angle, x, y) * self def translated_pt(self, x, y): - return translate_pt(x, y, epsilon=self.epsilon) * self + return translate_pt(x, y) * self def translated(self, x, y): - return translate(x, y, epsilon=self.epsilon) * self + return translate(x, y) * self class trafo(trafo_pt): """affine transformation""" - def __init__(self, matrix=((1,0), (0,1)), vector=(0, 0), epsilon=_marker): + def __init__(self, matrix=((1,0), (0,1)), vector=(0, 0)): trafo_pt.__init__(self, - matrix, (unit.topt(vector[0]), unit.topt(vector[1])), - epsilon=epsilon) + matrix, (unit.topt(vector[0]), unit.topt(vector[1]))) # # some standard transformations @@ -200,34 +169,34 @@ identity = trafo() class mirror(trafo): - def __init__(self, angle=0, epsilon=_marker): - trafo.__init__(self, matrix=_mmatrix(angle), epsilon=epsilon) + def __init__(self, angle=0): + trafo.__init__(self, matrix=_mmatrix(angle)) class rotate_pt(trafo_pt): - def __init__(self, angle, x=None, y=None, epsilon=_marker): + def __init__(self, angle, x=None, y=None): vector = 0, 0 if x is not None or y is not None: if x is None or y is None: raise TrafoException("either specify both x and y or none of them") vector=_rvector(angle, x, y) - trafo_pt.__init__(self, matrix=_rmatrix(angle), vector=vector, epsilon=epsilon) + trafo_pt.__init__(self, matrix=_rmatrix(angle), vector=vector) class rotate(trafo_pt): - def __init__(self, angle, x=None, y=None, epsilon=_marker): + def __init__(self, angle, x=None, y=None): vector = 0, 0 if x is not None or y is not None: if x is None or y is None: raise TrafoException("either specify both x and y or none of them") vector=_rvector(angle, unit.topt(x), unit.topt(y)) - trafo_pt.__init__(self, matrix=_rmatrix(angle), vector=vector, epsilon=epsilon) + trafo_pt.__init__(self, matrix=_rmatrix(angle), vector=vector) class scale_pt(trafo_pt): - def __init__(self, sx, sy=None, x=None, y=None, epsilon=_marker): + def __init__(self, sx, sy=None, x=None, y=None): if sy is None: sy = sx vector = 0, 0 @@ -235,11 +204,11 @@ if x is None or y is None: raise TrafoException("either specify both x and y or none of them") vector = (1-sx)*x, (1-sy)*y - trafo_pt.__init__(self, matrix=((sx, 0), (0, sy)), vector=vector, epsilon=epsilon) + trafo_pt.__init__(self, matrix=((sx, 0), (0, sy)), vector=vector) class scale(trafo): - def __init__(self, sx, sy=None, x=None, y=None, epsilon=_marker): + def __init__(self, sx, sy=None, x=None, y=None): if sy is None: sy = sx vector = 0, 0 @@ -247,30 +216,30 @@ if x is None or y is None: raise TrafoException("either specify both x and y or none of them") vector = (1-sx)*x, (1-sy)*y - trafo.__init__(self, matrix=((sx, 0), (0, sy)), vector=vector, epsilon=epsilon) + trafo.__init__(self, matrix=((sx, 0), (0, sy)), vector=vector) class slant_pt(trafo_pt): - def __init__(self, a, angle=0, x=None, y=None, epsilon=_marker): - t = ( rotate_pt(-angle, x, y, epsilon=epsilon) * - trafo(matrix=((1, a), (0, 1)), epsilon=epsilon) * - rotate_pt(angle, x, y, epsilon=epsilon) ) - trafo_pt.__init__(self, t.matrix, t.vector, epsilon=epsilon) + def __init__(self, a, angle=0, x=None, y=None): + t = ( rotate_pt(-angle, x, y) * + trafo(matrix=((1, a), (0, 1))) * + rotate_pt(angle, x, y) ) + trafo_pt.__init__(self, t.matrix, t.vector) class slant(trafo): - def __init__(self, a, angle=0, x=None, y=None, epsilon=_marker): - t = ( rotate(-angle, x, y, epsilon=epsilon) * - trafo(matrix=((1, a), (0, 1)), epsilon=epsilon) * - rotate(angle, x, y, epsilon=epsilon) ) - trafo.__init__(self, t.matrix, t.vector, epsilon=epsilon) + def __init__(self, a, angle=0, x=None, y=None): + t = ( rotate(-angle, x, y) * + trafo(matrix=((1, a), (0, 1))) * + rotate(angle, x, y) ) + trafo.__init__(self, t.matrix, t.vector) class translate_pt(trafo_pt): - def __init__(self, x, y, epsilon=_marker): - trafo_pt.__init__(self, vector=(x, y), epsilon=epsilon) + def __init__(self, x, y): + trafo_pt.__init__(self, vector=(x, y)) class translate(trafo): - def __init__(self, x, y, epsilon=_marker): - trafo.__init__(self, vector=(x, y), epsilon=epsilon) + def __init__(self, x, y): + trafo.__init__(self, vector=(x, y)) ```

 [PyX-checkins] commit 3572: trunk/pyx/pyx/trafo.py: remove invalid trafos From: - 2013-12-19 21:09:51 ```Revision: 3572 https://sourceforge.net/p/pyx/code/3572/ Author: wobsta Date: 2013-12-19 21:09:47 +0000 (Thu, 19 Dec 2013) Log Message: ----------- remove invalid trafos Modified Paths: -------------- trunk/pyx/pyx/trafo.py Modified: trunk/pyx/pyx/trafo.py =================================================================== --- trunk/pyx/pyx/trafo.py 2013-12-19 21:09:28 UTC (rev 3571) +++ trunk/pyx/pyx/trafo.py 2013-12-19 21:09:47 UTC (rev 3572) @@ -23,15 +23,6 @@ import math from . import attr, baseclasses, unit -# global epsilon (used to judge whether a matrix is singular) -_epsilon = (1e-5)**2 - -def set(epsilon=None): - global _epsilon - if epsilon is not None: - _epsilon = epsilon - - # some helper routines def _rmatrix(angle): @@ -55,13 +46,7 @@ (-2*math.sin(phi)*math.cos(phi), math.sin(phi)*math.sin(phi)-math.cos(phi)*math.cos(phi) ) ) -class _marker: pass -# Exception - -class TrafoException(Exception): - pass - # trafo: affine transformations class trafo_pt(baseclasses.deformer): @@ -74,29 +59,14 @@ """ - def __init__(self, matrix=((1, 0), (0, 1)), vector=(0, 0), epsilon=_marker): - """Return trafo with given transformation matrix and vector. If epsilon - is passed it is used instead of the global epsilon defined in the module to - check whether the matrix is singular or not. Use epsilon=None to turn of this - checking. + def __init__(self, matrix=((1, 0), (0, 1)), vector=(0, 0)): + """Return trafo with given transformation matrix and vector. """ - if epsilon is _marker: - epsilon = _epsilon - self.epsilon = epsilon - if epsilon is not None and abs(matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]) < epsilon: - raise TrafoException("transformation matrix must not be singular") - else: - self.matrix = matrix + self.matrix = matrix self.vector = vector def __mul__(self, other): if isinstance(other, trafo_pt): - if self.epsilon is None or other.epsilon is None: - epsilon = None - elif self.epsilon <= other.epsilon: - epsilon = self.epsilon - else: - epsilon = other.epsilon matrix = ( ( self.matrix[0][0]*other.matrix[0][0] + self.matrix[0][1]*other.matrix[1][0], self.matrix[0][0]*other.matrix[0][1] + @@ -114,7 +84,7 @@ self.matrix[1][1]*other.vector[1] + self.vector[1] ) - return trafo_pt(matrix=matrix, vector=vector, epsilon=epsilon) + return trafo_pt(matrix=matrix, vector=vector) else: raise NotImplementedError("can only multiply two transformations") @@ -153,45 +123,44 @@ det = 1.0*(self.matrix[0][0]*self.matrix[1][1] - self.matrix[0][1]*self.matrix[1][0]) matrix = ( ( self.matrix[1][1]/det, -self.matrix[0][1]/det), (-self.matrix[1][0]/det, self.matrix[0][0]/det) ) - return ( trafo_pt(matrix=matrix, epsilon=self.epsilon) * - trafo_pt(vector=(-self.vector[0], -self.vector[1]), epsilon=self.epsilon) ) + return ( trafo_pt(matrix=matrix) * + trafo_pt(vector=(-self.vector[0], -self.vector[1])) ) def mirrored(self, angle): - return mirror(angle, epsilon=self.epsilon) * self + return mirror(angle) * self def rotated_pt(self, angle, x=None, y=None): - return rotate_pt(angle, x, y, epsilon=self.epsilon) * self + return rotate_pt(angle, x, y) * self def rotated(self, angle, x=None, y=None): - return rotate(angle, x, y, epsilon=self.epsilon) * self + return rotate(angle, x, y) * self def scaled_pt(self, sx, sy=None, x=None, y=None): - return scale_pt(sx, sy, x, y, epsilon=self.epsilon) * self + return scale_pt(sx, sy, x, y) * self def scaled(self, sx, sy=None, x=None, y=None): - return scale(sx, sy, x, y, epsilon=self.epsilon) * self + return scale(sx, sy, x, y) * self def slanted_pt(self, a, angle=0, x=None, y=None): - return slant_pt(a, angle, x, y, epsilon=self.epsilon) * self + return slant_pt(a, angle, x, y) * self def slanted(self, a, angle=0, x=None, y=None): - return slant(a, angle, x, y, epsilon=self.epsilon) * self + return slant(a, angle, x, y) * self def translated_pt(self, x, y): - return translate_pt(x, y, epsilon=self.epsilon) * self + return translate_pt(x, y) * self def translated(self, x, y): - return translate(x, y, epsilon=self.epsilon) * self + return translate(x, y) * self class trafo(trafo_pt): """affine transformation""" - def __init__(self, matrix=((1,0), (0,1)), vector=(0, 0), epsilon=_marker): + def __init__(self, matrix=((1,0), (0,1)), vector=(0, 0)): trafo_pt.__init__(self, - matrix, (unit.topt(vector[0]), unit.topt(vector[1])), - epsilon=epsilon) + matrix, (unit.topt(vector[0]), unit.topt(vector[1]))) # # some standard transformations @@ -200,34 +169,34 @@ identity = trafo() class mirror(trafo): - def __init__(self, angle=0, epsilon=_marker): - trafo.__init__(self, matrix=_mmatrix(angle), epsilon=epsilon) + def __init__(self, angle=0): + trafo.__init__(self, matrix=_mmatrix(angle)) class rotate_pt(trafo_pt): - def __init__(self, angle, x=None, y=None, epsilon=_marker): + def __init__(self, angle, x=None, y=None): vector = 0, 0 if x is not None or y is not None: if x is None or y is None: raise TrafoException("either specify both x and y or none of them") vector=_rvector(angle, x, y) - trafo_pt.__init__(self, matrix=_rmatrix(angle), vector=vector, epsilon=epsilon) + trafo_pt.__init__(self, matrix=_rmatrix(angle), vector=vector) class rotate(trafo_pt): - def __init__(self, angle, x=None, y=None, epsilon=_marker): + def __init__(self, angle, x=None, y=None): vector = 0, 0 if x is not None or y is not None: if x is None or y is None: raise TrafoException("either specify both x and y or none of them") vector=_rvector(angle, unit.topt(x), unit.topt(y)) - trafo_pt.__init__(self, matrix=_rmatrix(angle), vector=vector, epsilon=epsilon) + trafo_pt.__init__(self, matrix=_rmatrix(angle), vector=vector) class scale_pt(trafo_pt): - def __init__(self, sx, sy=None, x=None, y=None, epsilon=_marker): + def __init__(self, sx, sy=None, x=None, y=None): if sy is None: sy = sx vector = 0, 0 @@ -235,11 +204,11 @@ if x is None or y is None: raise TrafoException("either specify both x and y or none of them") vector = (1-sx)*x, (1-sy)*y - trafo_pt.__init__(self, matrix=((sx, 0), (0, sy)), vector=vector, epsilon=epsilon) + trafo_pt.__init__(self, matrix=((sx, 0), (0, sy)), vector=vector) class scale(trafo): - def __init__(self, sx, sy=None, x=None, y=None, epsilon=_marker): + def __init__(self, sx, sy=None, x=None, y=None): if sy is None: sy = sx vector = 0, 0 @@ -247,30 +216,30 @@ if x is None or y is None: raise TrafoException("either specify both x and y or none of them") vector = (1-sx)*x, (1-sy)*y - trafo.__init__(self, matrix=((sx, 0), (0, sy)), vector=vector, epsilon=epsilon) + trafo.__init__(self, matrix=((sx, 0), (0, sy)), vector=vector) class slant_pt(trafo_pt): - def __init__(self, a, angle=0, x=None, y=None, epsilon=_marker): - t = ( rotate_pt(-angle, x, y, epsilon=epsilon) * - trafo(matrix=((1, a), (0, 1)), epsilon=epsilon) * - rotate_pt(angle, x, y, epsilon=epsilon) ) - trafo_pt.__init__(self, t.matrix, t.vector, epsilon=epsilon) + def __init__(self, a, angle=0, x=None, y=None): + t = ( rotate_pt(-angle, x, y) * + trafo(matrix=((1, a), (0, 1))) * + rotate_pt(angle, x, y) ) + trafo_pt.__init__(self, t.matrix, t.vector) class slant(trafo): - def __init__(self, a, angle=0, x=None, y=None, epsilon=_marker): - t = ( rotate(-angle, x, y, epsilon=epsilon) * - trafo(matrix=((1, a), (0, 1)), epsilon=epsilon) * - rotate(angle, x, y, epsilon=epsilon) ) - trafo.__init__(self, t.matrix, t.vector, epsilon=epsilon) + def __init__(self, a, angle=0, x=None, y=None): + t = ( rotate(-angle, x, y) * + trafo(matrix=((1, a), (0, 1))) * + rotate(angle, x, y) ) + trafo.__init__(self, t.matrix, t.vector) class translate_pt(trafo_pt): - def __init__(self, x, y, epsilon=_marker): - trafo_pt.__init__(self, vector=(x, y), epsilon=epsilon) + def __init__(self, x, y): + trafo_pt.__init__(self, vector=(x, y)) class translate(trafo): - def __init__(self, x, y, epsilon=_marker): - trafo.__init__(self, vector=(x, y), epsilon=epsilon) + def __init__(self, x, y): + trafo.__init__(self, vector=(x, y)) ```