<commit_before>//
//  UIView+RGUIExtension.swift
//  RGUIExtension
//
//  Created by RAIN on 15/11/30.
//  Copyright © 2015年 Smartech. All rights reserved.
//

import UIKit

extension RGUIExtension where Base: UIView {
    /// 为视图添加边线
    ///
    /// - Parameters:
    ///   - width: 边线宽度
    ///   - cornerRadius: 边线圆角半径, 若无圆角则值为 0
    ///   - color: 边线颜色
    public func addBorder(
        width: CGFloat,
        cornerRadius: CGFloat,
        color: UIColor)
    {
        base.layer.masksToBounds = true
        base.layer.borderWidth = width
        base.layer.cornerRadius = cornerRadius
        base.layer.borderColor = color.cgColor
    }

    /// 在 view 的指定位置加指定颜色的线
    ///
    /// - Parameters:
    ///   - startPoint: 起始点坐标
    ///   - length: 长度
    ///   - width: 宽度
    ///   - color: 颜色
    ///   - direction: 方向
    /// - Returns: 按参数条件添加的线
    public func drawLine(
        from startPoint: CGPoint,
        length: CGFloat,
        width: CGFloat,
        color: UIColor,
        direction: RGLineDirection = .horizontal) -> UIView
    {
        let line = UIView()
        line.backgroundColor = color

        switch (direction) {
        case .horizontal:
            line.frame = CGRect(x: startPoint.x, y: startPoint.y, width: length, height: width)

        case .vertical:
            line.frame = CGRect(x: startPoint.x, y: startPoint.y, width: width, height: length)
        }

        base.addSubview(line)

        return line
    }
}

//  MARK: Rect
extension UIView {
    //  MARK: size
    /// size
    var size: CGSize { return self.bounds.size }

    /// width
    var width: CGFloat {
        get {
            return self.size.width
        }

        set {
            var frame = self.frame
            frame.size.width = newValue
            self.frame = frame
        }
    }

    /// height
    var height: CGFloat {
        get {
            return self.size.height
        }

        set {
            var frame = self.frame
            frame.size.height = newValue
            self.frame = frame
        }
    }

    //  MARK: origin
    /// x
    var x: CGFloat {
        get {
            return self.frame.origin.x
        }

        set {
            var frame = self.frame
            frame.origin.x = newValue
            self.frame = frame
        }
    }

    /// y
    var y: CGFloat {
        get {
            return self.frame.origin.y
        }

        set {
            var frame = self.frame
            frame.origin.y = newValue
            self.frame = frame
        }
    }
    
    /// right side x
    var maxX: CGFloat { return self.x + self.width }
    
    /// bottom y
    var maxY: CGFloat { return self.y + self.height }
    
    /// mid x
    var midX: CGFloat { return (self.x + self.maxX) / 2 }
    
    /// mid y
    var midY: CGFloat { return (self.y + self.maxY) / 2 }
}


//  MARK: DrawTools
/**
 绘制线条的方向
 
 - Horizontal: 水平方向
 - Vertical:   竖直方向
 */
public enum RGLineDirection {
    case horizontal
    case vertical
}

extension UIView {
     /**
     为视图添加边线
     
     - parameter width:        边线宽度
     - parameter cornerRadius: 边线圆角半径, 若无圆角则值为0
     - parameter color:        边线颜色
     */
    public func rue_addBorder(_ width: CGFloat, cornerRadius: CGFloat, color: UIColor) {
        self.layer.masksToBounds = true
        self.layer.borderWidth = width
        self.layer.cornerRadius = cornerRadius
        self.layer.borderColor = color.cgColor
    }

