From 08fc009cba8a556ad98a8e97bc9f79d87b81cc08 Mon Sep 17 00:00:00 2001 From: Louis Simard Date: Sat, 12 Mar 2011 03:51:04 -0500 Subject: [PATCH] Add a modulo 360 for coalesced rotate() transformation angles. This allows rotate(-300) rotate(-60) from the unit test to be correctly made into rotate(0). Allow skewX(0), skewY(0) and rotate(0) to be deleted in 1-transformation lists. All unit tests pass now. --- scour.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/scour.py b/scour.py index de5d04c..7ff2a16 100755 --- a/scour.py +++ b/scour.py @@ -2413,6 +2413,13 @@ def optimizeTransform(transform): and len(prevArgs) == len(currArgs) == 1): # Only coalesce if both rotations are from the origin. prevArgs[0] += currArgs[0] # angle + # Put the new angle in the range ]-360, 360[. + # The modulo operator yields results with the sign of the + # divisor, so for negative dividends, we preserve the sign + # of the angle. + if prevArgs[0] < 0: prevArgs[0] = prevArgs[0] % -360 + else: prevArgs[0] = prevArgs[0] % 360 + del transform[i] elif currType == prevType == 'scale': prevArgs[0] *= currArgs[0] # x @@ -2431,10 +2438,22 @@ def optimizeTransform(transform): # Identity scale! i -= 1 del transform[i] - elif ((currType == 'skewX' or currType == 'skewY') - and len(currArgs) == 1 and currArgs[0] == 0): + else: + i += 1 + + # Some fixups are needed for single-element transformation lists, since + # the loop above was to coalesce elements with their predecessors in the + # list, and thus it required 2 elements. + i = 0 + while i < len(transform): + currType, currArgs = transform[i] + if ((currType == 'skewX' or currType == 'skewY') + and len(currArgs) == 1 and currArgs[0] == 0): # Identity skew! - i -= 1 + del transform[i] + elif ((currType == 'rotate') + and len(currArgs) == 1 and currArgs[0] == 0): + # Identity rotation! del transform[i] else: i += 1