some convenience for finding closed contours

This commit is contained in:
Mario Voigt 2021-05-19 14:24:08 +02:00
parent 90fd706551
commit 3dc8f7e90d
2 changed files with 16 additions and 6 deletions

View File

@ -13,8 +13,11 @@ Features
Author: Mario Voigt / FabLab Chemnitz Author: Mario Voigt / FabLab Chemnitz
Mail: mario.voigt@stadtfabrikanten.org Mail: mario.voigt@stadtfabrikanten.org
Date: 09.08.2020 Date: 09.08.2020
Last patch: 14.04.2021 Last patch: 19.05.2021
License: GNU GPL v3 License: GNU GPL v3
ToDo:
- add option to replace last segment of closed paths by 'Z' or 'z' in case the first and last segment touch each other (coincident point)
""" """
import sys import sys
@ -131,9 +134,13 @@ class ContourScanner(inkex.EffectExtension):
subPaths.append(raw[prev:]) subPaths.append(raw[prev:])
for simpath in subPaths: for simpath in subPaths:
closed = False closed = False
if simpath[-1][0] == 'Z': if simpath[-1][0] == 'Z' or \
closed = True (simpath[-1][0] == 'L' and simpath[0][1] == simpath[-1][1]) or \
(simpath[-1][0] == 'C' and simpath[0][1] == [simpath[-1][1][-2], simpath[-1][1][-1]]) : #if first is last point the path is also closed. The "Z" command is not required
closed = True
if simpath[-2][0] == 'L': simpath[-1][1] = simpath[0][1] if simpath[-2][0] == 'L': simpath[-1][1] = simpath[0][1]
else: simpath.pop() else: simpath.pop()
points = [] points = []

View File

@ -93,11 +93,14 @@ class LinksCreator(inkex.EffectExtension):
def effect(self): def effect(self):
def createLinks(element): def createLinks(element):
elementParent = element.getparent() elementParent = element.getparent()
pathIsClosed = False
path = element.path.to_arrays() #to_arrays() is deprecated. How to make more modern? path = element.path.to_arrays() #to_arrays() is deprecated. How to make more modern?
if path[-1][0] == 'Z' or path[0][1] == path[-1][1]: #if first is last point the path is also closed. The "Z" command is not required pathIsClosed = False
if path[-1][0] == 'Z' or \
(path[-1][0] == 'L' and path[0][1] == path[-1][1]) or \
(path[-1][0] == 'C' and path[0][1] == [path[-1][1][-2], path[-1][1][-1]]) \
: #if first is last point the path is also closed. The "Z" command is not required
pathIsClosed = True pathIsClosed = True
if self.options.path_types == 'open_paths' and pathIsClosed is True: if self.options.path_types == 'open_paths' and pathIsClosed is True:
return #skip this loop iteration return #skip this loop iteration
elif self.options.path_types == 'closed_paths' and pathIsClosed is False: elif self.options.path_types == 'closed_paths' and pathIsClosed is False: