Rotate PDF by increments of 90 degrees.
966117
def rotate(file_name, rotate, suffix='rotated', tempdir=None):
    """"""
    # Set output file name
    if tempdir:
        outfn = NamedTemporaryFile(suffix='.pdf', dir=tempdir, delete=False).name
    elif suffix:
        outfn = os.path.join(os.path.dirname(file_name), add_suffix(file_name, suffix))
    else:
        outfn = NamedTemporaryFile(suffix='.pdf').name

    trailer = PdfReader(file_name)
    pages = trailer.pages

    ranges = [[1, len(pages)]]

    for onerange in ranges:
        onerange = (onerange + onerange[-1:])[:2]
        for pagenum in range(onerange[0] - 1, onerange[1]):
            pages[pagenum].Rotate = (int(pages[pagenum].inheritable.Rotate or 0) + rotate) % 360

    outdata = PdfWriter(outfn)
    outdata.trailer = trailer
    outdata.write()
    return outfn
1274105
public void rotate(double cos, double sin) {
		Transformation2D temp = new Transformation2D();
		temp.setRotate(cos, sin);
		multiply(temp);
	}
135021
public static void rotateImage(File input, File output, String format, int degrees) 
	  throws IOException
	  {
	   	   
		  BufferedImage inputImage = ImageIO.read(input);	   

		    Graphics2D g = (Graphics2D) inputImage.getGraphics();
		    g.drawImage(inputImage, 0, 0, null);
	
		    AffineTransform at = new AffineTransform();
	
		    // scale image
		    //at.scale(2.0, 2.0);
	
		    // rotate 45 degrees around image center
		    at.rotate(degrees * Math.PI / 180.0, inputImage.getWidth() / 2.0, inputImage.getHeight() / 2.0);
		    //at.rotate(Math.toRadians(degrees), inputImage.getWidth() / 2.0, inputImage.getHeight() / 2.0);
	
		   
		    /*
		     * translate to make sure the rotation doesn't cut off any image data
		     */
		    AffineTransform translationTransform;
		    translationTransform = findTranslation(at, inputImage);
		    at.preConcatenate(translationTransform);
		   
		    
		    // instantiate and apply transformation filter
		    BufferedImageOp bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
		    
		    BufferedImage destinationBI = bio.filter(inputImage, null);
	
		    ImageIO.write(destinationBI, format, output);
		    
	  }
1109872
def random(cls):
        """"""
        axis = random_unit()
        angle = np.random.uniform(0,2*np.pi)
        invert = bool(np.random.randint(0,2))
        return Rotation.from_properties(angle, axis, invert)
43558
def _pdf(self, x, dist, cache):
        """"""
        output = evaluation.evaluate_density(dist, numpy.arccosh(x), cache=cache)
        output /= numpy.where(x != 1, numpy.sqrt(x*x-1), numpy.inf)
        return output
189515
def logpdf(self, x):
        
        if self.transform is not None:
            x = self.transform(x)       
        return (-self.alpha-1)*np.log(x) - (self.beta/float(x))
812493
def z_rotate(rotationAmt):
        """"""
        ma4 = Matrix4((math.cos(rotationAmt), -math.sin(rotationAmt), 0, 0),
                      (math.sin(rotationAmt), math.cos(rotationAmt), 0, 0),
                      (0, 0, 1, 0),
                      (0, 0, 0, 1))

        return ma4
969807
def pdf(self, mu):
        
        if self.transform is not None:
            mu = self.transform(mu)             
        return (1.0/float(self.sigma0))*np.exp(-(0.5*(mu-self.mu0)**2)/float(self.sigma0**2))
194492
def _pdf(self, x, dist, cache):
        """"""
        return evaluation.evaluate_density(
            dist, numpy.arcsinh(x), cache=cache)/numpy.sqrt(1+x*x)
582863
def _rotate(n, x, y, rx, ry):
    
    if ry == 0:
        if rx == 1:
            x = n - 1 - x
            y = n - 1 - y
        return y, x
    return x, y
