The points (x_i, y_i) and values z_ij are connected as follows:
    Starting from lower left going in mathematically positive direction, i.e. counter clockwise.
    Therefore: (x1,y1,z11), (x2,y1,z21), (x2,y2,z22), (x1,y2,z12).
172685
def interpolation_bilinear(x, y, x1, x2, y1, y2, z11, z21, z22, z12):
    '''
    
    '''
    t = (x - x1) / (x2 - x1)
    s = (y - y1) / (y2 - y1)
    v1 = (1.0 - t) * (1.0 - s) * z11
    v2 = t * (1.0 - s) * z21
    v3 = t * s * z22
    v4 = (1.0 - t) * s * z12
    ret = v1 + v2 + v3 + v4
    return ret
1354423
def set_coords(self, x=0, y=0, z=0, t=0):
        
        self.coords = {}
        self.coords['x'] = x
        self.coords['y'] = y
        self.coords['z'] = z
        self.coords['t'] = t
680715
public Stream<IntPair> adjacent4Points(final int i, final int j) {
        final IntPair up = i == 0 ? null : IntPair.of(i - 1, j);
        final IntPair right = j == cols - 1 ? null : IntPair.of(i, j + 1);
        final IntPair down = i == rows - 1 ? null : IntPair.of(i + 1, j);
        final IntPair left = j == 0 ? null : IntPair.of(i, j - 1);

        return Stream.of(up, right, down, left);
    }
116405
def is_clockwise(vertices):
    
    it = iterator.consecutive(cycle(vertices), 3)
    clockwise = 0
    counter = 0
    for _ in range(len(vertices)):
        p0, p1, p2 = next(it)
        cross = cross_product(p1, p2, p0)
        int_angle = interior_angle(p0, p2, p1)  # raises ValueError
        if cross < 0:
            clockwise += int_angle
            counter += 2 * pi - int_angle
        else:
            clockwise += 2 * pi - int_angle
            counter += int_angle
    if round(clockwise / pi) == len(vertices) - 2:
        return True
    elif round(counter / pi) == len(vertices) - 2:
        return False
    else:
        raise ValueError("the polygon is complex or overlapped")
1092673
static boolean mergeVertices(Point pt_1, Point pt_2, double w_1,
			int rank_1, double w_2, int rank_2, Point pt_res, double[] w_res,
			int[] rank_res) {
		assert (!pt_1.isEmpty() && !pt_2.isEmpty());
		boolean res = pt_1.equals(pt_2);

		if (rank_1 > rank_2) {
			pt_res = pt_1;
			if (w_res != null) {
				rank_res[0] = rank_1;
				w_res[0] = w_1;
			}
			return res;
		} else if (rank_2 > rank_1) {
			pt_res = pt_2;
			if (w_res != null) {
				rank_res[0] = rank_1;
				w_res[0] = w_1;
			}
			return res;
		}

		pt_res = pt_1;
		Point2D pt2d = new Point2D();
		mergeVertices2D(pt_1.getXY(), pt_2.getXY(), w_1, rank_1, w_2, rank_2,
				pt2d, w_res, rank_res);
		pt_res.setXY(pt2d);
		return res;
	}
340176
def _pnpoly(x, y, coords):
    
    vert = [[0, 0]]

    for coord in coords:
        for node in coord:
            vert.append(node)
        vert.append(coord[0])
        vert.append([0, 0])

    inside = False

    i = 0
    j = len(vert) - 1

    while i < len(vert):
        if ((vert[i][0] > y) != (vert[j][0] > y)) and (x < (vert[j][1] - vert[i][1])
                                                       * (y - vert[i][0]) / (vert[j][0] - vert[i][0]) + vert[i][1]):
            inside = not inside
        j = i
        i += 1

    return inside
595432
private boolean connected(NodeCursor start, long end, int[][] typedDirections) {
        try (RelationshipTraversalCursor relationship = ktx.cursors().allocateRelationshipTraversalCursor()) {
            start.allRelationships(relationship);
            while (relationship.next()) {
                if (relationship.neighbourNodeReference() ==end) {
                    if (typedDirections==null) {
                        return true;
                    } else {
                        int direction = relationship.targetNodeReference() == end ? 0 : 1 ;
                        int[] types = typedDirections[direction];
                        if (arrayContains(types, relationship.type())) return true;
                    }
                }
            }
        }
        return false;
    }