     /**
     在 view 的指定位置加指定颜色的线
     
     - parameter startPoint: 起始点坐标
     - parameter length:     长度
     - parameter width:      宽度
     - parameter color:      颜色
     - parameter direction:  方向
     
     - returns: 按参数条件添加的线<commit_msg>refactor（UIView）：deprecated a method<commit_after>//
//  UIView+RGUIExtension.swift
//  RGUIExtension
//
//  Created by RAIN on 15/11/30.
//  Copyright © 2015年 Smartech. All rights reserved.
//

import UIKit

extension RGUIExtension where Base: UIView {
    /// 为视图添加边线
    ///
    /// - Parameters:
    ///   - width: 边线宽度
    ///   - cornerRadius: 边线圆角半径, 若无圆角则值为 0
    ///   - color: 边线颜色
    public func addBorder(
        width: CGFloat,
        cornerRadius: CGFloat,
        color: UIColor)
    {
        base.layer.masksToBounds = true
        base.layer.borderWidth = width
        base.layer.cornerRadius = cornerRadius
        base.layer.borderColor = color.cgColor
    }

    /// 在 view 的指定位置加指定颜色的线
    ///
    /// - Parameters:
    ///   - startPoint: 起始点坐标
    ///   - length: 长度
    ///   - width: 宽度
    ///   - color: 颜色
    ///   - direction: 方向
    /// - Returns: 按参数条件添加的线
    public func drawLine(
        from startPoint: CGPoint,
        length: CGFloat,
        width: CGFloat,
        color: UIColor,
        direction: RGLineDirection = .horizontal) -> UIView
    {
        let line = UIView()
        line.backgroundColor = color

        switch (direction) {
        case .horizontal:
            line.frame = CGRect(x: startPoint.x, y: startPoint.y, width: length, height: width)

        case .vertical:
            line.frame = CGRect(x: startPoint.x, y: startPoint.y, width: width, height: length)
        }

        base.addSubview(line)

        return line
    }
}

//  MARK: Rect
extension UIView {
    //  MARK: size
    /// size
    var size: CGSize { return self.bounds.size }

    /// width
    var width: CGFloat {
        get {
            return self.size.width
        }

        set {
            var frame = self.frame
            frame.size.width = newValue
            self.frame = frame
        }
    }

    /// height
    var height: CGFloat {
        get {
            return self.size.height
        }

        set {
            var frame = self.frame
            frame.size.height = newValue
            self.frame = frame
        }
    }

    //  MARK: origin
    /// x
    var x: CGFloat {
        get {
            return self.frame.origin.x
        }

        set {
            var frame = self.frame
            frame.origin.x = newValue
            self.frame = frame
        }
    }

    /// y
    var y: CGFloat {
        get {
            return self.frame.origin.y
        }

        set {
            var frame = self.frame
            frame.origin.y = newValue
            self.frame = frame
        }
    }
    
    /// right side x
    var maxX: CGFloat { return self.x + self.width }
    
    /// bottom y
    var maxY: CGFloat { return self.y + self.height }
    
    /// mid x
    var midX: CGFloat { return (self.x + self.maxX) / 2 }
    
    /// mid y
    var midY: CGFloat { return (self.y + self.maxY) / 2 }
}


//  MARK: DrawTools
/**
 绘制线条的方向
 
 - Horizontal: 水平方向
 - Vertical:   竖直方向
 */
public enum RGLineDirection {
    case horizontal
    case vertical
}

extension UIView {
     /**
     为视图添加边线
     
     - parameter width:        边线宽度
     - parameter cornerRadius: 边线圆角半径, 若无圆角则值为0
     - parameter color:        边线颜色
     */
    @available(*, deprecated, message: "Extensions directly on UIView are deprecated. Use `UIView.rue.addBorder` instead.", renamed: "rue.addBorder")
    public func rue_addBorder(_ width: CGFloat, cornerRadius: CGFloat, color: UIColor) {
        self.layer.masksToBounds = true
        self.layer.borderWidth = width
        self.layer.cornerRadius = cornerRadius
        self.layer.borderColor = color.cgColor
    }

     /**
     在 view 的指定位置加指定颜色的线
     
     - parameter startPoint: 起始点坐标
     - parameter length:     长度
     - parameter width:      宽度
     - parameter color:      颜色
     - parameter direction:  方向
     
     - returns: 按参数条件添加的线
{'fraction_non_alphanumeric': 0.10361254466057959, 'fraction_numerical': 0.003705174010850867, 'mean_word_length': 1.4286632390745502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '255698', 'n_tokens_mistral': 2561, 'n_tokens_neox': 2597, 'n_words': 587}