small fixes
This commit is contained in:
parent
7343d5be1b
commit
bb3505ed9e
@ -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
|
|
@ -93,74 +93,75 @@ class SubdividePathEffect(inkex.Effect):
|
|||||||
if(len(paths) > 0):
|
if(len(paths) > 0):
|
||||||
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)
|
|
||||||
|
|
||||||
if(maxL != None):
|
|
||||||
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
|
|
||||||
|
|
||||||
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:
|
|
||||||
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:
|
|
||||||
cspath = getCubicSuperFromParts(parts)
|
|
||||||
elem.set('d', CubicSuperPath(cspath))
|
|
||||||
|
|
||||||
|
newSegs = []
|
||||||
|
for j, seg in enumerate(part):
|
||||||
|
segL = bezier.bezierlength((seg[0], seg[1], seg[2], seg[3]), tolerance = tolerance)
|
||||||
|
|
||||||
|
if(maxL != None):
|
||||||
|
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
|
||||||
|
|
||||||
|
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:
|
||||||
|
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:
|
||||||
|
cspath = getCubicSuperFromParts(parts)
|
||||||
|
elem.set('d', CubicSuperPath(cspath))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
SubdividePathEffect().run()
|
SubdividePathEffect().run()
|
Reference in New Issue
Block a user