kopia lustrzana https://github.com/inkstitch/inkstitch
change pull_compensation_rails to a continuous balance and fix some edge cases.
rodzic
4285a6fb7f
commit
3aa92ba7b7
|
@ -136,14 +136,13 @@ class SatinColumn(EmbroideryElement):
|
|||
@param(
|
||||
'pull_compensation_percent',
|
||||
_('Pull compensation percentage'),
|
||||
tooltip=_('pull compensation in percentage'),
|
||||
tooltip=_('Additional pull compensation which varries as a percentage of stitch width.'),
|
||||
unit='%',
|
||||
type='int',
|
||||
type='float',
|
||||
default=0)
|
||||
def pull_compensation_percent(self):
|
||||
# pull compensation as a percentage of the width
|
||||
return max(self.get_int_param("pull_compensation_percent", 0), 0)
|
||||
|
||||
return self.get_float_param("pull_compensation_percent", 0)
|
||||
@property
|
||||
@param(
|
||||
'pull_compensation_mm',
|
||||
|
@ -161,15 +160,14 @@ class SatinColumn(EmbroideryElement):
|
|||
|
||||
@property
|
||||
@param(
|
||||
'pull_compensation_rails',
|
||||
_('Apply pull compensation to '),
|
||||
tooltip=_('decide wether the pull compensations should be applied to both side or only to a given one'),
|
||||
type='dropdown',
|
||||
options=[_("Both rails"), _("First rail only"), _("Second rail only")],
|
||||
default=0)
|
||||
def pull_compensation_rails(self):
|
||||
# 0=Both | 1 = First Rail | 2 = Second Rail
|
||||
return self.get_int_param("pull_compensation_rails", 0)
|
||||
'pull_compensation_balance',
|
||||
_('Pull compensation balance'),
|
||||
tooltip=_('Percentage of pull compensation which gets applied to second rail (50% is centered).'),
|
||||
unit='%',
|
||||
type='float',
|
||||
default=50)
|
||||
def pull_compensation_balance(self):
|
||||
return min(100, max(0, self.get_float_param("pull_compensation_balance", 50)))
|
||||
|
||||
@property
|
||||
@param('contour_underlay', _('Contour underlay'), type='toggle', group=_('Contour Underlay'))
|
||||
|
@ -643,41 +641,31 @@ class SatinColumn(EmbroideryElement):
|
|||
center_walk, _ = self.plot_points_on_rails(self.zigzag_spacing, -100000)
|
||||
return shgeo.LineString(center_walk)
|
||||
|
||||
def offset_points(self, pos1, pos2, offset, offset_percent=0, offset_rails=0):
|
||||
def offset_points(self, pos1, pos2, offset_px, offset_prop=0, offset_balance=0.5):
|
||||
# Expand or contract two points about their midpoint. This is
|
||||
# useful for pull compensation and insetting underlay.
|
||||
|
||||
distance = (pos1 - pos2).length()
|
||||
offset_px = 0
|
||||
if offset:
|
||||
offset_px += offset
|
||||
if offset_percent:
|
||||
offset_px += ((offset_percent / 100) * distance)
|
||||
|
||||
if distance < 0.0001:
|
||||
# if they're the same point, we don't know which direction
|
||||
# to offset in, so we have to just return the points
|
||||
return pos1, pos2
|
||||
|
||||
# calculate the offset for each side
|
||||
offset_total = offset_px + (offset_prop * distance)
|
||||
inv_offset_balance = 1 - offset_balance
|
||||
offset1 = offset_total * inv_offset_balance
|
||||
offset2 = offset_total * offset_balance
|
||||
|
||||
# don't contract beyond the midpoint, or we'll start expanding
|
||||
if offset_px < -distance / 2.0:
|
||||
offset_px = -distance / 2.0
|
||||
if offset1 < -distance * inv_offset_balance:
|
||||
offset1 = -distance * inv_offset_balance
|
||||
if offset2 < -distance * offset_balance:
|
||||
offset2 = -distance * offset_balance
|
||||
|
||||
# chose how to apply on the rails
|
||||
|
||||
coeff1 = 1
|
||||
coeff2 = 1
|
||||
|
||||
if offset_rails == 1:
|
||||
coeff1 = 2
|
||||
coeff2 = 0
|
||||
|
||||
if offset_rails == 2:
|
||||
coeff1 = 0
|
||||
coeff2 = 2
|
||||
|
||||
pos1 = pos1 + (pos1 - pos2).unit() * offset_px * coeff1
|
||||
pos2 = pos2 + (pos2 - pos1).unit() * offset_px * coeff2
|
||||
pos1 = pos1 + (pos1 - pos2).unit() * offset1
|
||||
pos2 = pos2 + (pos2 - pos1).unit() * offset2
|
||||
|
||||
return pos1, pos2
|
||||
|
||||
|
@ -714,13 +702,13 @@ class SatinColumn(EmbroideryElement):
|
|||
distance_remaining -= segment_length
|
||||
pos = segment_end
|
||||
|
||||
def plot_points_on_rails(self, spacing, offset, offset_percent=0, offset_rails=0):
|
||||
def plot_points_on_rails(self, spacing, offset_px=0, offset_prop=0, offset_balance=0.5):
|
||||
# Take a section from each rail in turn, and plot out an equal number
|
||||
# of points on both rails. Return the points plotted. The points will
|
||||
# be contracted or expanded by offset using self.offset_points().
|
||||
|
||||
def add_pair(pos0, pos1):
|
||||
pos0, pos1 = self.offset_points(pos0, pos1, offset, offset_percent, offset_rails)
|
||||
pos0, pos1 = self.offset_points(pos0, pos1, offset_px, offset_prop, offset_balance)
|
||||
points[0].append(pos0)
|
||||
points[1].append(pos1)
|
||||
|
||||
|
@ -878,8 +866,10 @@ class SatinColumn(EmbroideryElement):
|
|||
# print >> dbg, "satin", self.zigzag_spacing, self.pull_compensation
|
||||
|
||||
patch = StitchGroup(color=self.color)
|
||||
sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation, self.pull_compensation_percent,
|
||||
self.pull_compensation_rails)
|
||||
|
||||
# pull compensation is automatically converted from mm to pixels by get_float_param
|
||||
sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation, self.pull_compensation_percent/100,
|
||||
self.pull_compensation_balance/100)
|
||||
|
||||
if self.max_stitch_length:
|
||||
return self.do_split_stitch(patch, sides)
|
||||
|
@ -909,7 +899,7 @@ class SatinColumn(EmbroideryElement):
|
|||
|
||||
patch = StitchGroup(color=self.color)
|
||||
|
||||
sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation, self.pull_compensation_percent, self.pull_compensation_rails)
|
||||
sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation, self.pull_compensation_percent/100, self.pull_compensation_balance/100)
|
||||
|
||||
# "left" and "right" here are kind of arbitrary designations meaning
|
||||
# a point from the first and second rail respectively
|
||||
|
|
|
@ -117,7 +117,7 @@ inkstitch_attribs = [
|
|||
'e_stitch',
|
||||
'pull_compensation_mm',
|
||||
'pull_compensation_percent',
|
||||
'pull_compensation_rails',
|
||||
'pull_compensation_balance',
|
||||
'stroke_first',
|
||||
# stitch_plan
|
||||
'invisible_layers',
|
||||
|
|
Ładowanie…
Reference in New Issue