@@ -262,35 +262,19 @@ def check_point_on_array(array, point, left_right_direction=True):
262262 rightY = float (array [i + 1 ]['y' ])
263263
264264 # Check if the point lies on the line segment between array[i] and array[i + 1]
265- if - 40 <= leftY - pointY <= 40 and \
266- - 40 <= rightY - pointY <= 40 and \
267- leftX <= pointX <= rightX :
268- return True , array [:i + 1 ] + [point ], [point ] + array [i + 1 :]
269- if - 40 <= leftX - pointX <= 40 and \
270- - 40 <= rightX - pointX <= 40 and \
271- leftY <= pointY <= rightY :
272- return True , array [:i + 1 ] + [point ], [point ] + array [i + 1 :]
273265
274- # if left_right_direction:
275- if - 20 <= leftX - pointX <= 20 and \
276- (leftY <= pointY <= rightY or leftY >= pointY >= rightY ):
277- print ('to the left / right' )
278- return True , array [:i + 1 ] + [point ], [point ] + array [i + 1 :]
279- # else:
280- if - 20 <= leftY - pointY <= 20 and \
281- (leftX <= pointX <= rightX or leftX >= pointX >= rightX ):
282- print ('on the up / down' )
283- return True , array [:i + 1 ] + [point ], [point ] + array [i + 1 :]
266+ pointbetweenleftrightx = leftX <= pointX <= rightX or leftX >= pointX >= rightX
267+ samey = - 40 <= leftY - pointY <= 40 and - 40 <= rightY - pointY <= 40
268+ sameleftorrighty = - 20 <= leftY - pointY <= 20 or - 20 <= rightY - pointY <= 20
284269
285- # if left_right_direction:
286- if - 20 <= rightX - pointX <= 20 and \
287- (leftY <= pointY <= rightY or leftY >= pointY >= rightY ):
288- print ('to the right / right' )
270+ if pointbetweenleftrightx and (samey or sameleftorrighty ):
289271 return True , array [:i + 1 ] + [point ], [point ] + array [i + 1 :]
290- # else:
291- if - 20 <= rightY - pointY <= 20 and \
292- (leftX <= pointX <= rightX or leftX >= pointX >= rightX ):
293- print ('on the up / down' )
272+
273+ pointbetweenleftrighty = leftY <= pointY <= rightY or leftY >= pointY >= rightY
274+ samex = - 40 <= leftX - pointX <= 40 and - 40 <= rightX - pointX <= 40
275+ sameleftorrightx = - 20 <= leftX - pointX <= 20 or - 20 <= rightX - pointX <= 20
276+
277+ if pointbetweenleftrighty and (samex or sameleftorrightx ):
294278 return True , array [:i + 1 ] + [point ], [point ] + array [i + 1 :]
295279
296280 # switch direction for the next waypoint
0 commit comments