private function init(S2CellId $id) { $this->cellId = $id; $ij = array(0, 0); $mOrientation = 0; // echo " $mOrientation\n"; $this->face = $id->toFaceIJOrientation($ij[0], $ij[1], $mOrientation); // echo ">> $mOrientation\n"; $this->orientation = $mOrientation; $this->level = $id->level(); $cellSize = 1 << S2CellId::MAX_LEVEL - $this->level; for ($d = 0; $d < 2; ++$d) { // Compute the cell bounds in scaled (i,j) coordinates. $sijLo = ($ij[$d] & -$cellSize) * 2 - self::MAX_CELL_SIZE; $sijHi = $sijLo + $cellSize * 2; $this->uv[$d][0] = S2Projections::stToUV(1.0 / self::MAX_CELL_SIZE * $sijLo); $this->uv[$d][1] = S2Projections::stToUV(1.0 / self::MAX_CELL_SIZE * $sijHi); } }
/** * Public helper function that calls FromFaceIJ if sameFace is true, or * FromFaceIJWrap if sameFace is false. */ public static function fromFaceIJSame($face, $i, $j, $sameFace) { if ($sameFace) { return S2CellId::fromFaceIJ($face, $i, $j); } else { return S2CellId::fromFaceIJWrap($face, $i, $j); } }
/** 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); } }