added more options to split and break bezier at t extension
This commit is contained in:
parent
e1daf4c934
commit
efa6cca11c
@ -19,6 +19,9 @@
|
|||||||
</param>
|
</param>
|
||||||
<param name="target_length" type="float" min="0.0" precision="4" gui-text="Length">0.5000</param>
|
<param name="target_length" type="float" min="0.0" precision="4" gui-text="Length">0.5000</param>
|
||||||
<param name="target_t" type="float" min="0.0000" max="1.0000" precision="4" appearance="full" gui-text="t">0.5000</param>
|
<param name="target_t" type="float" min="0.0000" max="1.0000" precision="4" appearance="full" gui-text="t">0.5000</param>
|
||||||
|
<param name="keep_start" type="bool" gui-text="Keep start">true</param>
|
||||||
|
<param name="keep_end" type="bool" gui-text="Keep end">true</param>
|
||||||
|
<param name="keep_seg" type="bool" gui-text="Keep only segment where trim applies">false</param>
|
||||||
</page>
|
</page>
|
||||||
<page name="tab_about" gui-text="About">
|
<page name="tab_about" gui-text="About">
|
||||||
<label appearance="header">Split And Break Bezier At t</label>
|
<label appearance="header">Split And Break Bezier At t</label>
|
||||||
|
@ -57,6 +57,9 @@ class SplitAndBreakBezierAtT(inkex.EffectExtension):
|
|||||||
pars.add_argument('--unit', default="mm")
|
pars.add_argument('--unit', default="mm")
|
||||||
pars.add_argument('--target_length', type=float, default=0.5)
|
pars.add_argument('--target_length', type=float, default=0.5)
|
||||||
pars.add_argument('--target_t', type=float, default=0.5)
|
pars.add_argument('--target_t', type=float, default=0.5)
|
||||||
|
pars.add_argument('--keep_start', type=inkex.Boolean, default=True)
|
||||||
|
pars.add_argument('--keep_end', type=inkex.Boolean, default=True)
|
||||||
|
pars.add_argument('--keep_seg', type=inkex.Boolean, default=False)
|
||||||
|
|
||||||
def effect(self):
|
def effect(self):
|
||||||
breakApartElements = None
|
breakApartElements = None
|
||||||
@ -80,11 +83,13 @@ class SplitAndBreakBezierAtT(inkex.EffectExtension):
|
|||||||
self.options.target_t = length_at_target_t / totalLength #override
|
self.options.target_t = length_at_target_t / totalLength #override
|
||||||
|
|
||||||
new = []
|
new = []
|
||||||
|
keep = [] #some copy for the segment where the split applies
|
||||||
lengthSum = 0
|
lengthSum = 0
|
||||||
segOfTOccurence = None
|
segOfTOccurence = None
|
||||||
for seg in csp:
|
for seg in csp:
|
||||||
new.append([seg[0][:]])
|
new.append([seg[0][:]])
|
||||||
for i in range(1,len(seg)):
|
for i in range(1,len(seg)):
|
||||||
|
aSeg = seg[i][0]
|
||||||
segLength = bezier.cspseglength(new[-1][-1], seg[i])
|
segLength = bezier.cspseglength(new[-1][-1], seg[i])
|
||||||
lengthSum += segLength
|
lengthSum += segLength
|
||||||
current_t = lengthSum / totalLength
|
current_t = lengthSum / totalLength
|
||||||
@ -97,17 +102,46 @@ class SplitAndBreakBezierAtT(inkex.EffectExtension):
|
|||||||
better_result = [[list(el) for el in elements] for elements in result]
|
better_result = [[list(el) for el in elements] for elements in result]
|
||||||
new[-1][-1], nxt, seg[i] = better_result
|
new[-1][-1], nxt, seg[i] = better_result
|
||||||
new[-1].append(nxt[:])
|
new[-1].append(nxt[:])
|
||||||
new[-1].append(seg[i])
|
if self.options.keep_start is True and self.options.keep_end is False:
|
||||||
newpath = CubicSuperPath(new).to_path(curves_only=True).to_arrays()
|
if segOfTOccurence == 1:
|
||||||
#insert the splitting at the occurence (we add "m 0,0") to break the path
|
keep.append([seg[i-1][0], seg[i-1][0], seg[i-1][0]])
|
||||||
newpath.insert(segOfTOccurence + 1, ['m', [0, 0]])
|
else:
|
||||||
element.path = Path(newpath)
|
keep.append([seg[i-1][1], seg[i-1][1], seg[i-1][1]])
|
||||||
breakAparts = self.breakContours(element)
|
keep.append([better_result[0][2], nxt[0], nxt[1]])
|
||||||
|
elif self.options.keep_start is False and self.options.keep_end is True:
|
||||||
|
keep.append([better_result[0][2], nxt[0], nxt[1]])
|
||||||
|
keep.append([better_result[1][2], better_result[2][0], seg[i][1]])
|
||||||
|
elif self.options.keep_start is True and self.options.keep_end is True:
|
||||||
|
if segOfTOccurence == 1:
|
||||||
|
keep.append([seg[i-1][0], seg[i-1][0], seg[i-1][0]])
|
||||||
|
else:
|
||||||
|
keep.append([seg[i-1][1], seg[i-1][1], seg[i-1][1]])
|
||||||
|
keep.append([seg[i-1][2], aSeg, seg[i][1]])
|
||||||
|
|
||||||
|
new[-1].append(seg[i])
|
||||||
|
|
||||||
#print the breaking point coordinate
|
if self.options.keep_seg is False:
|
||||||
#for step, (x, y) in enumerate(breakAparts[1].path.end_points):
|
newpath = CubicSuperPath(new).to_path(curves_only=True).to_arrays()
|
||||||
# self.msg("x={},y={}".format(x, y))
|
#insert the splitting at the occurence (we add "m 0,0") to break the path
|
||||||
# break
|
newpath.insert(segOfTOccurence + 1, ['m', [0, 0]])
|
||||||
|
element.path = Path(newpath)
|
||||||
|
|
||||||
|
breakAparts = self.breakContours(element)
|
||||||
|
|
||||||
|
pathStart = breakAparts[0]
|
||||||
|
pathEnd = breakAparts[1]
|
||||||
|
if self.options.keep_start is False:
|
||||||
|
pathStart.delete()
|
||||||
|
if self.options.keep_end is False:
|
||||||
|
pathEnd.delete()
|
||||||
|
|
||||||
|
else:
|
||||||
|
element.path = CubicSuperPath(keep)
|
||||||
|
|
||||||
|
#print the breaking point coordinate
|
||||||
|
#for step, (x, y) in enumerate(breakAparts[1].path.end_points):
|
||||||
|
# self.msg("x={},y={}".format(x, y))
|
||||||
|
# break
|
||||||
else:
|
else:
|
||||||
inkex.utils.debug("Selection seems to be empty!")
|
inkex.utils.debug("Selection seems to be empty!")
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user