rudimentary gradient support, only for manual fill currently

pull/5/head
Lex Neva 2017-11-15 02:07:06 +00:00
rodzic 2a97c5d25a
commit 2841cb8c6f
1 zmienionych plików z 30 dodań i 13 usunięć

Wyświetl plik

@ -263,6 +263,10 @@ class Fill(EmbroideryElement):
def row_spacing(self): def row_spacing(self):
return self.get_float_param("row_spacing_mm") return self.get_float_param("row_spacing_mm")
@property
def end_row_spacing(self):
return self.get_float_param("end_row_spacing_mm")
@property @property
@param('max_stitch_length_mm', 'Maximum fill stitch length', unit='mm', type='float') @param('max_stitch_length_mm', 'Maximum fill stitch length', unit='mm', type='float')
def max_stitch_length(self): def max_stitch_length(self):
@ -329,13 +333,16 @@ class Fill(EmbroideryElement):
return stitch - offset * self.east(angle) return stitch - offset * self.east(angle)
def intersect_region_with_grating(self, angle=None, row_spacing=None): def intersect_region_with_grating(self, angle=None, row_spacing=None, end_row_spacing=None):
if angle is None: if angle is None:
angle = self.angle angle = self.angle
if row_spacing is None: if row_spacing is None:
row_spacing = self.row_spacing row_spacing = self.row_spacing
if end_row_spacing is None:
end_row_spacing = self.end_row_spacing
# the max line length I'll need to intersect the whole shape is the diagonal # the max line length I'll need to intersect the whole shape is the diagonal
(minx, miny, maxx, maxy) = self.shape.bounds (minx, miny, maxx, maxy) = self.shape.bounds
upper_left = PyEmb.Point(minx, miny) upper_left = PyEmb.Point(minx, miny)
@ -367,6 +374,10 @@ class Fill(EmbroideryElement):
start -= center.y start -= center.y
end -= center.y end -= center.y
height = abs(end - start)
print >> dbg, "grating:", start, end, height, row_spacing, end_row_spacing
# offset start slightly so that rows are always an even multiple of # offset start slightly so that rows are always an even multiple of
# row_spacing_px from the origin. This makes it so that abutting # row_spacing_px from the origin. This makes it so that abutting
# fill regions at the same angle and spacing always line up nicely. # fill regions at the same angle and spacing always line up nicely.
@ -374,9 +385,11 @@ class Fill(EmbroideryElement):
rows = [] rows = []
while start < end: current_row_y = start
p0 = center + normal * start + direction * half_length
p1 = center + normal * start - direction * half_length while current_row_y < end:
p0 = center + normal * current_row_y + direction * half_length
p1 = center + normal * current_row_y - direction * half_length
endpoints = [p0.as_tuple(), p1.as_tuple()] endpoints = [p0.as_tuple(), p1.as_tuple()]
grating_line = shgeo.LineString(endpoints) grating_line = shgeo.LineString(endpoints)
@ -387,19 +400,23 @@ class Fill(EmbroideryElement):
else: else:
if res.is_empty or len(res.coords) == 1: if res.is_empty or len(res.coords) == 1:
# ignore if we intersected at a single point or no points # ignore if we intersected at a single point or no points
start += row_spacing runs = []
continue else:
runs = [res.coords] runs = [res.coords]
runs.sort(key=lambda seg: (PyEmb.Point(*seg[0]) - upper_left).length()) if runs:
runs.sort(key=lambda seg: (PyEmb.Point(*seg[0]) - upper_left).length())
if self.flip: if self.flip:
runs.reverse() runs.reverse()
runs = map(lambda run: tuple(reversed(run)), runs) runs = map(lambda run: tuple(reversed(run)), runs)
rows.append(runs) rows.append(runs)
start += row_spacing if end_row_spacing:
current_row_y += row_spacing + (end_row_spacing - row_spacing) * ((current_row_y - start) / height)
else:
current_row_y += row_spacing
return rows return rows