public function mayIntersect(S2Cell $cell)
 {
     // If the cap contains any cell vertex, return true.
     $vertices = array();
     for ($k = 0; $k < 4; ++$k) {
         $vertices[$k] = $cell->getVertex($k);
         if ($this->contains($vertices[$k])) {
             return true;
         }
     }
     return $this->intersects($cell, $vertices);
 }
 /**
  * This test is cheap but is NOT exact. Use Intersects() if you want a more
  * accurate and more expensive test. Note that when this method is used by an
  * S2RegionCoverer, the accuracy isn't all that important since if a cell may
  * intersect the region then it is subdivided, and the accuracy of this method
  * goes up as the cells get smaller.
  */
 public function mayIntersect(S2Cell $cell)
 {
     // This test is cheap but is NOT exact (see s2latlngrect.h).
     $rb = $cell->getRectBound();
     //      echo __METHOD__ . $cell . ' ' . $rb . "\n";
     return $this->intersects($rb);
 }
 /**
  * Populate the children of "candidate" by expanding the given number of
  * levels from the given cell. Returns the number of children that were marked
  * "terminal".
  */
 private function expandChildren(Candidate $candidate, S2Cell $cell, $numLevels)
 {
     $numLevels--;
     $childCells = array();
     for ($i = 0; $i < 4; ++$i) {
         $childCells[$i] = new S2Cell();
     }
     $cell->subdivide($childCells);
     $numTerminals = 0;
     for ($i = 0; $i < 4; ++$i) {
         if ($numLevels > 0) {
             if ($this->region->mayIntersect($childCells[$i])) {
                 $numTerminals += $this->expandChildren($candidate, $childCells[$i], $numLevels);
             }
             continue;
         }
         $child = $this->newCandidate($childCells[$i]);
         //        echo "child for " . $childCells[$i] . " is " . $child . "\n";
         if ($child != null) {
             $candidate->children[$candidate->numChildren++] = $child;
             if ($child->isTerminal) {
                 ++$numTerminals;
             }
         }
     }
     return $numTerminals;
 }