Ejemplo n.º 1
0
 /**
  * @param Polygon $polygon
  * @param bool $inferOuter
  *
  * @return $this
  */
 public function addPolygon(Polygon $polygon, $inferOuter = true)
 {
     if (!$inferOuter) {
         $this->innerPolygons[] = $polygon;
     } else {
         if (count($this->points) === 0) {
             foreach ($polygon->getPoints() as $point) {
                 $this->points[] = $point;
             }
             $this->isHole = $polygon->isHole();
         } else {
             $this->addPolygon($polygon, false);
         }
     }
     //        $this->innerPolygons[] = $polygon;
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * @return Polygon
  */
 public function getResult()
 {
     $result = new Polygon();
     $numContours = $this->countContours();
     if ($numContours > 0) {
         /** @var PolygonNode $nPolyNode */
         $nPolyNode = null;
         for ($polyNode = $this->topNode; $polyNode != null; $polyNode = $nPolyNode) {
             $nPolyNode = $polyNode->getNext();
             if ($polyNode->getActive() != 0) {
                 $polygon = $result;
                 if ($numContours > 1) {
                     $polygon = new Polygon();
                 }
                 if ($polyNode->getProxy()->isHole()) {
                     $polygon->setIsHole($polyNode->getProxy()->isHole());
                 }
                 // --- This algorithm puts the verticies into the Polygon in
                 // reverse order ---
                 for ($vtx = $polyNode->getProxy()->getVertexList()[PolygonUtils::LEFT]; $vtx != null; $vtx = $vtx->getNext()) {
                     $polygon->addVertex(new Point($vtx->getX(), $vtx->getY()));
                 }
                 if ($numContours > 1) {
                     $result->addPolygon($polygon);
                 }
             }
         }
         // --- Sort holes to the end of the list ---
         $orig = $result;
         $result = new Polygon();
         for ($i = 0; $i < $orig->getNumInnerPoly(); $i++) {
             $inner = $orig->getInnerPolygon($i);
             if (!$inner->isHole()) {
                 $result->addPolygon($inner);
             }
         }
         for ($i = 0; $i < $orig->getNumInnerPoly(); $i++) {
             $inner = $orig->getInnerPolygon($i);
             if ($inner->isHole()) {
                 $result->addPolygon($inner);
             }
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * @param Polygon $polygon
  * @param int $i
  *
  * @return bool
  */
 private function isOptimal(Polygon $polygon, $i)
 {
     return $polygon->getInnerPolygon(0)->getPoints()[self::prevIndex($i, $polygon->nVertices())]->getY() != $polygon->getInnerPolygon(0)->getPoints()[$i]->getY() || $polygon->getInnerPolygon(0)->getPoints()[self::nextIndex($i, $polygon->nVertices())]->getY() != $polygon->getInnerPolygon(0)->getPoints()[$i]->getY();
 }