private function getLongitude($i, $j) { $p = S2Projections::faceUvToXyz($this->face, $this->uv[0][$i], $this->uv[1][$j]); return atan2($p->y, $p->x); }
/** * Given (i, j) coordinates that may be out of bounds, normalize them by * returning the corresponding neighbor cell on an adjacent face. */ private static function fromFaceIJWrap($face, $i, $j) { // Convert i and j to the coordinates of a leaf cell just beyond the // boundary of this face. This prevents 32-bit overflow in the case // of finding the neighbors of a face cell, and also means that we // don't need to worry about the distinction between (s,t) and (u,v). $i = max(-1, min(self::MAX_SIZE, $i)); $j = max(-1, min(self::MAX_SIZE, $j)); // Find the (s,t) coordinates corresponding to (i,j). At least one // of these coordinates will be just outside the range [0, 1]. $kScale = 1.0 / self::MAX_SIZE; $s = $kScale * (($i << 1) + 1 - self::MAX_SIZE); $t = $kScale * (($j << 1) + 1 - self::MAX_SIZE); // Find the leaf cell coordinates on the adjacent face, and convert // them to a cell id at the appropriate level. $p = S2Projections::faceUvToXyz($face, $s, $t); $face = S2Projections::xyzToFace($p); $st = S2Projections::validFaceXyzToUv($face, $p); return self::fromFaceIJ($face, self::stToIJ($st->x()), self::stToIJ($st->y())); }
/** 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); } }