summaryrefslogtreecommitdiff
path: root/lib/stitches
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2021-03-04 18:40:53 +0100
committerGitHub <noreply@github.com>2021-03-04 18:40:53 +0100
commite84a86d4ac0caf29d6074728376ff0a594243fec (patch)
tree888c79ed0094ba2916a1d329861a85515959913c /lib/stitches
parentb39575a50191307b3b56eab6455626398eec6397 (diff)
Update for Inkscape 1.0 (#880)
* update for inkscape 1.0 * add about extension * Build improvements for the inkscape1.0 branch (#985) * zip: export real svg not stitch plan * #411 and #726 * Tools for Font Creators (#1018) * ignore very small holes in fills * remove embroider (#1026) * auto_fill: ignore shrink_or_grow if result is empty (#589) * break apart: do not ignore small fills Co-authored-by: Hagen Fritsch <rumpeltux-github@irgendwo.org> Co-authored-by: Lex Neva <github.com@lexneva.name>
Diffstat (limited to 'lib/stitches')
-rw-r--r--lib/stitches/__init__.py6
-rw-r--r--lib/stitches/auto_fill.py15
-rw-r--r--lib/stitches/auto_satin.py29
-rw-r--r--lib/stitches/fill.py5
-rw-r--r--lib/stitches/running_stitch.py2
5 files changed, 29 insertions, 28 deletions
diff --git a/lib/stitches/__init__.py b/lib/stitches/__init__.py
index e052d144..12c636a6 100644
--- a/lib/stitches/__init__.py
+++ b/lib/stitches/__init__.py
@@ -1,6 +1,6 @@
-from running_stitch import *
-from auto_fill import auto_fill
-from fill import legacy_fill
+from .auto_fill import auto_fill
+from .fill import legacy_fill
+from .running_stitch import *
# Can't put this here because we get a circular import :(
#from auto_satin import auto_satin
diff --git a/lib/stitches/auto_fill.py b/lib/stitches/auto_fill.py
index b5157a5a..485f51e5 100644
--- a/lib/stitches/auto_fill.py
+++ b/lib/stitches/auto_fill.py
@@ -8,11 +8,12 @@ from shapely import geometry as shgeo
from shapely.ops import snap
from shapely.strtree import STRtree
-from .fill import intersect_region_with_grating, stitch_row
-from .running_stitch import running_stitch
from ..debug import debug
from ..svg import PIXELS_PER_MM
-from ..utils.geometry import Point as InkstitchPoint, line_string_to_point_list
+from ..utils.geometry import Point as InkstitchPoint
+from ..utils.geometry import line_string_to_point_list
+from .fill import intersect_region_with_grating, stitch_row
+from .running_stitch import running_stitch
class PathEdge(object):
@@ -82,7 +83,7 @@ def which_outline(shape, coords):
point = shgeo.Point(*coords)
outlines = list(shape.boundary)
- outline_indices = range(len(outlines))
+ outline_indices = list(range(len(outlines)))
closest = min(outline_indices, key=lambda index: outlines[index].distance(point))
return closest
@@ -175,7 +176,7 @@ def insert_node(graph, shape, point):
if key == "outline":
edges.append(((start, end), data))
- edge, data = min(edges, key=lambda (edge, data): shgeo.LineString(edge).distance(projected_point))
+ edge, data = min(edges, key=lambda edge_data: shgeo.LineString(edge_data[0]).distance(projected_point))
graph.remove_edge(*edge, key="outline")
graph.add_edge(edge[0], node, key="outline", **data)
@@ -204,7 +205,7 @@ def add_boundary_travel_nodes(graph, shape):
if length > 1:
# Just plot a point every pixel, that should be plenty of
# resolution. A pixel is around a quarter of a millimeter.
- for i in xrange(1, int(length)):
+ for i in range(1, int(length)):
subpoint = segment.interpolate(i)
graph.add_node((subpoint.x, subpoint.y), projection=outline.project(subpoint), outline=outline_index)
@@ -480,7 +481,7 @@ def find_stitch_path(graph, travel_graph, starting_point=None, ending_point=None
graph = graph.copy()
if not starting_point:
- starting_point = graph.nodes.keys()[0]
+ starting_point = list(graph.nodes.keys())[0]
starting_node = nearest_node(graph, starting_point)
diff --git a/lib/stitches/auto_satin.py b/lib/stitches/auto_satin.py
index 112c714b..5ce91a49 100644
--- a/lib/stitches/auto_satin.py
+++ b/lib/stitches/auto_satin.py
@@ -1,14 +1,12 @@
import math
-from itertools import chain, izip
+from itertools import chain
+import inkex
import networkx as nx
+from lxml import etree
from shapely import geometry as shgeo
from shapely.geometry import Point as ShapelyPoint
-import cubicsuperpath
-import inkex
-import simplestyle
-
from ..commands import add_commands
from ..elements import SatinColumn, Stroke
from ..i18n import _
@@ -87,7 +85,7 @@ class SatinSegment(object):
num_segments = int(math.ceil(self.center_line.length / segment_size))
segments = []
- for i in xrange(num_segments):
+ for i in range(num_segments):
segments.append(SatinSegment(self.satin,
float(i) / num_segments,
float(i + 1) / num_segments,
@@ -216,13 +214,13 @@ class RunningStitch(object):
original_element.node.get(INKSTITCH_ATTRIBS['contour_underlay_stitch_length_mm'], '')
def to_element(self):
- node = inkex.etree.Element(SVG_PATH_TAG)
- node.set("d", cubicsuperpath.formatPath(
- line_strings_to_csp([self.path])))
+ node = etree.Element(SVG_PATH_TAG)
+ d = str(inkex.paths.CubicSuperPath(line_strings_to_csp([self.path])))
+ node.set("d", d)
style = self.original_element.parse_style()
style['stroke-dasharray'] = "0.5,0.5"
- style = simplestyle.formatStyle(style)
+ style = str(inkex.Style(style))
node.set("style", style)
node.set(INKSTITCH_ATTRIBS['running_stitch_length_mm'], self.running_stitch_length)
@@ -445,8 +443,9 @@ def add_jumps(graph, elements, preserve_order):
point2 = graph.nodes[node2]['point']
potential_edges.append((point1, point2))
- edge = min(potential_edges, key=lambda (p1, p2): p1.distance(p2))
- graph.add_edge(str(edge[0]), str(edge[1]), jump=True)
+ if potential_edges:
+ edge = min(potential_edges, key=lambda p1_p2: p1_p2[0].distance(p1_p2[1]))
+ graph.add_edge(str(edge[0]), str(edge[1]), jump=True)
else:
# networkx makes this super-easy! k_edge_agumentation tells us what edges
# we need to add to ensure that the graph is fully connected. We give it a
@@ -497,7 +496,7 @@ def find_path(graph, starting_node, ending_node):
# forth on each satin twice due to the satin edges being in the graph
# twice (forward and reverse).
graph = nx.Graph(graph)
- graph.remove_edges_from(zip(path[:-1], path[1:]))
+ graph.remove_edges_from(list(zip(path[:-1], path[1:])))
final_path = []
prev = None
@@ -643,14 +642,14 @@ def preserve_original_groups(elements, original_parent_nodes):
to the group that contained the original SatinColumn that spawned it.
"""
- for element, parent in izip(elements, original_parent_nodes):
+ for element, parent in zip(elements, original_parent_nodes):
if parent is not None:
parent.append(element.node)
element.node.set('transform', get_correction_transform(parent, child=True))
def create_new_group(parent, insert_index):
- group = inkex.etree.Element(SVG_GROUP_TAG, {
+ group = etree.Element(SVG_GROUP_TAG, {
INKSCAPE_LABEL: _("Auto-Satin"),
"transform": get_correction_transform(parent, child=True)
})
diff --git a/lib/stitches/fill.py b/lib/stitches/fill.py
index 924f64f6..a19e080b 100644
--- a/lib/stitches/fill.py
+++ b/lib/stitches/fill.py
@@ -3,7 +3,8 @@ import math
import shapely
from ..svg import PIXELS_PER_MM
-from ..utils import cache, Point as InkstitchPoint
+from ..utils import Point as InkstitchPoint
+from ..utils import cache
def legacy_fill(shape, angle, row_spacing, end_row_spacing, max_stitch_length, flip, staggers, skip_last):
@@ -223,7 +224,7 @@ def pull_runs(rows, shape, row_spacing):
run = []
prev = None
- for row_num in xrange(len(rows)):
+ for row_num in range(len(rows)):
row = rows[row_num]
first, rest = row[0], row[1:]
diff --git a/lib/stitches/running_stitch.py b/lib/stitches/running_stitch.py
index 0bb8fc7d..57a03865 100644
--- a/lib/stitches/running_stitch.py
+++ b/lib/stitches/running_stitch.py
@@ -92,7 +92,7 @@ def bean_stitch(stitches, repeats):
for stitch in stitches:
new_stitches.append(stitch)
- for i in xrange(repeats):
+ for i in range(repeats):
new_stitches.extend(copy(new_stitches[-2:]))
return new_stitches