Skip to content

Commit

Permalink
properly detect closed paths
Browse files Browse the repository at this point in the history
We flatten paths using cspsubdiv, and this can mean that the starting and ending points of a
closed path are not actually the exact same floating point values.  Instead, compare with a
slop factor.
  • Loading branch information
lexelby committed Dec 5, 2017
1 parent 5dbd018 commit b24f019
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sendto_silhouette.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
from silhouette.Graphtec import SilhouetteCameo
from silhouette.Strategy import MatFree
from silhouette.convert2dashes import splitPath
from silhouette.Geometry import dist_sq, XY_a

N_PAGE_WIDTH = 3200
N_PAGE_HEIGHT = 800
Expand Down Expand Up @@ -946,6 +947,9 @@ def handleViewBox( self ):
self.docTransform = parseTransform( 'scale(%f,%f)' % (sx, sy) )


def is_closed_path(self, path):
return dist_sq(XY_a(path[0]), XY_a(path[-1])) < 0.01

def effect(self):
if self.options.version:
print __version__
Expand Down Expand Up @@ -1008,21 +1012,22 @@ def write_progress(done, total, msg):

multipath = []
multipath.extend(mm_path)

for i in range(1,self.options.multipass):
# if reverse continue path without lifting, instead turn with rotating knife
if (self.options.reversetoggle):
mm_path = list(reversed(mm_path))
multipath.extend(mm_path[1:])
# if closed path (end = start) continue path without lifting
elif (mm_path[0] == mm_path[-1]):
elif self.is_closed_path(mm_path):
multipath.extend(mm_path[1:])
# else start a new path
else:
else:
cut.append(mm_path)

# on a closed path some overlapping doesn't harm, limited to a maximum of one additional round
overcut = self.options.overcut
if (overcut > 0) and (mm_path[0] == mm_path[-1]):
if (overcut > 0) and self.is_closed_path(mm_path):
pfrom = mm_path[0]
for pnext in mm_path[1:]:
dx = pnext[0] - pfrom[0]
Expand Down

0 comments on commit b24f019

Please sign in to comment.