684697
public static boolean linesIntersect (double x1, double y1, double x2, double y2,
                                          double x3, double y3, double x4, double y4) {
        // A = (x2-x1, y2-y1)
        // B = (x3-x1, y3-y1)
        // C = (x4-x1, y4-y1)
        // D = (x4-x3, y4-y3) = C-B
        // E = (x1-x3, y1-y3) = -B
        // F = (x2-x3, y2-y3) = A-B
        //
        // Result is ((AxB) * (AxC) <= 0) and ((DxE) * (DxF) <= 0)
        //
        // DxE = (C-B)x(-B) = BxB-CxB = BxC
        // DxF = (C-B)x(A-B) = CxA-CxB-BxA+BxB = AxB+BxC-AxC
        x2 -= x1; // A
        y2 -= y1;
        x3 -= x1; // B
        y3 -= y1;
        x4 -= x1; // C
        y4 -= y1;

        double AvB = x2 * y3 - x3 * y2;
        double AvC = x2 * y4 - x4 * y2;

        // online
        if (AvB == 0 && AvC == 0) {
            if (x2 != 0) {
                return (x4 * x3 <= 0) ||
                    ((x3 * x2 >= 0) && (x2 > 0 ? x3 <= x2 || x4 <= x2 : x3 >= x2 || x4 >= x2));
            }
            if (y2 != 0) {
                return (y4 * y3 <= 0) ||
                    ((y3 * y2 >= 0) && (y2 > 0 ? y3 <= y2 || y4 <= y2 : y3 >= y2 || y4 >= y2));
            }
            return false;
        }

        double BvC = x3 * y4 - x4 * y3;
        return (AvB * AvC <= 0) && (BvC * (AvB + BvC - AvC) <= 0);
    }
1360922
private boolean addTangents(Grid grid, int rowA, int colA, int rowB, int colB) {
		EllipseRotated_F64 a = grid.get(rowA,colA);
		EllipseRotated_F64 b = grid.get(rowB,colB);

		if( !tangentFinder.process(a,b, A0, A1, A2, A3, B0, B1, B2, B3) ) {
			return false;
		}
		Tangents ta = tangents.get(grid.getIndexOfRegEllipse(rowA,colA));
		Tangents tb = tangents.get(grid.getIndexOfRegEllipse(rowB,colB));

		// Which point is 0 or 3 is not defined and can swap arbitrarily.  To fix this problem
		// 0 will be defined as on the 'positive side' of the line connecting the ellipse centers

		double slopeX = b.center.x-a.center.x;
		double slopeY = b.center.y-a.center.y;

		double dx0 = A0.x-a.center.x;
		double dy0 = A0.y-a.center.y;

		double z = slopeX*dy0 - slopeY*dx0;
		if( z < 0 == (rowA == rowB)) {
			Point2D_F64 tmp = A0; A0 = A3; A3 = tmp;
			tmp = B0; B0 = B3; B3 = tmp;
		}

		// add tangent points from the two lines which do not cross the center line
		if( rowA == rowB ) {
			ta.t[ta.countT++].set(A0);
			ta.b[ta.countB++].set(A3);
			tb.t[tb.countT++].set(B0);
			tb.b[tb.countB++].set(B3);
		} else {
			ta.r[ta.countL++].set(A0);
			ta.l[ta.countR++].set(A3);
			tb.r[tb.countL++].set(B0);
			tb.l[tb.countR++].set(B3);
		}
		return true;
	}
1059447
def build_y(self):
        """"""
        if not self.n:
            return
        self.y1 = mul(self.u, self.g1 + self.b1 * 1j)
        self.y2 = mul(self.u, self.g2 + self.b2 * 1j)
        self.y12 = div(self.u, self.r + self.x * 1j)
        self.m = polar(self.tap, self.phi * deg2rad)
        self.m2 = abs(self.m)**2
        self.mconj = conj(self.m)

        # build self and mutual admittances into Y
        self.Y = spmatrix(
            div(self.y12 + self.y1, self.m2), self.a1, self.a1,
            (self.nb, self.nb), 'z')
        self.Y -= spmatrix(
            div(self.y12, self.mconj), self.a1, self.a2, (self.nb, self.nb),
            'z')
        self.Y -= spmatrix(
            div(self.y12, self.m), self.a2, self.a1, (self.nb, self.nb), 'z')
        self.Y += spmatrix(self.y12 + self.y2, self.a2, self.a2,
                           (self.nb, self.nb), 'z')
73766
def iterline(x1, y1, x2, y2):
    ''
    xdiff = abs(x2-x1)
    ydiff = abs(y2-y1)
    xdir = 1 if x1 <= x2 else -1
    ydir = 1 if y1 <= y2 else -1

    r = math.ceil(max(xdiff, ydiff))
    if r == 0:  # point, not line
        yield x1, y1
    else:
        x, y = math.floor(x1), math.floor(y1)
        i = 0
        while i < r:
            x += xdir * xdiff / r
            y += ydir * ydiff / r

            yield x, y
            i += 1
994033
def quadrant(xcoord, ycoord):
    

    xneg = bool(xcoord < 0)
    yneg = bool(ycoord < 0)
    if xneg is True:
        if yneg is False:
            return 2
        return 3
    if yneg is False:
        return 1
    return 4
1203853
private ResultPoint[] detectSolid1(ResultPoint[] cornerPoints) {
    // 0  2
    // 1  3
    ResultPoint pointA = cornerPoints[0];
    ResultPoint pointB = cornerPoints[1];
    ResultPoint pointC = cornerPoints[3];
    ResultPoint pointD = cornerPoints[2];

    int trAB = transitionsBetween(pointA, pointB);
    int trBC = transitionsBetween(pointB, pointC);
    int trCD = transitionsBetween(pointC, pointD);
    int trDA = transitionsBetween(pointD, pointA);

    // 0..3
    // :  :
    // 1--2
    int min = trAB;
    ResultPoint[] points = {pointD, pointA, pointB, pointC};
    if (min > trBC) {
      min = trBC;
      points[0] = pointA;
      points[1] = pointB;
      points[2] = pointC;
      points[3] = pointD;
    }
    if (min > trCD) {
      min = trCD;
      points[0] = pointB;
      points[1] = pointC;
      points[2] = pointD;
      points[3] = pointA;
    }
    if (min > trDA) {
      points[0] = pointC;
      points[1] = pointD;
      points[2] = pointA;
      points[3] = pointB;
    }

    return points;
  }
387525
private static int winding(Point2d a, Point2d b, Point2d c) {
        return (int) Math.signum((b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x));
    }
1031681
def inROI(self, Y):
        ''''''
        if Y.ndim > 1:
            area = np.zeros((Y.shape[0],4))
        else:
            area = np.zeros((1,4))
        pts = np.zeros((0,), int)
        pdist = np.zeros((0,), int)
        dist0 = 0
        for k in range(len(self.prect)):
            self.square_area = (triangle_area(self.prect[k][0,:], self.prect[k][1,:], self.prect[k][2,:]) +
                            triangle_area(self.prect[k][2,:], self.prect[k][3,:], self.prect[k][4,:]))
            for n in range(4):
                area[:,n] = triangle_area(self.prect[k][0+n,:], self.prect[k][1+n,:], Y)
            # points inside prect
            newpts = np.array((area.sum(axis=1) <= self.square_area+1e-5).nonzero()).flatten().astype(int)
            if newpts.size > 0:
                pts = np.concatenate((pts, newpts))
                newdists = self.orthproj(Y[newpts, :], k) + dist0
                pdist = np.concatenate((pdist, newdists))
            dist0 += (np.diff(self.pos[k], axis=0)[0,:]**2).sum()
            # check if in radius of circle
            if k < len(self.prect)-1:
                pcent = self.pos[k][1,:]
                dist = ((Y - pcent[np.newaxis,:])**2).sum(axis=1)**0.5
                newpts = np.array((dist<=self.d).nonzero()[0].astype(int))
                if newpts.size > 0:
                    pts = np.concatenate((pts, newpts))
                    newdists = dist0 * np.ones(newpts.shape)
                    pdist = np.concatenate((pdist, newdists))

        pts, inds = np.unique(pts, return_index=True)
        pdist = pdist[inds]
        return pts, pdist
1040092
def _edge_opposite_point(self, tri, i):
        
        ind = tri.index(i)
        return (tri[(ind+1) % 3], tri[(ind+2) % 3])
918679
public static boolean isConvex(double[] data, int points)
    {
        if (points < 3)
        {
            return true;
        }
        for (int i1 = 0; i1 < points; i1++)
        {
            int i2 = (i1 + 1) % points;
            int i3 = (i2 + 1) % points;
            double x1 = data[2 * i1];
            double y1 = data[2 * i1 + 1];
            double x2 = data[2 * i2];
            double y2 = data[2 * i2 + 1];
            double x3 = data[2 * i3];
            double y3 = data[2 * i3 + 1];
            if (Vectors.isClockwise(x1, y1, x2, y2, x3, y3))
            {
                return false;
            }
        }
        return true;
    }