/** * Default constructor used only internally. */ public function __construct($p = null) { if ($p instanceof S2Point) { $this->init(S2CellId::fromPoint($p)); } else { if ($p instanceof S2LatLng) { $this->init(S2CellId::fromLatLng($p)); } else { if ($p instanceof S2CellId) { $this->init($p); } } } }
/** Computes a set of initial candidates that cover the given region. */ private function getInitialCandidates() { // Optimization: if at least 4 cells are desired (the normal case), // start with a 4-cell covering of the region's bounding cap. This // lets us skip quite a few levels of refinement when the region to // be covered is relatively small. if ($this->maxCells >= 4) { // Find the maximum level such that the bounding cap contains at most one // cell vertex at that level. $cap = $this->region->getCapBound(); $level = min(S2Projections::MIN_WIDTH()->getMaxLevel(2 * $cap->angle()->radians()), min($this->maxLevel(), S2CellId::MAX_LEVEL - 1)); if ($this->levelMod() > 1 && $level > $this->minLevel()) { $level -= ($level - $this->minLevel()) % $this->levelMod(); } // We don't bother trying to optimize the level == 0 case, since more than // four face cells may be required. if ($level > 0) { // Find the leaf cell containing the cap axis, and determine which // subcell of the parent cell contains it. /** @var S2CellId[] $base */ $base = array(); $s2point_tmp = $cap->axis(); $id = S2CellId::fromPoint($s2point_tmp); $id->getVertexNeighbors($level, $base); for ($i = 0; $i < count($base); ++$i) { // printf("(face=%s pos=%s level=%s)\n", $base[$i]->face(), dechex($base[$i]->pos()), $base[$i]->level()); // echo "new S2Cell(base[i])\n"; $cell = new S2Cell($base[$i]); // echo "neighbour cell: " . $cell . "\n"; $c = $this->newCandidate($cell); // if ($c !== null) // echo "addCandidato getInitialCandidates: " . $c->cell->id() . "\n"; $this->addCandidate($c); } // echo "\n\n\n"; return; } } // Default: start with all six cube faces. $face_cells = self::FACE_CELLS(); for ($face = 0; $face < 6; ++$face) { $c = $this->newCandidate($face_cells[$face]); echo "addCandidato getInitialCandidates_default: " . $c->cell->id() . "\n"; $this->addCandidate($c); } }