Example #1
0
 /**
  * Checks if coordinates are inside the field
  *
  * @param Coords $coords
  * @return bool
  */
 public function has(Coords $coords)
 {
     $x = $coords->x();
     if ($x < 0 || $x >= $this->width) {
         return false;
     }
     $y = $coords->y();
     if ($y < 0 || $y >= $this->height) {
         return false;
     }
     return true;
 }
Example #2
0
 /**
  * @param Coords $coords
  * @return bool
  */
 public function on(Coords $coords)
 {
     if ($coords->x() == $this->startPoint->x() && $coords->y() >= $this->startPoint->y() && $coords->y() <= $this->endPoint->y()) {
         return true;
     }
     if ($coords->y() == $this->startPoint->y() && $coords->x() >= $this->startPoint->x() && $coords->x() <= $this->endPoint->x()) {
         return true;
     }
     return false;
 }
Example #3
0
 /**
  * @param Coords $coords
  *
  * @return integer
  */
 public function distance(Coords $coords)
 {
     if ($this->x == $coords->x()) {
         return abs($this->y - $coords->y());
     }
     if ($this->y == $coords->y()) {
         return abs($this->x - $coords->x());
     }
     throw new CannotCalculateDistanceBetweenDiagonalCoordsException();
 }