This function gives the magnitude and direction of the slope based on
    Tarboton's D_\infty method. This is a helper-function to
    _tarboton_slopes_directions
518002
def _calc_direction(data, mag, direction, ang, d1, d2, theta,
                    slc0, slc1, slc2):
    
    
    data0 = data[slc0]
    data1 = data[slc1]
    data2 = data[slc2]

    s1 = (data0 - data1) / d1
    s2 = (data1 - data2) / d2
    s1_2 = s1**2
    
    sd = (data0 - data2) / np.sqrt(d1**2 + d2**2)
    r = np.arctan2(s2, s1)
    rad2 = s1_2 + s2**2

    # Handle special cases
    # should be on diagonal
    b_s1_lte0 = s1 <= 0
    b_s2_lte0 = s2 <= 0
    b_s1_gt0 = s1 > 0
    b_s2_gt0 = s2 > 0

    I1 = (b_s1_lte0 & b_s2_gt0) | (r > theta)
    if I1.any():
        rad2[I1] = sd[I1] ** 2
        r[I1] = theta.repeat(I1.shape[1], 1)[I1]
    
    I2 = (b_s1_gt0 & b_s2_lte0) | (r < 0)  # should be on straight section
    if I2.any():
        rad2[I2] = s1_2[I2]
        r[I2] = 0
    
    I3 = b_s1_lte0 & (b_s2_lte0 | (b_s2_gt0 & (sd <= 0)))  # upslope or flat
    rad2[I3] = -1

    I4 = rad2 > mag[slc0]
    if I4.any():
        mag[slc0][I4] = rad2[I4]
        direction[slc0][I4] = r[I4] * ang[1] + ang[0] * np.pi/2

    return mag, direction
626701
def slope(self, other):
        
        X1, Y1, X2, Y2 = self.X, self.Y, other.X, other.Y
        Y3 = Y1 - Y2
        X3 = X1 - X2
        return (Y3 * self.inverse(X3)) % self.P
1053715
def ladderize(self, direction=0):
        
        if not self.is_leaf():
            n2s = {}
            for n in self.get_children():
                s = n.ladderize(direction=direction)
                n2s[n] = s

            self.children.sort(key=lambda x: n2s[x])
            if direction == 1:
                self.children.reverse()
            size = sum(n2s.values())
        else:
            size = 1
        return size
38661
public Direction direction() {
        if (!Op.isFinite(slope) || Op.isEq(slope, 0.0)) {
            return Direction.Zero;
        }
        if (Op.isGt(slope, 0.0)) {
            return Direction.Positive;
        }
        return Direction.Negative;
    }
44087
def derivative(self, t, n=1):
        """"""
        angle = radians(self.theta + t*self.delta)
        phi = radians(self.rotation)
        rx = self.radius.real
        ry = self.radius.imag
        k = (self.delta*2*pi/360)**n  # ((d/dt)angle)**n

        if n % 4 == 0 and n > 0:
            return rx*cos(phi)*cos(angle) - ry*sin(phi)*sin(angle) + 1j*(
                rx*sin(phi)*cos(angle) + ry*cos(phi)*sin(angle))
        elif n % 4 == 1:
            return k*(-rx*cos(phi)*sin(angle) - ry*sin(phi)*cos(angle) + 1j*(
                -rx*sin(phi)*sin(angle) + ry*cos(phi)*cos(angle)))
        elif n % 4 == 2:
            return k*(-rx*cos(phi)*cos(angle) + ry*sin(phi)*sin(angle) + 1j*(
                -rx*sin(phi)*cos(angle) - ry*cos(phi)*sin(angle)))
        elif n % 4 == 3:
            return k*(rx*cos(phi)*sin(angle) + ry*sin(phi)*cos(angle) + 1j*(
                rx*sin(phi)*sin(angle) - ry*cos(phi)*cos(angle)))
        else:
            raise ValueError("n should be a positive integer.")
687642
def _compute_non_linear_slope(self, vs30, C):
        
        V1 = 180.0
        V2 = 300.0
        Vref = 760.0

        # equation (13d), values are zero for vs30 >= Vref = 760.0
        bnl = np.zeros(vs30.shape)

        # equation (13a)
        idx = vs30 <= V1
        bnl[idx] = C['b1']

        # equation (13b)
        idx = np.where((vs30 > V1) & (vs30 <= V2))
        bnl[idx] = (C['b1'] - C['b2']) * \
                   np.log(vs30[idx] / V2) / np.log(V1 / V2) + C['b2']

        # equation (13c)
        idx = np.where((vs30 > V2) & (vs30 < Vref))
        bnl[idx] = C['b2'] * np.log(vs30[idx] / Vref) / np.log(V2 / Vref)
        return bnl
990058
def _get_symbol_by_slope(
        self,
        slope,
        default_symbol
        ):

        

        if slope > math.tan(3 * math.pi / 8):
            draw_symbol = "|"
        elif math.tan(math.pi / 8) < slope < math.tan(3 * math.pi / 8):
            draw_symbol = u"\u27cb" # "/"
        elif abs(slope) < math.tan(math.pi / 8):
            draw_symbol = "-"
        elif slope < math.tan(-math.pi / 8) and\
            slope > math.tan(-3 * math.pi / 8):
            draw_symbol = u"\u27CD" # "\\"
        elif slope < math.tan(-3 * math.pi / 8):
            draw_symbol = "|"
        else:
            draw_symbol = default_symbol
        return draw_symbol
