Skip to content

Instantly share code, notes, and snippets.

@jrialland
Created November 9, 2015 21:43
Show Gist options
  • Save jrialland/2d83d7a9f0f565eaa3e2 to your computer and use it in GitHub Desktop.
Save jrialland/2d83d7a9f0f565eaa3e2 to your computer and use it in GitHub Desktop.
simplifies a list a points
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