Check the given Dinf angle based on D8 flow direction encoding code by ArcGIS
163158
def check_orthogonal(angle):
        """"""
        flow_dir_taudem = -1
        flow_dir = -1
        if MathClass.floatequal(angle, FlowModelConst.e):
            flow_dir_taudem = FlowModelConst.e
            flow_dir = 1
        elif MathClass.floatequal(angle, FlowModelConst.ne):
            flow_dir_taudem = FlowModelConst.ne
            flow_dir = 128
        elif MathClass.floatequal(angle, FlowModelConst.n):
            flow_dir_taudem = FlowModelConst.n
            flow_dir = 64
        elif MathClass.floatequal(angle, FlowModelConst.nw):
            flow_dir_taudem = FlowModelConst.nw
            flow_dir = 32
        elif MathClass.floatequal(angle, FlowModelConst.w):
            flow_dir_taudem = FlowModelConst.w
            flow_dir = 16
        elif MathClass.floatequal(angle, FlowModelConst.sw):
            flow_dir_taudem = FlowModelConst.sw
            flow_dir = 8
        elif MathClass.floatequal(angle, FlowModelConst.s):
            flow_dir_taudem = FlowModelConst.s
            flow_dir = 4
        elif MathClass.floatequal(angle, FlowModelConst.se):
            flow_dir_taudem = FlowModelConst.se
            flow_dir = 2
        return flow_dir_taudem, flow_dir
36074
function(obj) {
    if (obj.normal) { return obj.isParallelTo(this); }
    var theta = this.direction.angleFrom(obj.direction);
    return (Math.abs(theta) <= Sylvester.precision || Math.abs(theta - Math.PI) <= Sylvester.precision);
  }
1044716
def ok(self):
        
        try:
            coord.Angle(self._value, unit=u.deg)
            return True
        except ValueError:
            return False
162146
boolean isCornerValidOrigin( Node candidate ) {
		candidate.putEdgesIntoList(edgeList);
		if( edgeList.size() != 2 ) {
			throw new RuntimeException("BUG! Should be a corner and have two edges");
		}

		Node a = edgeList.get(0);
		Node b = edgeList.get(1);

		// Find the average angle from the two vectors defined by the two connected nodes
		double dirA = Math.atan2(a.y-candidate.y, a.x-candidate.x);
		double dirB = Math.atan2(b.y-candidate.y, b.x-candidate.x);

		double dirAB = UtilAngle.boundHalf(dirA+UtilAngle.distanceCCW(dirA,dirB)/2.0);

		// Find the acute angle between the corner's orientation and the vector
		double acute = UtilAngle.distHalf(dirAB,candidate.orientation);

		return acute < Math.PI/4.0;
	}
574565
function getDirectionChange(angle1, angle2) {

        var directionChange = Math.abs(angle1 - angle2);
        return (directionChange > 180) ? (360 - directionChange) : directionChange;
    }
266187
def check_each_direction(n,angs,ifprint=True):
    
    checks = np.array([])
    P = np.array([])
    if(ifprint):
        print("\nChecking modes:\n====")
    for k,i in enumerate(n):
        N_matrix = np.linalg.norm(i)
        X = np.dot(angs,i)
        if(np.abs(np.max(X)-np.min(X))<2.*np.pi):
            if(ifprint):
                print("Need a longer integration window for mode ", i)
            checks=np.append(checks,i)
            P = np.append(P,(2.*np.pi-np.abs(np.max(X)-np.min(X))))
        elif(np.abs(np.max(X)-np.min(X))/len(X)>np.pi):
            if(ifprint):
                print("Need a finer sampling for mode ", i)
            checks=np.append(checks,i)
            P = np.append(P,(2.*np.pi-np.abs(np.max(X)-np.min(X))))
    if(ifprint):
        print("====\n")
    return checks,P
191849
def angle(v1, v2):
    """"""
    v1_u = unit_vector(v1)
    v2_u = unit_vector(v2)
    return np.arccos(np.clip(np.dot(v1_u, v2_u), -1.0, 1.0))
70639
def gate_angle(gate0: Gate, gate1: Gate) -> bk.BKTensor:
    """"""
    return fubini_study_angle(gate0.vec, gate1.vec)
934820
function angleAddr() {
        return wrap('angle-addr', or(
            and(
                invis(opt(cfws)),
                literal('<'),
                addrSpec,
                literal('>'),
                invis(opt(cfws))
            ),
            obsAngleAddr
        )());
    }
453022
function getDirection(gradient) {
    var segs;
    var angle;
    var result = {};

    if (gradient.sideCorner) {
        segs = gradient.sideCorner.split(/\s+/);

        var to = segs[0] === 'to';
        if (to) {
            // sideCorner starts with "to" so we shift it off since we don't
            // need this element anymore, and continue with generating the
            // gradient in the normal direction.
            segs.shift();
        } else {
            // sideCorner does not start with "to", so we need to reverse the
            // direction.
            var reverseDirections = {
                top: 'bottom',
                bottom: 'top',
                left: 'right',
                right: 'left'
            };
            segs[0] = reverseDirections[segs[0]];
        }

        result.direction = segs[0];
        // side corner is  `top right` or `bottom left` etc.
        if (segs.length > 1) {
            // fallback to one direction
            result.isFallback = true;
            result.message =
                'IE filter doesn\'t support side corner gradient, ' +
                'we use the first side of the side corner as fallback.';
        }
    } else {
        angle = normalizeAngle(gradient.angle.value, gradient.angle.unit);
        result = angleToDirection(angle);
    }

    return result;
}
649609
def _is_trivial_angle(rad: float, atol: float) -> bool:
    
    return abs(rad) < atol or abs(abs(rad) - np.pi / 4) < atol
