Skip to content

Commit

Permalink
Added sorting of voronoi wires to minimize rapid moves
Browse files Browse the repository at this point in the history
  • Loading branch information
mlampert committed Oct 25, 2020
1 parent ebe5bb0 commit 2046db0
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions src/Mod/Path/PathScripts/PathVcarve.py
Expand Up @@ -58,7 +58,7 @@ def translate(context, text, disambig=None):
VD = []
Vertex = {}

def _getVoronoiWires(vd):
def _collectVoronoiWires(vd):
edges = [e for e in vd.Edges if e.Color == PRIMARY]
vertex = {}
for e in edges:
Expand Down Expand Up @@ -116,6 +116,33 @@ def traverse(vStart, edge, edges):
knots = [v for v in knots if v != vLast]
return wires

def _sortVoronoiWires(wires, start = FreeCAD.Vector(0, 0, 0)):
def closestTo(start, point):
p = None
l = None
for i in point:
if l is None or l > start.distanceToPoint(point[i]):
l = start.distanceToPoint(point[i])
p = i
return p


begin = {}
end = {}

for i, w in enumerate(wires):
begin[i] = w[ 0].Vertices[0].toPoint()
end[i] = w[-1].Vertices[1].toPoint()

index = []
while begin:
idx = closestTo(start, begin)
index.append(idx)
del begin[idx]
start = end[idx]

return [wires[i] for i in index]

class ObjectVcarve(PathEngraveBase.ObjectOp):
'''Proxy class for Vcarve operation.'''

Expand Down Expand Up @@ -225,16 +252,13 @@ def cutWire(edges):
vd.colorColinear(COLINEAR, obj.Threshold)
vd.colorTwins(TWIN)

if True:
wires = []
for vWire in _getVoronoiWires(vd):
pWire = self._getPartEdges(obj, vWire)
if pWire:
wires.append(pWire)
pathlist.extend(cutWire(pWire))
VD.append((f, vd, wires))
else:
VD.append((f, vd))
wires = []
for vWire in _sortVoronoiWires(_collectVoronoiWires(vd)):
pWire = self._getPartEdges(obj, vWire)
if pWire:
wires.append(pWire)
pathlist.extend(cutWire(pWire))
VD.append((f, vd, wires))

self.commandlist = pathlist

Expand Down

0 comments on commit 2046db0

Please sign in to comment.