diff --git a/src/corners.py b/src/corners.py --- a/src/corners.py +++ b/src/corners.py @@ -44,6 +44,9 @@ class Corners: # For four points ABCD, there are 24 possible permutations corresponding to the desired KLMN. # When we relax the condition of K being the upper left one, we get six groups of four equivalent permutations. KLMN ~ LMNK ~ MNKL ~ NKLM. # + # We determine which of the points' triplets are oriented clockwise and which counter-clockwise (minus/plus in the table below) + # and swap them so that all triangles turn counter-clockwise. + # # xxxx -> KLMN | ABC | ABD | ACD | BCD | index | swap # ------------ | :-: | :-: | :-: | :-: | ----: | ---- # A BCD | + | + | + | + | 15 | 0 @@ -69,7 +72,7 @@ class Corners: if any(x==0 for x in (abc,abd,acd,bcd)): return False # collinear degenerate swaps=[(1,3),(0,1),(1,2),(0,3),(2,3),(0,0)] - index=(8 if abc>0 else 0)+(4 if abd>0 else 0)+(2 if acd>0 else 0)+(1 if bcd>0 else 0) + index=(8 if abc>0 else 0)|(4 if abd>0 else 0)|(2 if acd>0 else 0)|(1 if bcd>0 else 0) if index%3!=0: return False # concave degenerate swap=swaps[index//3] @@ -88,11 +91,3 @@ class Corners: self.corners=self.corners[kIndex:]+self.corners[:kIndex] # rotate the upper left corner to the first place return True # success - -# import itertools -# points=[(10,8),(8,10),(12,10),(10,12)] -# for perm in itertools.permutations(points): - # corn=Corners() - # for p in perm: corn.add(p[0],p[1]) - # print(corn.canonizeOrder()) - # print(corn.corners)