Computes quadKey value based on tile x, y and z values.
540965
def tileXYZToQuadKey(self, x, y, z):
        '''
        
        '''
        quadKey = ''
        for i in range(z, 0, -1):
            digit = 0
            mask = 1 << (i - 1)
            if (x & mask) != 0:
                digit += 1
            if (y & mask) != 0:
                digit += 2
            quadKey += str(digit)
        return quadKey
159450
def generate_unit_squares(image_width, image_height):
    """"""
    # Iterate over the required rows and cells.  The for loops (x, y)
    # give the coordinates of the top left-hand corner of each square:
    #
    #      (x, y) +-----+ (x + 1, y)
    #             |     |
    #             |     |
    #             |     |
    #  (x, y + 1) +-----+ (x + 1, y + 1)
    #
    for x in range(image_width):
        for y in range(image_height):
            yield [(x, y), (x + 1, y), (x + 1, y + 1), (x, y + 1)]
443379
def get_tile_properties(self, x, y, layer):
        
        try:
            assert (x >= 0 and y >= 0 and layer >= 0)
        except AssertionError:
            raise ValueError

        try:
            gid = self.layers[int(layer)].data[int(y)][int(x)]
        except (IndexError, ValueError):
            msg = "Coords: ({0},{1}) in layer {2} is invalid."
            logger.debug(msg.format(x, y, layer))
            raise Exception

        else:
            try:
                return self.tile_properties[gid]
            except (IndexError, ValueError):
                msg = "Coords: ({0},{1}) in layer {2} has invalid GID: {3}"
                logger.debug(msg.format(x, y, layer, gid))
                raise Exception
            except KeyError:
                return None
579127
def quadKeyToTileXYZ(self, quadKey):
        '''
        
        '''
        tileX = 0
        tileY = 0
        tileZ = len(quadKey)

        for i in range(tileZ, 0, -1):
            mask = 1 << (i - 1)
            value = quadKey[tileZ - i]

            if value == '0':
                continue

            elif value == '1':
                tileX |= mask

            elif value == '2':
                tileY |= mask

            elif value == '3':
                tileX |= mask
                tileY |= mask

            else:
                raise Exception('Invalid QuadKey')

        return (tileX, tileY, tileZ)
128890
def _tile_intersecting_tilepyramid(tile, tp):
    """"""
    if tile.tp.grid != tp.grid:
        raise ValueError("Tile and TilePyramid source grids must be the same.")
    tile_metatiling = tile.tile_pyramid.metatiling
    pyramid_metatiling = tp.metatiling
    multiplier = tile_metatiling / pyramid_metatiling
    if tile_metatiling > pyramid_metatiling:
        return [
            tp.tile(
                tile.zoom,
                int(multiplier) * tile.row + row_offset,
                int(multiplier) * tile.col + col_offset
            )
            for row_offset, col_offset in product(
                range(int(multiplier)), range(int(multiplier))
            )
        ]
    elif tile_metatiling < pyramid_metatiling:
        return [tp.tile(
            tile.zoom, int(multiplier * tile.row), int(multiplier * tile.col)
        )]
    else:
        return [tp.tile(*tile.id)]
946180
private void ekskey(final byte data[], final byte key[]) {
        int i;
        final int koffp[] = {0}, doffp[] = {0};
        final int lr[] = {0, 0};
        final int plen = P.length, slen = S.length;

        for (i = 0; i < plen; i++) {
            P[i] = P[i] ^ streamtoword(key, koffp);
        }

        for (i = 0; i < plen; i += 2) {
            lr[0] ^= streamtoword(data, doffp);
            lr[1] ^= streamtoword(data, doffp);
            encipher(lr, 0);
            P[i] = lr[0];
            P[i + 1] = lr[1];
        }

        for (i = 0; i < slen; i += 2) {
            lr[0] ^= streamtoword(data, doffp);
            lr[1] ^= streamtoword(data, doffp);
            encipher(lr, 0);
            S[i] = lr[0];
            S[i + 1] = lr[1];
        }
    }
1160831
private void CalculateMap(IntRange inRange, IntRange outRange, int[] map) {
        double k = 0, b = 0;

        if (inRange.getMax() != inRange.getMin()) {
            k = (double) (outRange.getMax() - outRange.getMin()) / (double) (inRange.getMax() - inRange.getMin());
            b = (double) (outRange.getMin()) - k * inRange.getMin();
        }

        for (int i = 0; i < 256; i++) {
            int v = (int) i;

            if (v >= inRange.getMax())
                v = outRange.getMax();
            else if (v <= inRange.getMin())
                v = outRange.getMin();
            else
                v = (int) (k * v + b);

            map[i] = v;
        }
    }
671359
def get_xyz_2d(self, xcoord, x, ycoord, y, u, v):
        """"""
        xy = xcoord.values.ravel() + 1j * ycoord.values.ravel()
        dist = np.abs(xy - (x + 1j * y))
        imin = np.nanargmin(dist)
        xy_min = xy[imin]
        return (xy_min.real, xy_min.imag, u.values.ravel()[imin],
                v.values.ravel()[imin])
537914
@Override
	public void compute(double x, double y, Point2D_F64 out) {
		narrowToNorm.compute(x,y, norm);

		// Convert from 2D homogenous to 3D
		unit.set( norm.x , norm.y , 1.0);

		// Rotate then make it a unit vector
		GeometryMath_F64.mult(rotateWideToNarrow,unit,unit);
		double n = unit.norm();
		unit.x /= n;
		unit.y /= n;
		unit.z /= n;

		unitToWide.compute(unit.x,unit.y,unit.z,out);
	}
1037251
def _get_vector_tile(self, x_tile, y_tile, z_tile):
        """"""
        cache_file = "mapscache/{}.{}.{}.json".format(z_tile, x_tile, y_tile)
        if cache_file not in self._tiles:
            if os.path.isfile(cache_file):
                with open(cache_file, 'rb') as f:
                    tile = json.loads(f.read().decode('utf-8'))
            else:
                url = _VECTOR_URL.format(z_tile, x_tile, y_tile, _KEY)
                data = requests.get(url).content
                try:
                    tile = mapbox_vector_tile.decode(data)
                    with open(cache_file, mode='w') as f:
                        json.dump(literal_eval(repr(tile)), f)
                except DecodeError:
                    tile = None
            if tile:
                self._tiles[cache_file] = [x_tile, y_tile, z_tile, tile, False]
                if len(self._tiles) > _CACHE_SIZE:
                    self._tiles.popitem(False)
                self._screen.force_update()
778930
protected String quadTree(final long pMapTileIndex) {
		final StringBuilder quadKey = new StringBuilder();
		for (int i = MapTileIndex.getZoom(pMapTileIndex); i > 0; i--) {
			int digit = 0;
			final int mask = 1 << (i - 1);
			if ((MapTileIndex.getX(pMapTileIndex) & mask) != 0)
				digit += 1;
			if ((MapTileIndex.getY(pMapTileIndex) & mask) != 0)
				digit += 2;
			quadKey.append("" + digit);
		}

		return quadKey.toString();
	}
