From 3181016ae597a04c6e9cb23ff7a5a3e029ff444a Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Sat, 7 Jan 2017 23:07:51 -0500 Subject: [PATCH] join paths --- axi/__init__.py | 3 ++- axi/device.py | 4 ++-- axi/drawing.py | 6 +++--- axi/paths.py | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/axi/__init__.py b/axi/__init__.py index bee7761..9b0ac4d 100644 --- a/axi/__init__.py +++ b/axi/__init__.py @@ -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 diff --git a/axi/device.py b/axi/device.py index 7b0025d..974512e 100644 --- a/axi/device.py +++ b/axi/device.py @@ -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' diff --git a/axi/drawing.py b/axi/drawing.py index 6c91541..504a3b8 100644 --- a/axi/drawing.py +++ b/axi/drawing.py @@ -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)) diff --git a/axi/paths.py b/axi/paths.py index 0930b9d..888b6da 100644 --- a/axi/paths.py +++ b/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