529975
protected void calculateDrawRectF() {
        mFillCircleRectF = getArcRect(mClockwiseReachedArcWidth);
        mReachedArcRectF = getArcRect(mClockwiseReachedArcWidth / 2);
        mOutlineArcRectF = getArcRect(mClockwiseOutlineArcWidth / 2);
    }
923832
def _voltage_angle_diff_limit(self, buses, branches):
        
        nb = len(buses)

        if not self.ignore_ang_lim:
            iang = [i for i, b in enumerate(branches)
                    if (b.ang_min and (b.ang_min > -360.0))
                    or (b.ang_max and (b.ang_max < 360.0))]
            iangl = array([i for i, b in enumerate(branches)
                     if b.ang_min is not None])[iang]
            iangh = array([i for i, b in enumerate(branches)
                           if b.ang_max is not None])[iang]
            nang = len(iang)

            if nang > 0:
                ii = range(nang) + range(nang)
                jjf = array([b.from_bus._i for b in branches])[iang]
                jjt = array([b.to_bus._i for b in branches])[iang]
                jj = r_[jjf, jjt]
                Aang = csr_matrix(r_[ones(nang), -ones(nang)], (ii, jj))
                uang = Inf * ones(nang)
                lang = -uang
                lang[iangl] = array([b.ang_min * (pi / 180.0)
                                    for b in branches])[iangl]
                uang[iangh] = array([b.ang_max * (pi / 180.0)
                                    for b in branches])[iangh]
            else:
#                Aang = csr_matrix((0, nb), dtype=float64)
#                lang = array([], dtype=float64)
#                uang = array([], dtype=float64)
                Aang = zeros((0, nb))
                lang = array([])
                uang = array([])
        else:
#            Aang = csr_matrix((0, nb), dtype=float64)
#            lang = array([], dtype=float64)
#            uang = array([], dtype=float64)
#            iang = array([], dtype=float64)
            Aang = zeros((0, nb))
            lang = array([])
            uang = array([])

        return LinearConstraint("ang", Aang, lang, uang, ["Va"])
943620
public static int getBlockNrForAlignPos(AFPChain afpChain, int aligPos){
		// moved here from DisplayAFP;

		int blockNum = afpChain.getBlockNum();

		int[] optLen = afpChain.getOptLen();
		int[][][] optAln = afpChain.getOptAln();

		int len = 0;
		int p1b=0;
		int p2b=0;

		for(int i = 0; i < blockNum; i ++)  {

			for(int j = 0; j < optLen[i]; j ++) {

				int p1 = optAln[i][0][j];
				int p2 = optAln[i][1][j];

				if (len != 0) {
					// check for gapped region
					int lmax = (p1 - p1b - 1)>(p2 - p2b - 1)?(p1 - p1b - 1):(p2 - p2b - 1);
					for(int k = 0; k < lmax; k ++)      {
						len++;
					}
				}


				p1b = p1;
				p2b = p2;
				if ( len >= aligPos) {

					return i;
				}
				len++;
			}
		}

		return blockNum;

	}
613762
function DEGtoSEC(angle) {

  // Extract DMS
  const deg = parseInt(angle, 10);
  let min = parseInt((angle - deg) * 100, 10);
  let sec = (((angle - deg) * 100) - min) * 100;

  // Avoid rounding problems with seconds=0
  const parts = String(angle).split('.');
  if (parts.length == 2 && parts[1].length == 2) {
    min = Number(parts[1]);
    sec = 0;
  }

  // Result in degrees sex (dd.mmss)
  return sec + min * 60 + deg * 3600;

}
812311
def vector_angle(pairs):
    
    pairs = np.asanyarray(pairs, dtype=np.float64)
    if len(pairs) == 0:
        return np.array([])
    elif util.is_shape(pairs, (2, 3)):
        pairs = pairs.reshape((-1, 2, 3))
    elif not util.is_shape(pairs, (-1, 2, (2, 3))):
        raise ValueError('pairs must be (n,2,(2|3))!')

    # do the dot product between vectors
    dots = util.diagonal_dot(pairs[:, 0], pairs[:, 1])
    # clip for floating point error
    dots = np.clip(dots, -1.0, 1.0)
    # do cos and remove arbitrary sign
    angles = np.abs(np.arccos(dots))

    return angles
1116772
function angle2String (angleObj) {
	let deg = angleObj.deg;
	if (angleObj.unit && angleObj.unit !== "deg") {
		// 单位不为度是，需要换算
		deg = (deg * angleUnitMap[angleObj.unit] / 360);
	}

	// 修正浮点数精度
	deg = parseFloat(deg.toFixed(4));
	if (deg === 0) {
		// 结果等于0时，直接转换为字符串输出，不要单位
		deg = "0";
	} else {
		// 结果不为0时，补上单位
		deg += angleObj.unit || "deg";
	}
	return deg;
}