Take a raster and return a polygon representing the outer edge.
480982
def raster_to_shape(raster):
    """"""
    left = raster.bounds.left
    right = raster.bounds.right
    top = raster.bounds.top
    bottom = raster.bounds.bottom

    top_left = (left, top)
    top_right = (right, top)
    bottom_left = (left, bottom)
    bottom_right = (right, bottom)

    return Polygon((
        top_left, top_right, bottom_right, bottom_left, top_left,
    ))
772616
def boundary_polygon(self, time):
        
        ti = np.where(time == self.times)[0][0]
        com_x, com_y = self.center_of_mass(time)
        # If at least one point along perimeter of the mask rectangle is unmasked, find_boundaries() works.
        # But if all perimeter points are masked, find_boundaries() does not find the object.
        # Therefore, pad the mask with zeroes first and run find_boundaries on the padded array.
        padded_mask = np.pad(self.masks[ti], 1, 'constant', constant_values=0)
        chull = convex_hull_image(padded_mask)
        boundary_image = find_boundaries(chull, mode='inner', background=0)
        # Now remove the padding.
        boundary_image = boundary_image[1:-1,1:-1]
        boundary_x = self.x[ti].ravel()[boundary_image.ravel()]
        boundary_y = self.y[ti].ravel()[boundary_image.ravel()]
        r = np.sqrt((boundary_x - com_x) ** 2 + (boundary_y - com_y) ** 2)
        theta = np.arctan2((boundary_y - com_y), (boundary_x - com_x)) * 180.0 / np.pi + 360
        polar_coords = np.array([(r[x], theta[x]) for x in range(r.size)], dtype=[('r', 'f4'), ('theta', 'f4')])
        coord_order = np.argsort(polar_coords, order=['theta', 'r'])
        ordered_coords = np.vstack([boundary_x[coord_order], boundary_y[coord_order]])
        return ordered_coords
116989
def bounding_polygon(self):
        
        lon_left, lat_bottom, lon_right, lat_top = Tile.tile_coords_to_bbox(self.x, self.y, self.zoom)
        print(lon_left, lat_bottom, lon_right, lat_top)
        return Polygon([[[lon_left, lat_top],
                       [lon_right, lat_top],
                       [lon_right, lat_bottom],
                       [lon_left, lat_bottom],
                       [lon_left, lat_top]]])
130778
function(x1, y1, x2, y2, width, height, centerX, centerY, padding) {
      var points = nodeShapes['square'].points;
      
      /*
      return renderer.boxIntersectPolygon(
        x1, y1, x2, y2,
        points, 
      */
    }
1146484
def _path_polygon(self, points):
        ""
        (xmin, ymin, xmax, ymax) = _compute_bounding_box(points)
        if invisible_p(xmax, ymax):
            return
        self.setbb(xmin, ymin)
        self.setbb(xmax, ymax)

        self.newpath()
        self.moveto(xscale(points[0][0]), yscale(points[0][1]))
        for point in points[1:]:
            self.lineto(xscale(point[0]), yscale(point[1]))
        self.closepath()
563794
def create_regpoly(self, x0, y0, x1, y1, sides=0, start=90, extent=360, **kw):
        """"""
        coords = self.__regpoly_coords(x0, y0, x1, y1, sides, start, extent)
        return self.canvas.create_polygon(*coords, **kw)
169963
function endPolygon(coordCurr, normPrev, normNext, join_type, v, context) {
    // If polygon ends on a tile boundary, don't add a join
    if (isCoordOutsideTile(coordCurr)) {
        addVertex(coordCurr, normPrev, normPrev, 1, v, context, 1);
        addVertex(coordCurr, normPrev, normPrev, 0, v, context, -1);
        indexPairs(1, context);
    }
    else {
        // If polygon ends within a tile, add Miter or no joint (join added on startPolygon)
        var miterVec = createMiterVec(normPrev, normNext);

        if (join_type === JOIN_TYPE.miter && Vector.lengthSq(miterVec) > context.miter_len_sq) {
            join_type = JOIN_TYPE.bevel; // switch to bevel
        }

        if (join_type === JOIN_TYPE.miter) {
            addVertex(coordCurr, miterVec, normPrev, 1, v, context, 1);
            addVertex(coordCurr, miterVec, normPrev, 0, v, context, -1);
            indexPairs(1, context);
        }
        else {
            addVertex(coordCurr, normPrev, normPrev, 1, v, context, 1);
            addVertex(coordCurr, normPrev, normPrev, 0, v, context, -1);
            indexPairs(1, context);
        }
    }
}
676382
def boundaries(nside, pix, step=1, nest=False):
    """"""
    pix = np.asarray(pix)
    if pix.ndim > 1:
        # For consistency with healpy we only support scalars or 1D arrays
        raise ValueError("Array has to be one dimensional")
    lon, lat = boundaries_lonlat(pix, step, nside, order='nested' if nest else 'ring')
    rep_sph = UnitSphericalRepresentation(lon, lat)
    rep_car = rep_sph.to_cartesian().xyz.value.swapaxes(0, 1)
    if rep_car.shape[0] == 1:
        return rep_car[0]
    else:
        return rep_car
676595
function outer(A, B) {
    if (A.shape.length === 1) {
        A.reshape([A.shape[0], 1]);
    }
    else if (A.shape.length === 2) {
        if (A.shape[1] !== 1) {
            throw new Error('A is not a column vector');
        }
    }
    else {
        throw new Error('A has invalid dimensions');
    }
    if (B.shape.length === 1) {
        B.reshape([1, B.shape[0]]);
    }
    else if (B.shape.length === 2) {
        if (B.shape[0] !== 1) {
            throw new Error('B is not a row vector');
        }
    }
    else {
        throw new Error('B has invalid dimensions');
    }
    if (A.shape[0] !== B.shape[1]) {
        throw new Error('Sizes of A and B are not compatible');
    }
    return matmul(A, B);
}
1304485
def val_to_edge(edges, x):
    """"""
    edges = np.array(edges)
    w = edges[1:] - edges[:-1]
    w = np.insert(w, 0, w[0])
    ibin = np.digitize(np.array(x, ndmin=1), edges - 0.5 * w) - 1
    ibin[ibin < 0] = 0
    return ibin
