Calculate and record the number of edge pixels left to do on each tile
188144
def fill_n_todo(self):
        
        left = self.left
        right = self.right
        top = self.top
        bottom = self.bottom
        for i in xrange(self.n_chunks):
            self.n_todo.ravel()[i] = np.sum([left.ravel()[i].n_todo,
                                            right.ravel()[i].n_todo,
                                            top.ravel()[i].n_todo,
                                            bottom.ravel()[i].n_todo])
332319
private ArrayList<Rect> calculateAllBounds(Paint paint) {
        ArrayList<Rect> list = new ArrayList<Rect>();
        //For each views (If no values then add a fake one)
        final int count = mRecyclerView.getAdapter().getItemCount();
        final int width = getWidth();
        final int halfWidth = width / 2;
        for (int i = 0; i < count; i++) {
            Rect bounds = calcBounds(i, paint);
            int w = bounds.right - bounds.left;
            int h = bounds.bottom - bounds.top;
            bounds.left = (int)(halfWidth - (w / 2f) + ((i - mCurrentPage - mPageOffset) * width));
            bounds.right = bounds.left + w;
            bounds.top = 0;
            bounds.bottom = h;
            list.add(bounds);
        }

        return list;
    }
535882
def _count_truth_pixels(self):
        
        pixel_count = np.array([[np.nonzero(mask)[0].shape[0] for mask in masktype]
                                for masktype in self.truth_masks])

        pixel_count = np.moveaxis(pixel_count, 0, -1)

        if self.pixel_truth_counts is None:
            self.pixel_truth_counts = np.copy(pixel_count)
        else:
            self.pixel_truth_counts = np.concatenate((self.pixel_truth_counts, pixel_count))
136678
private int countTiles(int widthInTile, int step, int s)
    {
        int count = 0;
        for (int tx = 0; tx < widthInTile; tx++)
        {
            for (int ty = 0; ty < map.getInTileHeight(); ty++)
            {
                if (map.getTile(tx + s * step, ty) != null)
                {
                    count++;
                }
            }
        }
        return count;
    }
782240
function tileRsys (x, y, z) {
    let max = Math.pow(2, z);
    return { scale: 1 / max, center: { x: 2 * (x + 0.5) / max - 1, y: 1 - 2 * (y + 0.5) / max } };
}
559698
function() {
          return {
            tileCount: tileSpans.length,
            layoutTime: layoutTime,
            mapTime: mapTime,
            reflowTime: reflowTime,
            totalTime: layoutTime + mapTime + reflowTime
          };
        }
51948
public double[] TileBounds( int tx, int ty, int zoom ) {
        double[] min = PixelsToMeters(tx * tileSize, ty * tileSize, zoom);
        double minx = min[0], miny = min[1];
        double[] max = PixelsToMeters((tx + 1) * tileSize, (ty + 1) * tileSize, zoom);
        double maxx = max[0], maxy = max[1];
        return new double[]{minx, miny, maxx, maxy};
    }
483452
function () {
            var /** @type {?} */ lastRowMax = Math.max.apply(Math, this.tracker);
            // if any of the tiles has a rowspan that pushes it beyond the total row count,
            // add the difference to the rowcount
            return lastRowMax > 1 ? this.rowCount + lastRowMax - 1 : this.rowCount;
        }
647013
def _calc_grad_tiled(self, img, t_grad, tile_size=512):
        ''''''
        sz = tile_size
        h, w = img.shape[:2]
        sx, sy = np.random.randint(sz, size=2)
        img_shift = np.roll(np.roll(img, sx, 1), sy, 0)
        grad = np.zeros_like(img)
        for y in range(0, max(h-sz//2, sz),sz):
            for x in range(0, max(w-sz//2, sz),sz):
                sub = img_shift[y:y+sz,x:x+sz]
                g = self._session.run(t_grad, {self._t_input:sub})
                grad[y:y+sz,x:x+sz] = g
        return np.roll(np.roll(grad, -sx, 1), -sy, 0)
183941
def count_filled_positions(self):
        
        filled = 0
        for row_ndx in range(self.grid_height - 0):
            for col_ndx in range(self.grid_width - 0):
                if self.get_tile(row_ndx, col_ndx) != EMPTY:
                    filled += 1
        return filled
1186598
def bounds(self, pixelbuffer=0):
        
        left = self._left
        bottom = self._bottom
        right = self._right
        top = self._top
        if pixelbuffer:
            offset = self.pixel_x_size * float(pixelbuffer)
            left -= offset
            bottom -= offset
            right += offset
            top += offset
        # on global grids clip at northern and southern TilePyramid bound
        if self.tp.grid.is_global:
            top = min([top, self.tile_pyramid.top])
            bottom = max([bottom, self.tile_pyramid.bottom])
        return Bounds(left, bottom, right, top)
1370217
def _global_tiles_from_bounds(tp, bounds, zoom):
    """"""
    seen = set()

    # clip to tilepyramid top and bottom bounds
    left, right = bounds.left, bounds.right
    top = tp.top if bounds.top > tp.top else bounds.top
    bottom = tp.bottom if bounds.bottom < tp.bottom else bounds.bottom

    if left >= tp.left and right <= tp.right:
        for tile in _tiles_from_cleaned_bounds(tp, bounds, zoom):
            yield tile

    # bounds overlap on the Western side with antimeridian
    if left < tp.left:
        for tile in chain(
            # tiles west of antimeridian
            _tiles_from_cleaned_bounds(
                tp,
                Bounds(left + (tp.right - tp.left), bottom, tp.right, top),
                zoom
            ),
            # tiles east of antimeridian
            _tiles_from_cleaned_bounds(
                tp, Bounds(tp.left, bottom, right, top), zoom
            )
        ):
            # make output tiles unique
            if tile.id not in seen:
                seen.add(tile.id)
                yield tile

    # bounds overlap on the Eastern side with antimeridian
    if right > tp.right:
        for tile in chain(
            # tiles west of antimeridian
            _tiles_from_cleaned_bounds(
                tp, Bounds(left, bottom, tp.right, top), zoom
            ),
            # tiles east of antimeridian
            _tiles_from_cleaned_bounds(
                tp,
                Bounds(tp.left, bottom, right - (tp.right - tp.left), top),
                zoom
            )
        ):
            # make output tiles unique
            if tile.id not in seen:
                seen.add(tile.id)
                yield tile
1106593
function (tilemapLayer, tiles) {
		let i, layerData = tilemapLayer.layer;
		
		// Pre-process the tiles
		for (i in tiles) {
			let tile = tiles[i];
			
			tile.physics.slopes = tile.physics.slopes || {};
			
			tile.physics.slopes = {
				neighbours: {
					up: GetTileAt(tile.x, tile.y - 1, true, layerData),
					down: GetTileAt(tile.x, tile.y + 1, true, layerData),
					left: GetTileAt(tile.x - 1, tile.y, true, layerData),
					right: GetTileAt(tile.x + 1, tile.y, true, layerData),
					topLeft: GetTileAt(tile.x - 1, tile.y - 1, true, layerData),
					topRight: GetTileAt(tile.x + 1, tile.y - 1, true, layerData),
					bottomLeft: GetTileAt(tile.x - 1, tile.y + 1, true, layerData),
					bottomRight: GetTileAt(tile.x + 1, tile.y + 1, true, layerData),
				},
				edges: {
					top: Constants.INTERESTING,
					bottom: Constants.INTERESTING,
					left: Constants.INTERESTING,
					right: Constants.INTERESTING
				}
			};
		}
		
		// Calculate boundary edges
		this.calculateBoundaryEdges(tiles);
		
		// Flag internal edges
		this.flagInternalEdges(tiles);
		
		// Build ghost edges and flag ignormals
		this.flagIgnormals(tiles);
	}
1218887
def tile_to_pixel(tile, centered=False):
        """"""
        pixel = [tile[0] * 256, tile[1] * 256]
        if centered:
            # should clip on max map size
            pixel = [pix + 128 for pix in pixel]
        return pixel[0], pixel[1]
1097381
def _tiles_from_cleaned_bounds(tp, bounds, zoom):
    """"""
    lb = _tile_from_xy(tp, bounds.left, bounds.bottom, zoom, on_edge_use="rt")
    rt = _tile_from_xy(tp, bounds.right, bounds.top, zoom, on_edge_use="lb")
    for tile_id in product([zoom], range(rt.row, lb.row + 1), range(lb.col, rt.col + 1)):
        yield tp.tile(*tile_id)
1331705
def _num2deg(self, tile):
        
        n = 2.0 ** tile.zoom
        lon_deg = tile.x / n * 360.0 - 180.0
        lat_rad = mod_math.atan(mod_math.sinh(mod_math.pi * (1 - 2 * tile.y / n)))
        lat_deg = mod_math.degrees(lat_rad)
        return (lat_deg, lon_deg)
355868
function (tiles) {
		const maxDist = 5;
		
		let t, tile, tileBody, tileVertices, n, neighbour, neighbourBody, neighbourVertices, i, j, tv0, tv1, tv2, tv3, nv1, nv2, edge;
		
		for (t = 0; t < tiles.length; t++) {
			tile = tiles[t];
			
			// Skip over irrelevant tiles
			if (isIrrelevant(tile)) {
				continue;
			}
			
			// Grab the tile's body and vertices to build its edges and compare with neighbours
			tileBody = tile.physics.matterBody.body;
			tileVertices = tileBody.vertices;
			
			tileBody.edges = [];
			tileBody.ignormals = [];
			
			for (i = 0; i < tileVertices.length; i++) {
				tv1 = tileVertices[i];
				tv2 = tileVertices[(i + 1) % tileVertices.length];
				
				// Find or build the edge for this tile vertex
				edge = tileBody.edges[i];
				
				// Build the edge
				edge = buildEdge(tv1, tv2, tileBody);
				edge.ignore = tv1.isInternal;
				
				// Add it to the tile's edge list
				tileBody.edges[i] = edge;
			}
			
			for (n in tile.physics.slopes.neighbours) {
				neighbour = tile.physics.slopes.neighbours[n];
				
				// Skip over irrelevant neighbouring tiles
				if (isIrrelevant(neighbour)) {
					continue;
				}
				
				// Grab the neighbour's body and vertices
				neighbourBody = neighbour.physics.matterBody.body;
				neighbourVertices = neighbourBody.vertices;
				
				// Skip over tile-neighbour pairs that don't overlap
				if (!Bounds.overlaps(tileBody.bounds, neighbourBody.bounds)) {
					continue;
				}
				
				// Iterate over the vertices of both the tile and its neighbour
				for (i = 0; i < tileVertices.length; i++) {
					tv1 = tileVertices[i];
					tv2 = tileVertices[(i + 1) % tileVertices.length];
					
					// Find the edge for this tile vertex
					edge = tileBody.edges[i];
					
					// Find neighbouring edges leading into this vertex
					for (j = 0; j < neighbourVertices.length; j++) {
						nv1 = neighbourVertices[j];
						nv2 = neighbourVertices[(j + 1) % neighbourVertices.length];
						
						// Skip internal neighbouring edges
						if (nv1.isInternal) {
							continue;
						}
						
						// Check for a leading or trailing ghost edges
						let leadingEdge = distance(tv1, nv2) < maxDist;
						let trailingEdge = distance(tv2, nv1) < maxDist;
						
						if (leadingEdge || trailingEdge) {
							// Add leading/trailing edge vertices
							if (leadingEdge && !edge.vertices[0]) {
								edge.vertices[0] = buildEdgeVertex(0, nv1.x, nv1.y, tileBody, true);
								
								// Link edges to each other
								if (neighbourBody.edges) {
									edge.prev = neighbourBody.edges[j];
									neighbourBody.edges[j].next = edge;
								}
							}
							
							if (trailingEdge && !edge.vertices[3]) {
								edge.vertices[3] = buildEdgeVertex(3, nv2.x, nv2.y, tileBody, true);
							}
							
							// Find the ignormals
							let ignormalVertex = leadingEdge ? nv2 : nv1;
							let tileEdgeNormal = tileBody.axes[i];
							let neighbourEdgeNormal = neighbourBody.axes[j];
							let ignormalCandidate = Vector.dot(tileEdgeNormal, neighbourEdgeNormal) > 0;// && !isAxisAligned(tileEdgeNormal) && !isAxisAligned(neighbourEdgeNormal);
							
							// If the tile edge normal and its neighbouring ghost edge normal are less than
							// 90 degrees different, we can set ignormals based on which bounds the joining
							// vertex lands on
							if (ignormalCandidate) {
								/**
								 * If the joining vertex is on a bounds edge, and the normal of its edge and the
								 * the neighbouring edge are not exactly the same as the corresponding direction
								 * constant, we can add an axis aligned ignormal
								 */
								
								// Leftwards ignormal
								if (Math.abs(ignormalVertex.x - tileBody.bounds.min.x) < 1 && !containsNormal(Constants.Directions.LEFT, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.LEFT) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.LEFT) < 1) {
									tileBody.ignormals.push(Constants.Directions.LEFT);
								}
								
								// Upwards ignormal
								if (Math.abs(ignormalVertex.y - tileBody.bounds.min.y) < 1 && !containsNormal(Constants.Directions.UP, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.UP) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.UP) < 1) {
									tileBody.ignormals.push(Constants.Directions.UP);
								}
								
								// Rightwards ignormal
								if (Math.abs(ignormalVertex.x - tileBody.bounds.max.x) < 1 && !containsNormal(Constants.Directions.RIGHT, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.RIGHT) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.RIGHT) < 1) {
									tileBody.ignormals.push(Constants.Directions.RIGHT);
								}
								
								// Downwards ignormal
								if (Math.abs(ignormalVertex.y - tileBody.bounds.max.y) < 1 && !containsNormal(Constants.Directions.DOWN, tileBody.axes) && Vector.dot(tileEdgeNormal, Constants.Directions.DOWN) < 1 && Vector.dot(neighbourEdgeNormal, Constants.Directions.DOWN) < 1) {
									tileBody.ignormals.push(Constants.Directions.DOWN);
								}
							}
						}
					}
				}
			}
			
			// Resolve edge normal data, now that we've seen all the neighbours
			// and ensure ghost vertices are set on each edge
			for (i = 0; i < tileVertices.length; i++) {
				edge = tileBody.edges[i];
				
				if (edge.ignore) {
					continue;
				}
				
				tv0 = tileVertices[((i - 1) % tileVertices.length + tileVertices.length) % tileVertices.length];
				tv1 = tileVertices[i];
				tv2 = tileVertices[(i + 1) % tileVertices.length];
				tv3 = tileVertices[(i + 2) % tileVertices.length];
				
				// Use this body's vertices as ghost vertices if neighbours
				// haven't provided them, and if they aren't internal edges
				if (!edge.vertices[0] && !tv0.isInternal) {
					edge.vertices[0] = buildEdgeVertex(0, tv0.x, tv0.y, tileBody, true);
				}
				
				if (!edge.vertices[3] && !tv2.isInternal) {
					edge.vertices[3] = buildEdgeVertex(3, tv3.x, tv3.y, tileBody, true);
				}
				
				// Calculate edge normals
				edge.normals = Axes.fromVertices(edge.vertices);
				
				// Calculate edge normal ranges
				buildEdgeNormalRanges(edge);
			}
		}
	}