// Rotate source file to destination file if source file exists.
508228
func (self *RotatingFileHandler) RotateFile(sourceFile, destFile string) error {
	if FileExists(sourceFile) {
		if FileExists(destFile) {
			if err := os.Remove(destFile); err != nil {
				return err
			}
		}
		if err := os.Rename(sourceFile, destFile); err != nil {
			return err
		}
	}
	return nil
}
953351
func Rotate(p, axis Point, angle s1.Angle) Point {
	// Let M be the plane through P that is perpendicular to axis, and let
	// center be the point where M intersects axis. We construct a
	// right-handed orthogonal frame (dx, dy, center) such that dx is the
	// vector from center to P, and dy has the same length as dx. The
	// result can then be expressed as (cos(angle)*dx + sin(angle)*dy + center).
	center := axis.Mul(p.Dot(axis.Vector))
	dx := p.Sub(center)
	dy := axis.Cross(p.Vector)
	// Mathematically the result is unit length, but normalization is necessary
	// to ensure that numerical errors don't accumulate.
	return Point{dx.Mul(math.Cos(angle.Radians())).Add(dy.Mul(math.Sin(angle.Radians()))).Add(center).Normalize()}
}
939216
func (f *FileRotator) Write(p []byte) (n int, err error) {
	n = 0
	var forceRotate bool

	for n < len(p) {
		// Check if we still have space in the current file, otherwise close and
		// open the next file
		if forceRotate || f.currentWr >= f.FileSize {
			forceRotate = false
			f.flushBuffer()
			f.currentFile.Close()
			if err := f.nextFile(); err != nil {
				f.logger.Error("error creating next file", "err", err)
				return 0, err
			}
		}
		// Calculate the remaining size on this file and how much we have left
		// to write
		remainingSpace := f.FileSize - f.currentWr
		remainingToWrite := int64(len(p[n:]))

		// Check if we are near the end of the file. If we are we attempt to
		// avoid a log line being split between two files.
		var nw int
		if (remainingSpace - lineScanLimit) < remainingToWrite {
			// Scan for new line and if the data up to new line fits in current
			// file, write to buffer
			idx := bytes.IndexByte(p[n:], newLineDelimiter)
			if idx >= 0 && (remainingSpace-int64(idx)-1) >= 0 {
				// We have space so write it to buffer
				nw, err = f.writeToBuffer(p[n : n+idx+1])
			} else if idx >= 0 {
				// We found a new line but don't have space so just force rotate
				forceRotate = true
			} else if remainingToWrite > f.FileSize || f.FileSize-lineScanLimit < 0 {
				// There is no new line remaining but there is no point in
				// rotating since the remaining data will not even fit in the
				// next file either so just fill this one up.
				li := int64(n) + remainingSpace
				if remainingSpace > remainingToWrite {
					li = int64(n) + remainingToWrite
				}
				nw, err = f.writeToBuffer(p[n:li])
			} else {
				// There is no new line in the data remaining for us to write
				// and it will fit in the next file so rotate.
				forceRotate = true
			}
		} else {
			// Write all the bytes in the current file
			nw, err = f.writeToBuffer(p[n:])
		}

		// Increment the number of bytes written so far in this method
		// invocation
		n += nw

		// Increment the total number of bytes in the file
		f.currentWr += int64(n)
		if err != nil {
			f.logger.Error("error writing to file", "err", err)

			// As bufio writer does not automatically recover in case of any
			// io error, we need to recover from it manually resetting the
			// writter.
			f.createOrResetBuffer()

			return
		}
	}
	return
}
428498
func RotateLeft64(value uint64, shift uint) (uint64){
    shift = shift & 0x3F

    return (value << shift) | (value >> (64 - shift))
}
1040951
func NewFileWriter(baseDir string, rotate bool) (err error) {
	singltonLock.Lock()
	defer singltonLock.Unlock()
	if nil != blog {
		return ErrAlreadyInit
	}

	fileWriter := new(MultiWriter)
	fileWriter.lock = new(sync.RWMutex)
	fileWriter.level = DEBUG
	fileWriter.closed = false

	fileWriter.writers = make(map[LevelType]Writer)
	for _, level := range Levels {
		fileName := fmt.Sprintf("%s.log", strings.ToLower(level.String()))
		writer, err := newBaseFileWriter(path.Join(baseDir, fileName), rotate)
		if nil != err {
			return err
		}
		fileWriter.writers[level] = writer
	}

	// log hook
	fileWriter.hook = nil
	fileWriter.hookLevel = DEBUG
	fileWriter.hookAsync = true

	blog = fileWriter
	return
}
1307520
func Rotate(dst draw.Image, src image.Image, opt *RotateOptions) error {
	if dst == nil {
		return errors.New("graphics: dst is nil")
	}
	if src == nil {
		return errors.New("graphics: src is nil")
	}

	angle := 0.0
	if opt != nil {
		angle = opt.Angle
	}

	return I.Rotate(angle).TransformCenter(dst, src, interp.Bilinear)
}
193630
func RotatingFileHandler(path string, limit uint, formatter Format) (Handler, error) {
	if err := os.MkdirAll(path, 0700); err != nil {
		return nil, err
	}
	files, err := ioutil.ReadDir(path)
	if err != nil {
		return nil, err
	}
	re := regexp.MustCompile(`\.log$`)
	last := len(files) - 1
	for last >= 0 && (!files[last].Mode().IsRegular() || !re.MatchString(files[last].Name())) {
		last--
	}
	var counter *countingWriter
	if last >= 0 && files[last].Size() < int64(limit) {
		// Open the last file, and continue to write into it until it's size reaches the limit.
		if counter, err = prepFile(filepath.Join(path, files[last].Name())); err != nil {
			return nil, err
		}
	}
	if counter == nil {
		counter = new(countingWriter)
	}
	h := StreamHandler(counter, formatter)

	return FuncHandler(func(r *Record) error {
		if counter.count > limit {
			counter.Close()
			counter.w = nil
		}
		if counter.w == nil {
			f, err := os.OpenFile(
				filepath.Join(path, fmt.Sprintf("%s.log", strings.Replace(r.Time.Format("060102150405.00"), ".", "", 1))),
				os.O_CREATE|os.O_APPEND|os.O_WRONLY,
				0600,
			)
			if err != nil {
				return err
			}
			counter.w = f
			counter.count = 0
		}
		return h.Log(r)
	}), nil
}
579346
func (n *IntNode) rotateLeft() (root *IntNode) {
	// Assumes: n has a right child.
	root = n.Right
	n.Right = root.Left
	root.Left = n
	root.Color = n.Color
	n.Color = llrb.Red

	root.Left.Range.End = intMaxRange(root.Left, root.Left.Left, root.Left.Right)
	if root.Left == nil {
		root.Range.Start = root.Interval.Start
	} else {
		root.Range.Start = root.Left.Range.Start
	}
	root.Range.End = intMaxRange(root, root.Left, root.Right)

	return
}
113620
func (m Matrix) Rotated(around Vec, angle float64) Matrix {
	sint, cost := math.Sincos(angle)
	m[4], m[5] = m[4]-around.X, m[5]-around.Y
	m = m.Chained(Matrix{cost, sint, -sint, cost, 0, 0})
	m[4], m[5] = m[4]+around.X, m[5]+around.Y
	return m
}
132012
func (n *Node) rotateRight() (root *Node) {
	// Assumes: n has a left child.
	root = n.Left
	n.Left = root.Right
	root.Right = n
	root.Color = n.Color
	n.Color = llrb.Red

	if root.Right.Left == nil {
		root.Right.Range.SetStart(root.Right.Elem.Start())
	} else {
		root.Right.Range.SetStart(root.Right.Left.Range.Start())
	}
	root.Right.Range.SetEnd(maxRange(root.Right, root.Right.Left, root.Right.Right))
	root.Range.SetEnd(maxRange(root, root.Left, root.Right))

	return
}
464053
func CopyDir(src string, dst string) (err error) {
	src = filepath.Clean(src)
	dst = filepath.Clean(dst)

	si, err := os.Stat(src)
	if err != nil {
		return err
	}
	if !si.IsDir() {
		return fmt.Errorf("source is not a directory")
	}

	_, err = os.Stat(dst)
	if err != nil && !os.IsNotExist(err) {
		return
	}
	if err == nil {
		return fmt.Errorf("destination already exists")
	}

	err = os.MkdirAll(dst, si.Mode())
	if err != nil {
		return
	}

	entries, err := ioutil.ReadDir(src)
	if err != nil {
		return
	}

	for _, entry := range entries {
		srcPath := filepath.Join(src, entry.Name())
		dstPath := filepath.Join(dst, entry.Name())

		// If the entry is a symlink, we copy the contents
		for entry.Mode()&os.ModeSymlink != 0 {
			target, err := os.Readlink(srcPath)
			if err != nil {
				return err
			}

			entry, err = os.Stat(target)
			if err != nil {
				return err
			}
		}

		if entry.IsDir() {
			err = CopyDir(srcPath, dstPath)
			if err != nil {
				return
			}
		} else {
			err = CopyFile(srcPath, dstPath)
			if err != nil {
				return
			}
		}
	}

	return
}
71567
func (vec *T) Rotate90DegLeft() *T {
	temp := vec[0]
	vec[0] = -vec[1]
	vec[1] = temp
	return vec
}
1222555
func NewRotateFileWriter(p string) *RotateFileWriter {
	// init data
	var tmp RotateFileWriter
	tmp.prefix, _ = filepath.Abs(p)

	// create the first file
	tmp.create()

	return &tmp
}
1136176
func RunLogRotate(logFilePath string, c *RotateConfig, logger lager.Logger) {
	Logger = logger
	if logFilePath == "" {
		return
	}
	checkConfig(c)
	if c == nil {
		go func() {
			for {
				LogRotate(filepath.Dir(logFilePath), LogRotateSize, LogBackupCount)
				time.Sleep(30 * time.Second)
			}
		}()
	} else {
		if c.RollingPolicy == RollingPolicySize {
			go func() {
				for {
					LogRotate(filepath.Dir(logFilePath), c.LogRotateSize, c.LogBackupCount)
					time.Sleep(30 * time.Second)
				}
			}()
		} else {
			go func() {
				for {
					LogRotate(filepath.Dir(logFilePath), 0, c.LogBackupCount)
					time.Sleep(24 * time.Hour * time.Duration(c.LogRotateDate))
				}
			}()
		}
	}
}
891631
func (l *LogFile) rotateRoutine() {
	go func() {
		for {
			if stats, err := os.Stat(l.Path()); err == nil {
				if stats.Size() >= l.size {
					l.Rotate()
				}
			}
			time.Sleep(l.rate)
		}
	}()
}
1365676
func (h *Handler) Rotate() error {
	var err error

	if h.file != nil {
		defer func(f *os.File) {
			f.Close()
		}(h.file)
	}

	h.file, err = os.OpenFile(h.config.FilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0664)
	if err != nil {
		return err
	}
	h.mu.Lock()
	defer h.mu.Unlock()
	h.logger.Out = h.file
	return nil
}
543161
func (vec *T) Rotated(angle float64) T {
	sinus := math.Sin(angle)
	cosinus := math.Cos(angle)
	return T{
		vec[0]*cosinus - vec[1]*sinus,
		vec[0]*sinus + vec[1]*cosinus,
	}
}