19212
function (x, y, v) {
            var ret = v || new me.Vector2d();

            var alignedX = x,
                alignedY = y;

            if (this.staggerX) {
                alignedX -= this.staggerEven ? this.sideoffsetx : 0;
            } else {
                alignedY -= this.staggerEven ? this.sideoffsety : 0;
            }

            // Start with the coordinates of a grid-aligned tile
            var referencePoint = me.pool.pull("me.Vector2d",
                Math.floor(alignedX / this.tilewidth),
                Math.floor(alignedY / this.tileheight)
            );

            // Adjust the reference point to the correct tile coordinates
            if (this.staggerX) {
                referencePoint.x = referencePoint.x * 2;
                if (this.staggerEven) {
                    ++referencePoint.x;
                }
            } else {
                referencePoint.y = referencePoint.y * 2;
                if (this.staggerEven) {
                    ++referencePoint.y;
                }
            }

            // Relative x and y position on the base square of the grid-aligned tile
            var rel = me.pool.pull("me.Vector2d",
                alignedX - referencePoint.x * this.tilewidth,
                alignedY - referencePoint.y * this.tileheight
            );

            // Check whether the cursor is in any of the corners (neighboring tiles)
            var y_pos = rel.x * (this.tileheight / this.tilewidth);

            if (this.sideoffsety - y_pos > rel.y) {
                referencePoint = this.topLeft(referencePoint.x, referencePoint.y, referencePoint);
            }
            if (-this.sideoffsety + y_pos > rel.y) {
                referencePoint = this.topRight(referencePoint.x, referencePoint.y, referencePoint);
            }
            if (this.sideoffsety + y_pos < rel.y) {
                referencePoint = this.bottomLeft(referencePoint.x, referencePoint.y, referencePoint);
            }
            if (this.sideoffsety * 3 - y_pos < rel.y) {
                referencePoint = this.bottomRight(referencePoint.x, referencePoint.y, referencePoint);
            }

            ret = this.tileToPixelCoords(referencePoint.x, referencePoint.y, ret);

            ret.set(x - ret.x, y - ret.y);

            // Start with the coordinates of a grid-aligned tile
            ret.set(
                ret.x - (this.tilewidth / 2),
                ret.y * (this.tilewidth / this.tileheight)
            );

            ret.div(this.tilewidth / Math.sqrt(2)).rotate(me.Math.degToRad(-45)).add(referencePoint);

            me.pool.push(referencePoint);
            me.pool.push(rel);

            return ret;
        }
859954
def quadkey_to_tile(quadkey):
        """"""
        tile_x, tile_y = (0, 0)
        level = len(quadkey)
        for i in xrange(level):
            bit = level - i
            mask = 1 << (bit - 1)
            if quadkey[level - bit] == '1':
                tile_x |= mask
            if quadkey[level - bit] == '2':
                tile_y |= mask
            if quadkey[level - bit] == '3':
                tile_x |= mask
                tile_y |= mask
        return [(tile_x, tile_y), level]
1170212
public static boolean check(Tile tile1, Tile tile2, Tile tile3, Tile tile4) {
        return tile1 == tile2 && tile2 == tile3 && tile3 == tile4;
    }
1043052
def for_pixels(cls, pixel_x, pixel_y, zoom):
        """"""
        tms_x = int(math.ceil(pixel_x / float(TILE_SIZE)) - 1)
        tms_y = int(math.ceil(pixel_y / float(TILE_SIZE)) - 1)
        return cls(tms_x=tms_x, tms_y=(2 ** zoom - 1) - tms_y, zoom=zoom)
996999
function tileToBBOX(tile) {
    var e = tile2lon(tile[0] + 1, tile[2]);
    var w = tile2lon(tile[0], tile[2]);
    var s = tile2lat(tile[1] + 1, tile[2]);
    var n = tile2lat(tile[1], tile[2]);
    return [w, s, e, n];
}
119313
def ijk_to_xyz(dset,ijk):
    ''''''
    i = nl.dset_info(dset)
    orient_codes = [int(x) for x in nl.run(['@AfniOrient2RAImap',i.orient]).output.split()]
    orient_is = [abs(x)-1 for x in orient_codes]
    rai = []
    for rai_i in xrange(3):
         ijk_i = orient_is[rai_i]
         if orient_codes[rai_i] > 0:
             rai.append(ijk[ijk_i]*i.voxel_size[rai_i] + i.spatial_from[rai_i])
         else:
             rai.append(i.spatial_to[rai_i] - ijk[ijk_i]*i.voxel_size[rai_i])
    return rai