Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. # This program stops on the first match
  2. # and thus ignores repeating x,y values
  3. # as would occur in a point going around
  4. # a circle multiple times.
  5. # There's not really a good way to account
  6. # for that, and thus matching on the first is ideal.
  7.  
  8. max_difference = 0.2
  9.  
  10. initial_input = [
  11. [(1,1), (2,2), (3,3), (4.1, 4.15)],
  12. [(3.1, 3), (4, 4), (5,5)]
  13. ]
  14.  
  15. def two_tuples_match(tup1,tup2):
  16. return ((tup1[0] - tup2[0])**2 + (tup1[1] - tup2[1])**2)**0.5 <= max_difference
  17.  
  18. def check_overlap(l1, l2):
  19. """ look for a match starting with end of l1, then to the end and make sure
  20. they all match, otherwise it doesn't count as overlap"""
  21. return any(all(two_tuples_match(t1, t2)
  22. for t1,t2 in zip(l1[-i-1:], l2[:i+1]))
  23. for i, tup1 in enumerate(reversed(l1)))
  24.  
  25. def check_inputted_list(l):
  26. for a, l1 in enumerate(l[:-1]):
  27. for b, l2 in enumerate(l[a+1:]):
  28. print(check_overlap(l1,l2))
  29.  
  30. check_inputted_list(initial_input)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement