volume of a zone defined by two polygon bases
549992
def vol_zone(poly1, poly2):
    "
    c_point = central_p(poly1, poly2)
    c_point = (c_point[0], c_point[1], c_point[2])
    vol_therah = 0
    num = len(poly1)
    for i in range(num-2):
        # the upper part
        tehrahedron = [c_point, poly1[0], poly1[i+1], poly1[i+2]]
        vol_therah += vol_tehrahedron(tehrahedron)
        # the bottom part
        tehrahedron = [c_point, poly2[0], poly2[i+1], poly2[i+2]]
        vol_therah += vol_tehrahedron(tehrahedron)
    # the middle part
    for i in range(num-1):
        tehrahedron = [c_point, poly1[i], poly2[i], poly2[i+1]]
        vol_therah += vol_tehrahedron(tehrahedron)
        tehrahedron = [c_point, poly1[i], poly1[i+1], poly2[i]]
        vol_therah += vol_tehrahedron(tehrahedron)
    tehrahedron = [c_point, poly1[num-1], poly2[num-1], poly2[0]]
    vol_therah += vol_tehrahedron(tehrahedron)
    tehrahedron = [c_point, poly1[num-1], poly1[0], poly2[0]]
    vol_therah += vol_tehrahedron(tehrahedron)
    return vol_therah
264631
def area(self):
        
        # area of the sides of the extrusion
        area = abs(self.primitive.height *
                   self.primitive.polygon.length)
        # area of the two caps of the extrusion
        area += self.primitive.polygon.area * 2
        return area
271379
private static Rectangle2d
		computeIcosepSubarea(IcosepQuadTreeZone region, Rectangle2d area) {
		if (area == null || area.isEmpty()) {
			return area;
		}
		final double demiWidth = area.getWidth() / 2.;
		final double demiHeight = area.getHeight() / 2.;
		switch (region) {
		case ICOSEP:
			return area;
		case SOUTH_WEST:
			return new Rectangle2d(
					area.getMinX(), area.getMinY(),
					demiWidth, demiHeight);
		case NORTH_WEST:
			return new Rectangle2d(
					area.getMinX(), area.getCenterY(),
					demiWidth, demiHeight);
		case NORTH_EAST:
			return new Rectangle2d(
					area.getCenterX(), area.getMinY(),
					demiWidth, demiHeight);
		case SOUTH_EAST:
			return new Rectangle2d(
					area.getMinX(), area.getMinY(),
					demiWidth, demiHeight);
		default:
		}
		throw new IllegalStateException();
	}
723068
function polygonCanSee(polygon, a,b) {
    var p, dist, l1=tmpLine1, l2=tmpLine2;

    if (isLeftOn(polygonAt(polygon, a + 1), polygonAt(polygon, a), polygonAt(polygon, b)) && isRightOn(polygonAt(polygon, a - 1), polygonAt(polygon, a), polygonAt(polygon, b))) {
        return false;
    }
    dist = sqdist(polygonAt(polygon, a), polygonAt(polygon, b));
    for (var i = 0; i !== polygon.length; ++i) { // for each edge
        if ((i + 1) % polygon.length === a || i === a){ // ignore incident edges
            continue;
        }
        if (isLeftOn(polygonAt(polygon, a), polygonAt(polygon, b), polygonAt(polygon, i + 1)) && isRightOn(polygonAt(polygon, a), polygonAt(polygon, b), polygonAt(polygon, i))) { // if diag intersects an edge
            l1[0] = polygonAt(polygon, a);
            l1[1] = polygonAt(polygon, b);
            l2[0] = polygonAt(polygon, i);
            l2[1] = polygonAt(polygon, i + 1);
            p = lineInt(l1,l2);
            if (sqdist(polygonAt(polygon, a), p) < dist) { // if edge is blocking visibility to b
                return false;
            }
        }
    }

    return true;
}
1000204
def width(poly):
    """"""
    num = len(poly) - 1
    if abs(poly[num][2] - poly[0][2]) < abs(poly[1][2] - poly[0][2]):
        return dist(poly[num], poly[0])
    elif abs(poly[num][2] - poly[0][2]) > abs(poly[1][2] - poly[0][2]):
        return dist(poly[1], poly[0])
    else: return max(dist(poly[num], poly[0]), dist(poly[1], poly[0]))
1250550
function d3_geom_polygonIntersect(c, d, a, b) {
  var x1 = c[0], x2 = d[0], x3 = a[0], x4 = b[0],
      y1 = c[1], y2 = d[1], y3 = a[1], y4 = b[1],
      x13 = x1 - x3,
      x21 = x2 - x1,
      x43 = x4 - x3,
      y13 = y1 - y3,
      y21 = y2 - y1,
      y43 = y4 - y3,
      ua = (x43 * y13 - y43 * x13) / (y43 * x21 - x43 * y21);
  return [x1 + ua * x21, y1 + ua * y21];
}
543185
function insidePolygon(rings, p) {
    var inside = false;
    for (var i = 0, len = rings.length; i < len; i++) {
        var ring = rings[i];
        for (var j = 0, len2 = ring.length, k = len2 - 1; j < len2; k = j++) {
            if (rayIntersect(p, ring[j], ring[k])) inside = !inside;
        }
    }
    return inside;
}
1336067
public static double getPolygonArea( int[] x, int[] y, int N ) {
        int i, j;
        double area = 0;

        for( i = 0; i < N; i++ ) {
            j = (i + 1) % N;
            area += x[i] * y[j];
            area -= y[i] * x[j];
        }

        area /= 2;
        return (area < 0 ? -area : area);
    }
679280
private boolean isConvex(double[] a, double[] b, double[] c) {
    // We're using factor to improve numerical contrast for small polygons.
    double area = (b[0] - a[0]) * factor * (c[1] - a[1]) - (c[0] - a[0]) * factor * (b[1] - a[1]);
    return (-1e-13 < area && area < 1e-13) ? (mdist(b, c) > mdist(a, b) + mdist(a, c)) : (area < 0);
  }
560221
def calculate_bbox_area(bbox, rows, cols):
    """"""
    bbox = denormalize_bbox(bbox, rows, cols)
    x_min, y_min, x_max, y_max = bbox[:4]
    area = (x_max - x_min) * (y_max - y_min)
    return area
189131
function getSqDist(p1, p2) {

    var dx = p1.x - p2.x,
        dy = p1.y - p2.y;

    return dx * dx + dy * dy;
}
720517
private static boolean polygonWithinEnvelope_(Polygon polygon_a,
			Envelope envelope_b, double tolerance,
			ProgressTracker progress_tracker) {
		Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D();
		polygon_a.queryEnvelope2D(env_a);
		envelope_b.queryEnvelope2D(env_b);
		return envelopeInfContainsEnvelope_(env_b, env_a, tolerance);
	}
314986
public void boundingPolygonCCW(SquareGrid grid, Polygon2D_F64 bounding) {
		int w = grid.columns;
		int h = grid.rows;

		if( w == 1 && h == 1 ) {
			SquareNode n = grid.get(0,0);
			bounding.get(0).set(n.square.get(0));
			bounding.get(1).set(n.square.get(1));
			bounding.get(2).set(n.square.get(2));
			bounding.get(3).set(n.square.get(3));
		} else if( w == 1 ) {
			orderNode(grid.get(0, 0), grid.get(h - 1, 0), false);
			bounding.get(0).set(ordered[0]);
			bounding.get(1).set(ordered[1]);
			orderNode(grid.get(h - 1, 0), grid.get(0, 0), false);
			bounding.get(2).set(ordered[0]);
			bounding.get(3).set(ordered[1]);
		} else if( h == 1 ) {
			orderNode(grid.get(0, 0), grid.get(0, w - 1), true);
			bounding.get(0).set(ordered[0]);
			bounding.get(3).set(ordered[3]);
			orderNode(grid.get(0, w - 1), grid.get(0, 0), true);
			bounding.get(1).set(ordered[3]);
			bounding.get(2).set(ordered[0]);
		} else {
			orderNode(grid.get(0, 0), grid.get(0, w - 1), true);
			bounding.get(0).set(ordered[0]);
			orderNode(grid.get(0, w - 1), grid.get(h - 1, w - 1), true);
			bounding.get(1).set(ordered[0]);
			orderNode(grid.get(h - 1, w - 1), grid.get(h - 1, 0), true);
			bounding.get(2).set(ordered[0]);
			orderNode(grid.get(h - 1, 0), grid.get(0, 0), true);
			bounding.get(3).set(ordered[0]);
		}
	}
1304699
function (polygon, x, y) {
		var nn = polygon.length;
		var prevIndex = nn - 2;
		var inside = false;
		for (var ii = 0; ii < nn; ii += 2) {
			var vertexY = polygon[ii + 1];
			var prevY = polygon[prevIndex + 1];
			if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) {
				var vertexX = polygon[ii];
				if (vertexX + (y - vertexY) / (prevY - vertexY) * (polygon[prevIndex] - vertexX) < x) inside = !inside;
			}
			prevIndex = ii;
		}
		return inside;
	}
971783
def extract_polygon_area(self, pid, polygon_points):
        
        polygon = shapgeo.Polygon(polygon_points)
        xy = self.grid.get_element_centroids()
        in_poly = []
        for nr, point in enumerate(xy):
            if shapgeo.Point(point).within(polygon):
                in_poly.append(nr)

        values = self.parsets[pid][in_poly]
        return np.array(in_poly), values
609101
function(orthobasis) {
            var points2d = this.vertices.map(function(vertex) {
                return orthobasis.to2D(vertex.pos);
            });
            var result = CAG.fromPointsNoCheck(points2d);
            var area = result.area();
            if (Math.abs(area) < 1e-5) {
                // the polygon was perpendicular to the orthnormal plane. The resulting 2D polygon would be degenerate
                // return an empty area instead:
                result = new CAG();
            } else if (area < 0) {
                result = result.flipped();
            }
            return result;
        }
405890
def area (self):
    
    area = 0.0
    
    for segment in self.segments():
      area += ((segment.p.x * segment.q.y) - (segment.q.x * segment.p.y))/2

    return area