join paths
This commit is contained in:
parent
c0525511d2
commit
3181016ae5
|
@ -1,5 +1,6 @@
|
|||
from .device import Device
|
||||
from .drawing import Drawing
|
||||
from .paths import sort_paths, join_paths
|
||||
from .planner import Planner
|
||||
from .turtle import Turtle
|
||||
from .util import draw
|
||||
from .util import draw, reset
|
||||
|
|
|
@ -18,8 +18,8 @@ PEN_DOWN_POSITION = 40
|
|||
PEN_DOWN_SPEED = 150
|
||||
PEN_DOWN_DELAY = 100
|
||||
|
||||
ACCELERATION = 5
|
||||
MAX_VELOCITY = 3
|
||||
ACCELERATION = 8
|
||||
MAX_VELOCITY = 4
|
||||
CORNER_FACTOR = 0.01
|
||||
|
||||
VID_PID = '04D8:FD92'
|
||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import division
|
|||
|
||||
from math import sin, cos, radians
|
||||
|
||||
from .paths import sort_paths
|
||||
from .paths import sort_paths, join_paths
|
||||
|
||||
class Drawing(object):
|
||||
def __init__(self, paths=None):
|
||||
|
@ -36,8 +36,8 @@ class Drawing(object):
|
|||
def sort_paths(self, reversable=True):
|
||||
return Drawing(sort_paths(self.paths, reversable))
|
||||
|
||||
# def join_paths(self, tolerance=0.05):
|
||||
# return Drawing(util.join_paths(self.paths, tolerance))
|
||||
def join_paths(self, tolerance):
|
||||
return Drawing(join_paths(self.paths, tolerance))
|
||||
|
||||
# def remove_duplicates(self):
|
||||
# return Drawing(util.remove_duplicates(self.paths))
|
||||
|
|
16
axi/paths.py
16
axi/paths.py
|
@ -1,3 +1,5 @@
|
|||
from math import hypot
|
||||
|
||||
from .spatial import Index
|
||||
|
||||
def sort_paths(paths, reversable=True):
|
||||
|
@ -24,3 +26,17 @@ def sort_paths(paths, reversable=True):
|
|||
else:
|
||||
result.append(path)
|
||||
return result
|
||||
|
||||
def join_paths(paths, tolerance):
|
||||
if len(paths) < 2:
|
||||
return paths
|
||||
result = [list(paths[0])]
|
||||
for path in paths[1:]:
|
||||
x1, y1 = result[-1][-1]
|
||||
x2, y2 = path[0]
|
||||
d = hypot(x2 - x1, y2 - y1)
|
||||
if d <= tolerance:
|
||||
result[-1].extend(path)
|
||||
else:
|
||||
result.append(list(path))
|
||||
return result
|
||||
|
|
Loading…
Reference in New Issue