Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getDistance(int $point1 = null, int $point2 = null)
- {
- if (! $this->existsPoints($point1, $point2)) {
- throw new UnknownPointsSpecifiedException();
- }
- return $this->getSquareForPoints($point1, $point2);
- }
- protected function getSquareForPoints(int $point1, int $point2): float
- {
- $p1 = $this->points[$point1];
- $p2 = $this->points[$point2];
- return sqrt((float) (
- pow(($p2[0] - $p1[0]), 2) +
- pow(($p2[1] - $p1[1]), 2)
- ));
- }
- protected function existsPoints(int $point1 = null, int $point2 = null): bool
- {
- return isset($this->points[$point1]) && isset($this->points[$point2]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement