Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This program stops on the first match
- # and thus ignores repeating x,y values
- # as would occur in a point going around
- # a circle multiple times.
- # There's not really a good way to account
- # for that, and thus matching on the first is ideal.
- max_difference = 0.2
- initial_input = [
- [(1,1), (2,2), (3,3), (4.1, 4.15)],
- [(3.1, 3), (4, 4), (5,5)]
- ]
- def two_tuples_match(tup1,tup2):
- return ((tup1[0] - tup2[0])**2 + (tup1[1] - tup2[1])**2)**0.5 <= max_difference
- def check_overlap(l1, l2):
- """ look for a match starting with end of l1, then to the end and make sure
- they all match, otherwise it doesn't count as overlap"""
- return any(all(two_tuples_match(t1, t2)
- for t1,t2 in zip(l1[-i-1:], l2[:i+1]))
- for i, tup1 in enumerate(reversed(l1)))
- def check_inputted_list(l):
- for a, l1 in enumerate(l[:-1]):
- for b, l2 in enumerate(l[a+1:]):
- print(check_overlap(l1,l2))
- check_inputted_list(initial_input)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement