small fixes

This commit is contained in:
Mario Voigt 2020-08-09 12:56:14 +02:00
parent 7343d5be1b
commit bb3505ed9e
2 changed files with 72 additions and 72 deletions

View File

@ -24,7 +24,7 @@ def warn(*args, **kwargs):
import warnings import warnings
warnings.warn = warn warnings.warn = warn
class TemplateEffect(inkex.Effect): class ExportXY(inkex.Effect):
def __init__(self): def __init__(self):
inkex.Effect.__init__(self) inkex.Effect.__init__(self)
def effect(self): def effect(self):
@ -41,5 +41,4 @@ class TemplateEffect(inkex.Effect):
for csp in subpath: for csp in subpath:
output_nodes += str(csp[1][0]) + "\t" + str(csp[1][1]) + "\n" output_nodes += str(csp[1][0]) + "\t" + str(csp[1][1]) + "\n"
sys.stderr.write(output_nodes) sys.stderr.write(output_nodes)
TemplateEffect().run() ExportXY().run()
sys.exit(0) #helps to keep the selection

View File

@ -94,73 +94,74 @@ class SubdividePathEffect(inkex.Effect):
for key, cspath in paths: for key, cspath in paths:
parts = getPartsFromCubicSuper(cspath) parts = getPartsFromCubicSuper(cspath)
partsSplit = False partsSplit = False
try:
for i, part in enumerate(parts):
for i, part in enumerate(parts): newSegs = []
for j, seg in enumerate(part):
segL = bezier.bezierlength((seg[0], seg[1], seg[2], seg[3]), tolerance = tolerance)
newSegs = [] if(maxL != None):
for j, seg in enumerate(part): divL = maxL
segL = bezier.bezierlength((seg[0], seg[1], seg[2], seg[3]), tolerance = tolerance) elif(self.options.unit == 'perc'):
divL = segL * self.options.maxLength / 100
else:
divL = segL / ceil(self.options.maxLength)
if(maxL != None): if(segL > divL):
divL = maxL
elif(self.options.unit == 'perc'):
divL = segL * self.options.maxLength / 100
else:
divL = segL / ceil(self.options.maxLength)
if(segL > divL): coveredL = 0
s = seg
s1 = None
s2 = DEF_ERR_MARGIN #Just in case
coveredL = 0 while(not floatCmpWithMargin(segL, coveredL)):
s = seg if(s == seg):
s1 = None sL = segL
s2 = DEF_ERR_MARGIN #Just in case
while(not floatCmpWithMargin(segL, coveredL)):
if(s == seg):
sL = segL
else:
sL = bezier.bezierlength((s[0], s[1], s[2], s[3]), tolerance = tolerance)
if(floatCmpWithMargin(segL, coveredL + divL)):
s2 = s
break
else:
if(segL > (coveredL + divL)):
t1L = divL
else: else:
t1L = segL - coveredL sL = bezier.bezierlength((s[0], s[1], s[2], s[3]), tolerance = tolerance)
t1 = bezier.beziertatlength((s[0], s[1], s[2], s[3]), l = t1L / sL , tolerance = tolerance) if(floatCmpWithMargin(segL, coveredL + divL)):
s1, s2 = bezier.beziersplitatt((s[0], s[1], s[2], s[3]), t1) s2 = s
coveredL += t1L break
newSegs.append(s1) else:
s = s2 if(segL > (coveredL + divL)):
newSegs.append(s2) t1L = divL
else:
t1L = segL - coveredL
t1 = bezier.beziertatlength((s[0], s[1], s[2], s[3]), l = t1L / sL , tolerance = tolerance)
s1, s2 = bezier.beziersplitatt((s[0], s[1], s[2], s[3]), t1)
coveredL += t1L
newSegs.append(s1)
s = s2
newSegs.append(s2)
else:
newSegs.append(seg)
if(len(newSegs) > len(part)):
parts[i] = newSegs
partsSplit = True
if(partsSplit or separateSegs):
elem = selections[key]
if(separateSegs):
parent = elem.getparent()
idx = parent.index(elem)
parent.remove(elem)
allSegs = [seg for part in parts for seg in part]
idSuffix = 0
for seg in allSegs:
cspath = getCubicSuperFromParts([[seg]])
newElem = copy.copy(elem)
oldId = newElem.get('id')
newElem.set('d', CubicSuperPath(cspath))
newElem.set('id', oldId + str(idSuffix).zfill(5))
parent.insert(idx, newElem)
idSuffix += 1
else: else:
newSegs.append(seg) cspath = getCubicSuperFromParts(parts)
elem.set('d', CubicSuperPath(cspath))
if(len(newSegs) > len(part)): except:
parts[i] = newSegs pass
partsSplit = True
if(partsSplit or separateSegs):
elem = selections[key]
if(separateSegs):
parent = elem.getparent()
idx = parent.index(elem)
parent.remove(elem)
allSegs = [seg for part in parts for seg in part]
idSuffix = 0
for seg in allSegs:
cspath = getCubicSuperFromParts([[seg]])
newElem = copy.copy(elem)
oldId = newElem.get('id')
newElem.set('d', CubicSuperPath(cspath))
newElem.set('id', oldId + str(idSuffix).zfill(5))
parent.insert(idx, newElem)
idSuffix += 1
else:
cspath = getCubicSuperFromParts(parts)
elem.set('d', CubicSuperPath(cspath))
SubdividePathEffect().run() SubdividePathEffect().run()