77595
private static Cell getCentroidCell(Polygon polygon) {
        double area = 0.0;
        double x = 0.0;
        double y = 0.0;

        LineString exterior = polygon.getExteriorRing();

        for (int i = 0, n = exterior.getNumPoints() - 1, j = n - 1; i < n; j = i, i++) {
            Coordinate a = exterior.getCoordinateN(i);
            Coordinate b = exterior.getCoordinateN(j);
            double f = a.x * b.y - b.x * a.y;
            x += (a.x + b.x) * f;
            y += (a.y + b.y) * f;
            area += f * 3.0;
        }
        return new Cell(x / area, y / area, 0.0, polygon);
    }
942739
function polygonSlice(polygon, cutEdges){
    if(cutEdges.length === 0){
		return [polygon];
    }
    if(cutEdges instanceof Array && cutEdges.length && cutEdges[0] instanceof Array && cutEdges[0].length===2 && cutEdges[0][0] instanceof Array){

        var polys = [polygon];

        for(var i=0; i<cutEdges.length; i++){
            var cutEdge = cutEdges[i];
            // Cut all polys
            for(var j=0; j<polys.length; j++){
                var poly = polys[j];
                var result = polygonSlice(poly, cutEdge);
                if(result){
                    // Found poly! Cut and quit
                    polys.splice(j,1);
                    polys.push(result[0],result[1]);
                    break;
                }
            }
        }

        return polys;
    } else {

        // Was given one edge
        var cutEdge = cutEdges;
        var i = polygon.indexOf(cutEdge[0]);
        var j = polygon.indexOf(cutEdge[1]);

        if(i !== -1 && j !== -1){
            return [polygonCopy(polygon, i,j),
                    polygonCopy(polygon, j,i)];
        } else {
            return false;
        }
    }
}
1205760
def pix2ang(nside, ipix, nest=False, lonlat=False):
    """"""
    lon, lat = healpix_to_lonlat(ipix, nside, order='nested' if nest else 'ring')
    return _lonlat_to_healpy(lon, lat, lonlat=lonlat)
190512
def _in_polygon(points, polygon):
    """"""
    from matplotlib.path import Path
    points = _as_array(points)
    polygon = _as_array(polygon)
    assert points.ndim == 2
    assert polygon.ndim == 2
    if len(polygon):
        polygon = np.vstack((polygon, polygon[0]))
    path = Path(polygon, closed=True)
    return path.contains_points(points)
644151
float[] closestPointOnDetailEdges(MeshTile tile, Poly poly, float[] pos, boolean onlyBoundary) {
        int ANY_BOUNDARY_EDGE = (DT_DETAIL_EDGE_BOUNDARY << 0) | (DT_DETAIL_EDGE_BOUNDARY << 2)
                | (DT_DETAIL_EDGE_BOUNDARY << 4);
        int ip = poly.index;
        PolyDetail pd = tile.data.detailMeshes[ip];

        float dmin = Float.MAX_VALUE;
        float tmin = 0;
        float[] pmin = null;
        float[] pmax = null;

        for (int i = 0; i < pd.triCount; i++) {
            int ti = (pd.triBase + i) * 4;
            int[] tris = tile.data.detailTris;
            if (onlyBoundary && (tris[ti + 3] & ANY_BOUNDARY_EDGE) == 0) {
                continue;
            }

            float[][] v = new float[3][];
            for (int j = 0; j < 3; ++j) {
                if (tris[ti + j] < poly.vertCount) {
                    int index = poly.verts[tris[ti + j]] * 3;
                    v[j] = new float[] { tile.data.verts[index], tile.data.verts[index + 1],
                            tile.data.verts[index + 2] };
                } else {
                    int index = (pd.vertBase + (tris[ti + j] - poly.vertCount)) * 3;
                    v[j] = new float[] { tile.data.detailVerts[index], tile.data.detailVerts[index + 1],
                            tile.data.detailVerts[index + 2] };
                }
            }

            for (int k = 0, j = 2; k < 3; j = k++) {
                if ((getDetailTriEdgeFlags(tris[3], j) & DT_DETAIL_EDGE_BOUNDARY) == 0
                        && (onlyBoundary || tris[j] < tris[k])) {
                    // Only looking at boundary edges and this is internal, or
                    // this is an inner edge that we will see again or have already seen.
                    continue;
                }

                Tupple2<Float, Float> dt = distancePtSegSqr2D(pos, v[j], v[k]);
                float d = dt.first;
                float t = dt.second;
                if (d < dmin) {
                    dmin = d;
                    tmin = t;
                    pmin = v[j];
                    pmax = v[k];
                }
            }
        }

        return vLerp(pmin, pmax, tmin);
    }
554917
def outline(self, inner, outer):
        
        return self.dilate(outer).exclude(self.dilate(inner))
1129975
def boundary_map(self):
        
        # compute contours
        contours = self.find_contours()

        # fill in nonzero pixels
        new_data = np.zeros(self.data.shape)
        for contour in contours:
            new_data[contour.boundary_pixels[:, 0].astype(np.uint8),
                     contour.boundary_pixels[:, 1].astype(np.uint8)] = np.iinfo(np.uint8).max
        return BinaryImage(new_data.astype(np.uint8), frame=self.frame)