@@ -484,18 +484,41 @@ def get_distance(self, other: Tuple[float, float]) -> float:
484
484
assert len (other ) == 2
485
485
return math .sqrt ((self .x - other [0 ]) ** 2 + (self .y - other [1 ]) ** 2 )
486
486
487
+ def get_distance_squared (self , other : Tuple [float , float ]) -> float :
488
+ """The squared distance between the vector and other vector.
489
+ It is more efficent to use this method than to call get_distance()
490
+ first and then do a square() on the result.
491
+
492
+ >>> Vec2d(1, 0).get_distance_squared((1, 10))
493
+ 100
494
+ >>> Vec2d(1, 2).get_distance_squared((10, 11))
495
+ 162
496
+ >>> Vec2d(1, 2).get_distance((10, 11))**2
497
+ 162.0
498
+ """
499
+ assert len (other ) == 2
500
+ return (self .x - other [0 ]) ** 2 + (self .y - other [1 ]) ** 2
501
+
487
502
def get_dist_sqrd (self , other : Tuple [float , float ]) -> float :
488
503
"""The squared distance between the vector and other vector.
489
504
It is more efficent to use this method than to call get_distance()
490
505
first and then do a square() on the result.
491
506
507
+ .. deprecated:: 7.0.0
508
+ Please use :py:func:`get_distance_squared` instead.
509
+
492
510
>>> Vec2d(1, 0).get_dist_sqrd((1, 10))
493
511
100
494
512
>>> Vec2d(1, 2).get_dist_sqrd((10, 11))
495
513
162
496
514
>>> Vec2d(1, 2).get_distance((10, 11))**2
497
515
162.0
498
516
"""
517
+ warnings .warn (
518
+ "get_dist_sqrd() is deprecated. Use get_distance_squared() instead." ,
519
+ category = DeprecationWarning ,
520
+ stacklevel = 2 ,
521
+ )
499
522
assert len (other ) == 2
500
523
return (self .x - other [0 ]) ** 2 + (self .y - other [1 ]) ** 2
501
524
0 commit comments