// The point 'p' does not need to be normalized. private void Init(S2CellId id) { _cellId = id; var ij = new int[2]; int?mOrientation = 0; for (var d = 0; d < 2; ++d) { ij[d] = 0; } _face = (byte)id.ToFaceIjOrientation(ref ij[0], ref ij[1], ref mOrientation); _orientation = (byte)mOrientation.Value; // Compress int to a byte. _level = (byte)id.Level; var cellSize = 1 << (S2CellId.MaxLevel - _level); for (var d = 0; d < 2; ++d) { // Compute the cell bounds in scaled (i,j) coordinates. var sijLo = (ij[d] & -cellSize) * 2 - MaxCellSize; var sijHi = sijLo + cellSize * 2; _uv[d][0] = S2Projections.StToUv((1.0 / MaxCellSize) * sijLo); _uv[d][1] = S2Projections.StToUv((1.0 / MaxCellSize) * sijHi); } }
/** * Convert (face, si, ti) coordinates (see s2.h) to a direction vector (not * necessarily unit length). */ private static S2Point FaceSiTiToXyz(int face, int si, int ti) { const double kScale = 1.0 / MaxSize; var u = S2Projections.StToUv(kScale * si); var v = S2Projections.StToUv(kScale * ti); return(S2Projections.FaceUvToXyz(face, u, v)); }