Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function getDistance(int $point1 = null, int $point2 = null)
  2. {
  3.     if (! $this->existsPoints($point1, $point2)) {
  4.         throw new UnknownPointsSpecifiedException();
  5.     }
  6.  
  7.     return $this->getSquareForPoints($point1, $point2);
  8. }
  9.  
  10. protected function getSquareForPoints(int $point1, int $point2): float
  11. {
  12.     $p1 = $this->points[$point1];
  13.     $p2 = $this->points[$point2];
  14.  
  15.     return sqrt((float) (
  16.         pow(($p2[0] - $p1[0]), 2) +
  17.         pow(($p2[1] - $p1[1]), 2)
  18.     ));
  19. }
  20.  
  21. protected function existsPoints(int $point1 = null, int $point2 = null): bool
  22. {
  23.   return isset($this->points[$point1]) && isset($this->points[$point2]);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement