Fix collapsing of straight "m" path segments: Not only the slope but also the direction needs to be the same!

This commit is contained in:
Eduard Braun 2017-05-17 00:56:09 +02:00
parent 566c9cb6a2
commit f0865ed96f

View file

@ -407,9 +407,12 @@ def is_same_sign(a, b):
return (a <= 0 and b <= 0) or (a >= 0 and b >= 0) return (a <= 0 and b <= 0) or (a >= 0 and b >= 0)
def is_same_slope(x1, y1, x2, y2): def is_same_direction(x1, y1, x2, y2):
diff = y1/x1 - y2/x2 if is_same_sign(x1, x2) and is_same_sign(y1, y2):
return scouringContext.plus(1 + diff) == 1 diff = y1/x1 - y2/x2
return scouringContext.plus(1 + diff) == 1
else:
return False
scinumber = re.compile(r"[-+]?(\d*\.?)?\d+[eE][-+]?\d+") scinumber = re.compile(r"[-+]?(\d*\.?)?\d+[eE][-+]?\d+")
@ -2431,7 +2434,7 @@ def cleanPath(element, options):
elif cmd is 'l' and len(data) >= 4: elif cmd is 'l' and len(data) >= 4:
coordIndex = 0 coordIndex = 0
while coordIndex+2 < len(data): while coordIndex+2 < len(data):
if is_same_slope(*data[coordIndex:coordIndex+4]): if is_same_direction(*data[coordIndex:coordIndex+4]):
data[coordIndex] += data[coordIndex+2] data[coordIndex] += data[coordIndex+2]
data[coordIndex+1] += data[coordIndex+3] data[coordIndex+1] += data[coordIndex+3]
del data[coordIndex+2] # delete the next two elements del data[coordIndex+2] # delete the next two elements
@ -2444,7 +2447,7 @@ def cleanPath(element, options):
elif cmd is 'm' and len(data) >= 6: elif cmd is 'm' and len(data) >= 6:
coordIndex = 2; coordIndex = 2;
while coordIndex+2 < len(data): while coordIndex+2 < len(data):
if is_same_slope(*data[coordIndex:coordIndex+4]): if is_same_direction(*data[coordIndex:coordIndex+4]):
data[coordIndex] += data[coordIndex+2] data[coordIndex] += data[coordIndex+2]
data[coordIndex+1] += data[coordIndex+3] data[coordIndex+1] += data[coordIndex+3]
del data[coordIndex+2] # delete the next two elements del data[coordIndex+2] # delete the next two elements