838310
def orient(mag_azimuth, field_dip, or_con):
    
    or_con = str(or_con)
    if mag_azimuth == -999:
        return "", ""
    if or_con == "1":  # lab_mag_az=mag_az;  sample_dip = -dip
        return mag_azimuth, -field_dip
    if or_con == "2":
        return mag_azimuth - 90., -field_dip
    if or_con == "3":  # lab_mag_az=mag_az;  sample_dip = 90.-dip
        return mag_azimuth, 90. - field_dip
    if or_con == "4":  # lab_mag_az=mag_az;  sample_dip = dip
        return mag_azimuth, field_dip
    if or_con == "5":  # lab_mag_az=mag_az;  sample_dip = dip-90.
        return mag_azimuth, field_dip - 90.
    if or_con == "6":  # lab_mag_az=mag_az-90.;  sample_dip = 90.-dip
        return mag_azimuth - 90., 90. - field_dip
    if or_con == "7":  # lab_mag_az=mag_az;  sample_dip = 90.-dip
        return mag_azimuth - 90., 90. - field_dip
    print("Error in orientation convention")
1327187
private void rotateRight(int n) {
        final int l = left(n);
        final int rl = right(l);
        left(n, rl);
        if (rl != NIL) {
            parent(rl, n);
        }
        final int p = parent(n);
        parent(l, p);
        if (p == NIL) {
            root = l;
        } else if (right(p) == n) {
            right(p, l);
        } else {
            assert left(p) == n;
            left(p, l);
        }
        right(l, n);
        parent(n, l);
        fixAggregates(n);
        fixAggregates(parent(n));
    }
794863
def rotate(p, rad, o=(0, 0)):
    
    v = vector(o, p)
    fx = lambda x, y, d: x * cos(d) - y * sin(d)
    fy = lambda x, y, d: x * sin(d) + y * cos(d)
    rv = fx(v[0], v[1], rad), fy(v[0], v[1], rad)
    return translate(rv, o)
1121339
def _rotate(degrees:uniform):
    ""
    angle = degrees * math.pi / 180
    return [[cos(angle), -sin(angle), 0.],
            [sin(angle),  cos(angle), 0.],
            [0.        ,  0.        , 1.]]
162621
public static int rotateCCW (int direction, int ticks)
    {
        for (int ii = 0; ii < ticks; ii++) {
            direction = FINE_CCW_ROTATE[direction];
        }
        return direction;
    }
349882
def _symbolic_rotation_helper():
    """"""
    from sympy import symbols, Matrix

    cpsi, spsi = symbols('cpsi, spsi')
    cth, sth = symbols('cth, sth')
    cphi, sphi = symbols('cphi, sphi')
    Rpsi = Matrix([[cpsi, spsi, 0], [-spsi, cpsi, 0], [0, 0, 1]])
    Rth = Matrix([[1, 0, 0], [0, cth, sth], [0, -sth, cth]])
    Rphi = Matrix([[cphi, sphi, 0], [-sphi, cphi, 0], [0, 0, 1]])

    Q = Rpsi * Rth * Rphi

    epsy, epsz = symbols('epsy, epsz')
    A = Matrix([[1, 0, 0], [0, epsy, 0], [0, 0, epsz]])

    D = Q * A * Q.T

    for i in range(3):
        for j in range(3):
            print('D[%d, %d] = %s' % (i, j, D[i, j]))
999681
def pt_rotate(pt=(0.0, 0.0), angle=[0.0], center=(0.0, 0.0)):
    '''
    '''
    assert isinstance(pt, tuple)
    l_pt = len(pt)
    assert l_pt > 1
    for i in pt:
        assert isinstance(i, float)
    assert isinstance(angle, list)
    l_angle = len(angle)
    assert l_angle == l_pt-1
    for i in angle:
        assert isinstance(i, float)
        assert abs(i) <= 2*pi
    assert isinstance(center, tuple)
    assert len(center) == l_pt
    for i in center:
        assert isinstance(i, float)

    # Get vector from center to point and use to get relative polar coordinate.
    v_cart = [pt[i] - center[i] for i in range(l_pt)]

    # Length of vector needs to stay constant for new point.
    v_pol_l = [sqrt(v_cart[i]**2 + v_cart[i+1]**2) for i in range(l_angle)]
    v_pol_a = [(atan(v_cart[i+1] / v_cart[i]) if v_cart[i] != 0.0 else pi/2) + pi*int(pt[i] < center[i]) \
               for i in range(l_angle)]

    # Add rotation angle then convert back to cartesian vector.
    n_pol_a = [v_pol_a[i] + angle[i] for i in range(l_angle)]
    n_cart = [v_pol_l[0] * cos(n_pol_a[0])] + [v_pol_l[i] * sin(n_pol_a[i])\
                                               for i in range(l_angle)]

    # Add in the centre offset to get original offset from c.
    r = [n_cart[i] + center[i] for i in range(l_pt)]
    return tuple(r)