Exemplo n.º 1
0
 /**
  * Insert a new point into this QuadTree node
  *
  * @param    QuadTreeXYPoint    $point    The new point to insert in this QuadTree node
  * @return   boolean
  **/
 public function insert(QuadTreeXYPoint $point)
 {
     if (!$this->boundingBox->containsPoint($point)) {
         return false;
     }
     if (count($this->points) < $this->maxPoints) {
         // If we still have spaces in the bucket array for this QuadTree node,
         //    then the point simply goes here and we're finished
         $this->points[] = $point;
         return true;
     } elseif (!isset($this->northWest)) {
         // Otherwise we split this node into NW/NE/SE/SW quadrants
         $this->subdivide();
     }
     // Insert the point into the appropriate quadrant, and finish
     if ($this->northWest->insert($point) || $this->northEast->insert($point) || $this->southWest->insert($point) || $this->southEast->insert($point)) {
         return true;
     }
     // If we couldn't insert the new point, then we have an exception situation
     throw new \OutOfBoundsException('Point is outside bounding box');
 }