Added units to offset paths + some tweaks/better default
This commit is contained in:
parent
8b88223c61
commit
01b2b46411
@ -2,6 +2,14 @@
|
|||||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
<name>Ofsplot (Offset Paths)</name>
|
<name>Ofsplot (Offset Paths)</name>
|
||||||
<id>fablabchemnitz.de.ofsplot</id>
|
<id>fablabchemnitz.de.ofsplot</id>
|
||||||
|
<param name="unit" type="optiongroup" appearance="combo" gui-text="Unit">
|
||||||
|
<option value="mm">mm</option>
|
||||||
|
<option value="cm">cm</option>
|
||||||
|
<option value="in">in</option>
|
||||||
|
<option value="pt">pt</option>
|
||||||
|
<option value="px">px</option>
|
||||||
|
<option value="pc">pc</option>
|
||||||
|
</param>
|
||||||
<param name="offset_count" type="int" min="1" max="100000" gui-text="Number of offset paths:">1</param>
|
<param name="offset_count" type="int" min="1" max="100000" gui-text="Number of offset paths:">1</param>
|
||||||
<param name="offset" type="float" precision="4" min="-1000" max="+1000" gui-text="Offset between two paths:">1.0000</param>
|
<param name="offset" type="float" precision="4" min="-1000" max="+1000" gui-text="Offset between two paths:">1.0000</param>
|
||||||
<param name="init_offset" type="float" precision="4" min="-1000" max="+1000" gui-text="Initial offset from original path:">1.0000</param>
|
<param name="init_offset" type="float" precision="4" min="-1000" max="+1000" gui-text="Initial offset from original path:">1.0000</param>
|
||||||
|
@ -9,6 +9,7 @@ import pyclipper
|
|||||||
class ofsplot(inkex.Effect):
|
class ofsplot(inkex.Effect):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
inkex.Effect.__init__(self)
|
inkex.Effect.__init__(self)
|
||||||
|
self.arg_parser.add_argument('--unit')
|
||||||
self.arg_parser.add_argument("--offset_count", type=int, default=1, help="Number of offset paths")
|
self.arg_parser.add_argument("--offset_count", type=int, default=1, help="Number of offset paths")
|
||||||
self.arg_parser.add_argument("--offset", type=float, default=1.000, help="Offset amount")
|
self.arg_parser.add_argument("--offset", type=float, default=1.000, help="Offset amount")
|
||||||
self.arg_parser.add_argument("--init_offset", type=float, default=0.000, help="Initial Offset Amount")
|
self.arg_parser.add_argument("--init_offset", type=float, default=0.000, help="Initial Offset Amount")
|
||||||
@ -19,6 +20,7 @@ class ofsplot(inkex.Effect):
|
|||||||
self.arg_parser.add_argument("--clipperscale", type=float, default=1024.0, help="Scaling factor")
|
self.arg_parser.add_argument("--clipperscale", type=float, default=1024.0, help="Scaling factor")
|
||||||
|
|
||||||
def effect(self):
|
def effect(self):
|
||||||
|
unit_factor = 1.0 / self.svg.uutounit(1.0,self.options.unit)
|
||||||
paths = self.svg.selection.filter(inkex.PathElement).values()
|
paths = self.svg.selection.filter(inkex.PathElement).values()
|
||||||
count = sum(1 for path in paths)
|
count = sum(1 for path in paths)
|
||||||
paths = self.svg.selection.filter(inkex.PathElement).values() #we need to call this twice because the sum function consumes the generator
|
paths = self.svg.selection.filter(inkex.PathElement).values() #we need to call this twice because the sum function consumes the generator
|
||||||
@ -52,12 +54,12 @@ class ofsplot(inkex.Effect):
|
|||||||
|
|
||||||
# calculate offset paths for different offset amounts
|
# calculate offset paths for different offset amounts
|
||||||
offset_list = []
|
offset_list = []
|
||||||
offset_list.append(self.options.init_offset)
|
offset_list.append(self.options.init_offset * unit_factor)
|
||||||
for i in range(0, self.options.offset_count):
|
for i in range(0, self.options.offset_count):
|
||||||
ofs_inc = +math.pow(float(i)*self.options.offset_increase,2)
|
ofs_increase = +math.pow(float(i) * self.options.offset_increase * unit_factor, 2)
|
||||||
if self.options.offset_increase < 0:
|
if self.options.offset_increase < 0:
|
||||||
ofs_inc = -ofs_inc
|
ofs_increase = -ofs_increase
|
||||||
offset_list.append(offset_list[0]+float(i)*self.options.offset+ofs_inc)
|
offset_list.append(offset_list[0] + float(i) * self.options.offset * unit_factor + ofs_increase * unit_factor)
|
||||||
|
|
||||||
solutions = []
|
solutions = []
|
||||||
for offset in offset_list:
|
for offset in offset_list:
|
||||||
|
Reference in New Issue
Block a user