346562
def theta(v):
    
    v = np.atleast_2d(v)
    dir_z = v[:, 2]
    return theta_separg(dir_z)
702893
def magnitude(self):
    

    return math.sqrt(self.x ** 2 + self.y ** 2 + self.z ** 2 + self.w ** 2)
1311485
def _tilt(c, direction:uniform_int, magnitude:uniform=0, invert=False):
    ""
    orig_pts = [[-1,-1], [-1,1], [1,-1], [1,1]]
    if direction == 0:   targ_pts = [[-1,-1], [-1,1], [1,-1-magnitude], [1,1+magnitude]]
    elif direction == 1: targ_pts = [[-1,-1-magnitude], [-1,1+magnitude], [1,-1], [1,1]]
    elif direction == 2: targ_pts = [[-1,-1], [-1-magnitude,1], [1,-1], [1+magnitude,1]]
    elif direction == 3: targ_pts = [[-1-magnitude,-1], [-1,1], [1+magnitude,-1], [1,1]]
    coeffs = _find_coeffs(targ_pts, _orig_pts) if invert else _find_coeffs(_orig_pts, targ_pts)
    return _apply_perspective(c, coeffs)
81935
public static void DFT(ComplexNumber[] data, Direction direction) {
        int n = data.length;
        ComplexNumber[] c = new ComplexNumber[n];

        // for each destination element
        for (int i = 0; i < n; i++) {
            c[i] = new ComplexNumber(0, 0);
            double sumRe = 0;
            double sumIm = 0;
            double phim = 2 * Math.PI * i / n;

            // sum source elements
            for (int j = 0; j < n; j++) {
                double gRe = data[j].real;
                double gIm = data[j].imaginary;
                double cosw = Math.cos(phim * j);
                double sinw = Math.sin(phim * j);
                if (direction == Direction.Backward)
                    sinw = -sinw;

                sumRe += (gRe * cosw + data[j].imaginary * sinw);
                sumIm += (gIm * cosw - data[j].real * sinw);
            }

            c[i] = new ComplexNumber(sumRe, sumIm);
        }

        if (direction == Direction.Backward) {
            for (int i = 0; i < c.length; i++) {
                data[i].real = c[i].real / n;
                data[i].imaginary = c[i].imaginary / n;
            }
        } else {
            for (int i = 0; i < c.length; i++) {
                data[i].real = c[i].real;
                data[i].imaginary = c[i].imaginary;
            }
        }
    }
981742
function( useComputed ) {
			if ( useComputed ) {
				return this.getComputedStyle( 'direction' ) ||
						this.getDirection() ||
						this.getParent() && this.getParent().getDirection( 1 ) ||
						this.getDocument().$.dir ||
						'ltr';
			}
			else {
				return this.getStyle( 'direction' ) || this.getAttribute( 'dir' );
			}
		}
338715
def find_truncation_offset
      truncation = self.case.truncate_data
      slope_angle = self.case.truncate_data.slope_angle.abs
      time = self.case.compare_time.to_sym
      ms = analysis[time].elements.reverse
      offset = ms.size - 1
      @slopes = []
      ModuleFunctions.array_window(ms, truncation.window_size) do |data|
        lr = LinearRegression.new(data)
        a = lr.a
        @slopes << [ offset, a ]
        a.abs > slope_angle and break
        offset -= 1
      end
      offset < 0 ? 0 : offset
    end
641296
private void calcAngleStep() {
        final double angleRange = getAngleRange();
        angleStep = angleRange / range;
        logAngleStep = angleRange / (Util.INSTANCE.logOfBase(BASE, range));
    }
95128
def calculateOutletSlope(self):
        
        try:
            mask_grid = self.getGrid()
            elevation_grid = self.getGrid(use_mask=False)

            outrow = int(self.getCard("OUTROW").value)-1
            outcol = int(self.getCard("OUTCOL").value)-1
            cell_size = float(self.getCard("GRIDSIZE").value)

            min_row = max(0, outrow-1)
            max_row = min(mask_grid.x_size, outrow+2)
            min_col = max(0, outcol-1)
            max_col = min(mask_grid.y_size, outcol+2)

            mask_array = mask_grid.np_array()
            mask_array[outrow, outcol] = 0
            mask_array = mask_array[min_row:max_row, min_col:max_col]
            mask_array = (mask_array==0)

            elevation_array = elevation_grid.np_array()
            original_elevation = elevation_array[outrow, outcol]
            elevation_array = elevation_array[min_row:max_row, min_col:max_col]

            slope_calc_array = (elevation_array-original_elevation)/cell_size
            #NOTE: Ignoring distance to cells at angles. Assuming to small to matter
            mask_array[slope_calc_array<=0] = True

            slope_mask_array = np.ma.array(slope_calc_array, mask=mask_array)
            outslope = slope_mask_array.mean()
            if outslope is np.ma.masked or outslope < 0.001:
                outslope = 0.001

        except ValueError:
            outslope = 0.001

        self.setCard("OUTSLOPE", str(outslope))
667520
function(direction, length) {
        direction *= Math.PI / 180;
        var dx = length * Math.cos(direction);
        var dy = length * Math.sin(direction);
        this.insertDeltaXY(dx, dy);
    }
79008
public function getSlope($dp = 0)
    {
        if ($dp != 0) {
            return round(exp($this->_slope), $dp);
        }
        return exp($this->_slope);
    }