Skip to content

Commit a64ab5e

Browse files
committed
directionalize
1 parent 43ad106 commit a64ab5e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

gcodeplot.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def getConfigOpts(filename):
596596
opts.append( (opt,arg) )
597597
return opts
598598

599-
def directionalize(paths, angle):
599+
def directionalize(paths, angle, tolerance=1e-10):
600600
vector = (math.cos(angle * math.pi / 180.), math.sin(angle * math.pi / 180.))
601601

602602
outPaths = []
@@ -610,16 +610,18 @@ def directionalize(paths, angle):
610610
curVector = (path[i][0]-prevPoint[0],path[i][1]-prevPoint[1])
611611
if curVector[0] or curVector[1]:
612612
dotProduct = curVector[0]*vector[0] + curVector[1]*vector[1]
613-
if dotProduct > 0 and not canBeForward:
614-
outPaths.append(list(reversed(path[startIndex:i])))
615-
startIndex = i-1
616-
canBeForward = True
613+
if dotProduct > tolerance:
614+
if not canBeForward:
615+
outPaths.append(list(reversed(path[startIndex:i])))
616+
startIndex = i-1
617+
canBeForward = True
617618
canBeReversed = False
618-
elif dotProduct < 0 and not canBeReversed:
619-
outPaths.append(path[startIndex:i])
620-
startIndex = i-1
619+
elif dotProduct < -tolerance:
620+
if not canBeReversed:
621+
outPaths.append(path[startIndex:i])
622+
startIndex = i-1
623+
canBeReversed = True
621624
canBeForward = False
622-
canBeReversed = True
623625
prevPoint = path[i]
624626
i += 1
625627
if canBeForward:

svgpath/shader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def shade(self, polygon, grayscale, avoidOutline=True, mode=None):
3434
return []
3535
intensity = (self.unshadedThreshold-grayscale) / float(self.unshadedThreshold)
3636
spacing = self.lightestSpacing * (1-intensity) + self.darkestSpacing * intensity
37-
lines = Shader.shadePolygon(polygon, self.angle, spacing, avoidOutline=avoidOutline, mode=mode)
37+
lines = Shader.shadePolygon(polygon, self.angle, spacing, avoidOutline=avoidOutline, mode=mode, alternate=(self.drawingDirectionAngle is None))
3838
if self.crossHatch:
3939
lines += Shader.shadePolygon(polygon, self.angle+90, spacing, avoidOutline=avoidOutline, mode=mode, alternate=(self.drawingDirectionAngle is None))
4040
return lines

0 commit comments

Comments
 (0)