summaryrefslogtreecommitdiff
path: root/lib/patterns.py
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2022-05-18 16:02:07 +0200
committerGitHub <noreply@github.com>2022-05-18 16:02:07 +0200
commitbc4f3b4699555f48c571be9a22a6768635c38cd0 (patch)
tree6a0bcd47bd19742857d0a7ed6bc034b22a4621a6 /lib/patterns.py
parentbb0f3b8168ea2c889935b96b532188b79d7f952e (diff)
Auto route for running stitch (#1638)
* add auto route for running stitch * introduce free motion commands Co-authored-by: Lex Neva <github.com@lexneva.name>
Diffstat (limited to 'lib/patterns.py')
-rw-r--r--lib/patterns.py48
1 files changed, 5 insertions, 43 deletions
diff --git a/lib/patterns.py b/lib/patterns.py
index da22f21b..aca6155c 100644
--- a/lib/patterns.py
+++ b/lib/patterns.py
@@ -3,25 +3,17 @@
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
-import inkex
from shapely import geometry as shgeo
+from .marker import get_marker_elements
from .stitch_plan import Stitch
-from .svg.tags import EMBROIDERABLE_TAGS
from .utils import Point
-def is_pattern(node):
- if node.tag not in EMBROIDERABLE_TAGS:
- return False
- style = node.get('style') or ''
- return "marker-start:url(#inkstitch-pattern-marker)" in style
-
-
def apply_patterns(patches, node):
- patterns = _get_patterns(node)
- _apply_fill_patterns(patterns['fill_patterns'], patches)
- _apply_stroke_patterns(patterns['stroke_patterns'], patches)
+ patterns = get_marker_elements(node, "pattern")
+ _apply_fill_patterns(patterns['fill'], patches)
+ _apply_stroke_patterns(patterns['stroke'], patches)
def _apply_stroke_patterns(patterns, patches):
@@ -64,43 +56,13 @@ def _apply_fill_patterns(patterns, patches):
patch.stitches = patch_points
-def _get_patterns(node):
- from .elements import EmbroideryElement
- from .elements.stroke import Stroke
-
- fills = []
- strokes = []
- xpath = "./parent::svg:g/*[contains(@style, 'marker-start:url(#inkstitch-pattern-marker)')]"
- patterns = node.xpath(xpath, namespaces=inkex.NSS)
- for pattern in patterns:
- if pattern.tag not in EMBROIDERABLE_TAGS:
- continue
-
- element = EmbroideryElement(pattern)
- fill = element.get_style('fill')
- stroke = element.get_style('stroke')
-
- if fill is not None:
- fill_pattern = Stroke(pattern).paths
- linear_rings = [shgeo.LinearRing(path) for path in fill_pattern]
- for ring in linear_rings:
- fills.append(shgeo.Polygon(ring))
-
- if stroke is not None:
- stroke_pattern = Stroke(pattern).paths
- line_strings = [shgeo.LineString(path) for path in stroke_pattern]
- strokes.append(shgeo.MultiLineString(line_strings))
-
- return {'fill_patterns': fills, 'stroke_patterns': strokes}
-
-
def _get_pattern_points(first, second, pattern):
points = []
intersection = shgeo.LineString([first, second]).intersection(pattern)
if isinstance(intersection, shgeo.Point):
points.append(Point(intersection.x, intersection.y))
if isinstance(intersection, shgeo.MultiPoint):
- for point in intersection:
+ for point in intersection.geoms:
points.append(Point(point.x, point.y))
# sort points after their distance to first
points.sort(key=lambda point: point.distance(first))