コード例 #1
0
ファイル: Rectangle.php プロジェクト: babkinandreyhm/polygon
 /**
  * @param PointInterface $point
  *
  * @return bool
  */
 public function isInside(PointInterface $point)
 {
     $px = $point->getX();
     $py = $point->getY();
     if ($px >= $this->topLeftX && $px <= $this->topLeftX + $this->width && $py >= $this->topLeftY && $py <= $this->topLeftY + $this->height) {
         return true;
     }
     return false;
 }
コード例 #2
0
ファイル: Polygon.php プロジェクト: babkinandreyhm/polygon
 /**
  * @param PointInterface $point
  * @link http://alienryderflex.com/polygon/
  *
  * @return bool
  */
 public function isInside(PointInterface $point)
 {
     $isClosed = $this->isClosed();
     if (!$isClosed) {
         $this->close();
     }
     $isOdd = false;
     for ($polygonIndex = 0; $polygonIndex < $this->getNumInnerPoly(); $polygonIndex++) {
         $vertices = $this->getInnerPolygon($polygonIndex)->getVertices();
         $vertexCount = count($vertices) - 1;
         for ($vertexIndex = 0; $vertexIndex < $vertexCount + 1; $vertexIndex++) {
             $y = $point->getY();
             if ($vertices[$vertexIndex]->getY() < $y && $vertices[$vertexCount]->getY() >= $y || $vertices[$vertexCount]->getY() < $y && $vertices[$vertexIndex]->getY() >= $y) {
                 if ($vertices[$vertexIndex]->getX() + ($point->getY() - $vertices[$vertexIndex]->getY()) / ($vertices[$vertexCount]->getY() - $vertices[$vertexIndex]->getY()) * ($vertices[$vertexCount]->getX() - $vertices[$vertexCount]->getX()) < $point->getX()) {
                     $isOdd = !$isOdd;
                 }
             }
         }
     }
     if ($isClosed) {
         $this->open();
     }
     return $isOdd;
 }