@@ -377,23 +377,6 @@ def calculate_y_intercept(self, offset):
377377 # y = mx + b -> b = y - mx
378378 return self .start .y + offset .y - self .slope * (self .start .x + offset .x )
379379
380- @staticmethod
381- def _approx (a , b ):
382- """
383- Same as math.isclose but supports python < 3.5
384-
385- :param a: first numeric
386- :type a: :class:`numbers.Number`
387- :param b: second numeric
388- :type b: :class:`numbers.Number`
389- :returns: if the are close
390- :rtype: bool
391- """
392-
393- if hasattr (math , 'isclose' ):
394- return math .isclose (a , b )
395- return abs (a - b ) <= 1e-09 * max (abs (a ), abs (b ))
396-
397380 @staticmethod
398381 def are_parallel (line1 , line2 ):
399382 """
@@ -412,7 +395,7 @@ def are_parallel(line1, line2):
412395 if line1 .vertical and line2 .vertical :
413396 return True
414397
415- return Line2 . _approx (line1 .slope , line2 .slope )
398+ return math . isclose (line1 .slope , line2 .slope )
416399
417400 @staticmethod
418401 def find_intersection (line1 , line2 , offset1 = None , offset2 = None ):
@@ -467,7 +450,7 @@ def find_intersection(line1, line2, offset1 = None, offset2 = None):
467450
468451 if line1 .vertical and line2 .vertical :
469452 # Two vertical lines
470- if not Line2 . _approx (l1_st_x , l2_st_x ):
453+ if not math . isclose (l1_st_x , l2_st_x ):
471454 return False , False , None
472455
473456 aal1 = axisall .AxisAlignedLine (None , l1_st_y , l1_en_y )
@@ -484,7 +467,7 @@ def find_intersection(line1, line2, offset1 = None, offset2 = None):
484467
485468 if line1 .horizontal and line2 .horizontal :
486469 # Two horizontal lines
487- if not Line2 . _approx (l1_st_y , l2_st_y ):
470+ if not math . isclose (l1_st_y , l2_st_y ):
488471 return False , False , None
489472
490473 aal1 = axisall .AxisAlignedLine (None , l1_st_x , l1_en_x )
@@ -503,7 +486,7 @@ def find_intersection(line1, line2, offset1 = None, offset2 = None):
503486 # Two non-vertical, non-horizontal, parallel lines
504487 yintr1 = line1 .calculate_y_intercept (offset1 )
505488 yintr2 = line2 .calculate_y_intercept (offset2 )
506- if not Line2 . _approx (yintr1 , yintr2 ):
489+ if not math . isclose (yintr1 , yintr2 ):
507490 return False , False , None
508491
509492 axis = line1 .axis
@@ -544,7 +527,7 @@ def unshift_vec(vec):
544527
545528 pt = vector2 .Vector2 (l1_st_x , l2_st_y )
546529
547- if Line2 . _approx (l2_st_y , l1_min ) or Line2 . _approx (l2_st_y , l2_max ) or Line2 . _approx (l1_st_x , l2_min ) or Line2 . _approx (l2_st_y , l2_max ):
530+ if math . isclose (l2_st_y , l1_min ) or math . isclose (l2_st_y , l2_max ) or math . isclose (l1_st_x , l2_min ) or math . isclose (l2_st_y , l2_max ):
548531 return True , False , pt
549532 else :
550533 return False , True , pt
@@ -556,7 +539,7 @@ def unshift_vec(vec):
556539 l1_min = min (l1_st_y , l1_en_y ) if offset1 is not None else line1 .min_y
557540 l1_max = max (l1_st_y , l1_en_y ) if offset1 is not None else line1 .max_y
558541
559- if Line2 . _approx (line2_y_at_line1_x , l1_min ) or Line2 . _approx (line2_y_at_line1_x , l1_max ):
542+ if math . isclose (line2_y_at_line1_x , l1_min ) or math . isclose (line2_y_at_line1_x , l1_max ):
560543 return True , False , vector2 .Vector2 (l1_st_x , line2_y_at_line1_x )
561544 elif line2_y_at_line1_x < l1_min or line2_y_at_line1_x > l2_max :
562545 return False , False , None
@@ -571,7 +554,7 @@ def unshift_vec(vec):
571554 l1_min = min (l1_st_x , l1_en_x ) if offset1 is not None else line1 .min_x
572555 l1_max = max (l1_st_x , l1_en_x ) if offset1 is not None else line1 .max_x
573556
574- if Line2 . _approx (line2_x_at_line1_y , l1_min ) or Line2 . _approx (line2_x_at_line1_y , l1_max ):
557+ if math . isclose (line2_x_at_line1_y , l1_min ) or math . isclose (line2_x_at_line1_y , l1_max ):
575558 return True , False , vector2 .Vector2 (line2_x_at_line1_y , l1_st_y )
576559 elif line2_x_at_line1_y < l1_min or line2_x_at_line1_y > l1_max :
577560 return False , False , None
@@ -593,8 +576,8 @@ def unshift_vec(vec):
593576 # Some caution needs to be taken here to ensure we do approximately before range
594577 # checks. It's possible for _approx(a, b) to be True and a < b to be True
595578
596- on_edge1 = Line2 . _approx (intr_x , l1_st_x ) or Line2 . _approx (intr_x , l1_en_x )
597- on_edge2 = Line2 . _approx (intr_x , l2_st_x ) or Line2 . _approx (intr_x , l2_en_x )
579+ on_edge1 = math . isclose (intr_x , l1_st_x ) or math . isclose (intr_x , l1_en_x )
580+ on_edge2 = math . isclose (intr_x , l2_st_x ) or math . isclose (intr_x , l2_en_x )
598581
599582 if on_edge1 and on_edge2 :
600583 intr_y = line1 .slope * intr_x + yintr1
0 commit comments