@@ -130,7 +130,7 @@ def select_vectors(vectors, previous_xDirection, previous_yDirection):
130130 Select the vectors that are aligned with the xDirection and yDirection.
131131 """
132132 if previous_xDirection is not None and previous_yDirection is not None :
133- sorted_vectors_by_alignment = sorted (vectors , key = lambda v : compute_dot_product (v , previous_xDirection ), reverse = True )
133+ sorted_vectors_by_alignment = sorted (vectors , key = lambda v : abs ( compute_dot_product (v , previous_xDirection ) ), reverse = True )
134134 new_xDirection = sorted_vectors_by_alignment [0 ]
135135 else :
136136 new_xDirection = vectors [0 ]
@@ -139,8 +139,12 @@ def select_vectors(vectors, previous_xDirection, previous_yDirection):
139139 for v in vectors :
140140 if compute_dot_product (v , new_xDirection ) ** 2 < 0.5 :
141141 condidates_for_yDirection .append (v )
142+
143+ if not condidates_for_yDirection :
144+ return new_xDirection , None
145+
142146 if previous_xDirection is not None and previous_yDirection is not None :
143- sorted_vectors_by_perpendicularity = sorted (condidates_for_yDirection , key = lambda v : compute_dot_product (v , previous_yDirection ), reverse = True )
147+ sorted_vectors_by_perpendicularity = sorted (condidates_for_yDirection , key = lambda v : abs ( compute_dot_product (v , previous_yDirection ) ), reverse = True )
144148 new_xDirection = sorted_vectors_by_alignment [0 ]
145149 new_yDirection = sorted_vectors_by_perpendicularity [0 ] - compute_dot_product (sorted_vectors_by_perpendicularity [0 ], new_xDirection ) * new_xDirection
146150 new_yDirection .Unitize ()
0 commit comments