@@ -377,23 +377,6 @@ def calculate_y_intercept(self, offset):
377
377
# y = mx + b -> b = y - mx
378
378
return self .start .y + offset .y - self .slope * (self .start .x + offset .x )
379
379
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
-
397
380
@staticmethod
398
381
def are_parallel (line1 , line2 ):
399
382
"""
@@ -412,7 +395,7 @@ def are_parallel(line1, line2):
412
395
if line1 .vertical and line2 .vertical :
413
396
return True
414
397
415
- return Line2 . _approx (line1 .slope , line2 .slope )
398
+ return math . isclose (line1 .slope , line2 .slope )
416
399
417
400
@staticmethod
418
401
def find_intersection (line1 , line2 , offset1 = None , offset2 = None ):
@@ -467,7 +450,7 @@ def find_intersection(line1, line2, offset1 = None, offset2 = None):
467
450
468
451
if line1 .vertical and line2 .vertical :
469
452
# 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 ):
471
454
return False , False , None
472
455
473
456
aal1 = axisall .AxisAlignedLine (None , l1_st_y , l1_en_y )
@@ -484,7 +467,7 @@ def find_intersection(line1, line2, offset1 = None, offset2 = None):
484
467
485
468
if line1 .horizontal and line2 .horizontal :
486
469
# 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 ):
488
471
return False , False , None
489
472
490
473
aal1 = axisall .AxisAlignedLine (None , l1_st_x , l1_en_x )
@@ -503,7 +486,7 @@ def find_intersection(line1, line2, offset1 = None, offset2 = None):
503
486
# Two non-vertical, non-horizontal, parallel lines
504
487
yintr1 = line1 .calculate_y_intercept (offset1 )
505
488
yintr2 = line2 .calculate_y_intercept (offset2 )
506
- if not Line2 . _approx (yintr1 , yintr2 ):
489
+ if not math . isclose (yintr1 , yintr2 ):
507
490
return False , False , None
508
491
509
492
axis = line1 .axis
@@ -544,7 +527,7 @@ def unshift_vec(vec):
544
527
545
528
pt = vector2 .Vector2 (l1_st_x , l2_st_y )
546
529
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 ):
548
531
return True , False , pt
549
532
else :
550
533
return False , True , pt
@@ -556,7 +539,7 @@ def unshift_vec(vec):
556
539
l1_min = min (l1_st_y , l1_en_y ) if offset1 is not None else line1 .min_y
557
540
l1_max = max (l1_st_y , l1_en_y ) if offset1 is not None else line1 .max_y
558
541
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 ):
560
543
return True , False , vector2 .Vector2 (l1_st_x , line2_y_at_line1_x )
561
544
elif line2_y_at_line1_x < l1_min or line2_y_at_line1_x > l2_max :
562
545
return False , False , None
@@ -571,7 +554,7 @@ def unshift_vec(vec):
571
554
l1_min = min (l1_st_x , l1_en_x ) if offset1 is not None else line1 .min_x
572
555
l1_max = max (l1_st_x , l1_en_x ) if offset1 is not None else line1 .max_x
573
556
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 ):
575
558
return True , False , vector2 .Vector2 (line2_x_at_line1_y , l1_st_y )
576
559
elif line2_x_at_line1_y < l1_min or line2_x_at_line1_y > l1_max :
577
560
return False , False , None
@@ -593,8 +576,8 @@ def unshift_vec(vec):
593
576
# Some caution needs to be taken here to ensure we do approximately before range
594
577
# checks. It's possible for _approx(a, b) to be True and a < b to be True
595
578
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 )
598
581
599
582
if on_edge1 and on_edge2 :
600
583
intr_y = line1 .slope * intr_x + yintr1
0 commit comments