コード例 #1
0
ファイル: QuadTree.php プロジェクト: markbaker/quadtrees
 /**
  * Return an array of all points within this QuadTree and its child nodes that fall
  *    within the specified bounding box
  *
  * @param    QuadTreeBoundingBox    $boundary    The bounding box that we want to search
  * @return   QuadTreeXYPoint[]
  **/
 public function search(QuadTreeBoundingBox $boundary)
 {
     $results = array();
     if ($this->boundingBox->encompasses($boundary) || $this->boundingBox->intersects($boundary)) {
         // Test each point that falls within the current QuadTree node
         foreach ($this->points as $point) {
             // Test each point stored in this QuadTree node in turn, adding to the results array
             //    if it falls within the bounding box
             if ($boundary->containsPoint($point)) {
                 $results[] = $point;
             }
         }
         // If we have child QuadTree nodes....
         if (isset($this->northWest)) {
             // ... search each child node in turn, merging with any existing results
             $results = array_merge($results, $this->northWest->search($boundary), $this->northEast->search($boundary), $this->southWest->search($boundary), $this->southEast->search($boundary));
         }
     }
     return $results;
 }