Created
November 9, 2015 21:43
-
-
Save jrialland/2d83d7a9f0f565eaa3e2 to your computer and use it in GitHub Desktop.
simplifies a list a points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def simplify_path(p): | |
direction = p[1][0]-p[0][0], p[1][1]-p[0][1] | |
yield p[0] | |
current = p[1] | |
if len(p)>2: | |
for pos in p[2:]: | |
rdir = pos[0]-current[0], pos[1]-current[1] | |
if direction != rdir: | |
yield current | |
current = pos | |
yield p[-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment