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.
This commit is contained in:
parent
9e49151ebf
commit
08fc009cba
1 changed files with 22 additions and 3 deletions
25
scour.py
25
scour.py
|
|
@ -2413,6 +2413,13 @@ def optimizeTransform(transform):
|
||||||
and len(prevArgs) == len(currArgs) == 1):
|
and len(prevArgs) == len(currArgs) == 1):
|
||||||
# Only coalesce if both rotations are from the origin.
|
# Only coalesce if both rotations are from the origin.
|
||||||
prevArgs[0] += currArgs[0] # angle
|
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]
|
del transform[i]
|
||||||
elif currType == prevType == 'scale':
|
elif currType == prevType == 'scale':
|
||||||
prevArgs[0] *= currArgs[0] # x
|
prevArgs[0] *= currArgs[0] # x
|
||||||
|
|
@ -2431,10 +2438,22 @@ def optimizeTransform(transform):
|
||||||
# Identity scale!
|
# Identity scale!
|
||||||
i -= 1
|
i -= 1
|
||||||
del transform[i]
|
del transform[i]
|
||||||
elif ((currType == 'skewX' or currType == 'skewY')
|
else:
|
||||||
and len(currArgs) == 1 and currArgs[0] == 0):
|
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!
|
# Identity skew!
|
||||||
i -= 1
|
del transform[i]
|
||||||
|
elif ((currType == 'rotate')
|
||||||
|
and len(currArgs) == 1 and currArgs[0] == 0):
|
||||||
|
# Identity rotation!
|
||||||
del transform[i]
|
del transform[i]
|
||||||
else:
|
else:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue