<commit_before>//
//  Copyright © 2016年 xiAo_Ju. All rights reserved.
//

enum LockItemViewDirection: Int {
    case none
    case top
    case rightTop
    case right
    case rightBottom
    case bottom
    case leftBottom
    case left
    case leftTop
    
    var angle: CGFloat {
        if case .none = self {
            return 0
        }
        return CGFloat.pi / 4 * CGFloat(rawValue - 1)
    }
}

final class LockItemView: UIView {
    public var direction: LockItemViewDirection = .none {
        willSet {
            layer.setAffineTransform(CGAffineTransform(rotationAngle: newValue.angle))
            setNeedsDisplay()
        }
    }

    public var selected: Bool = false {
        willSet {
            setNeedsDisplay()
        }
    }
    
    public func reset() {
        direction = .none
        selected = false
    }

    fileprivate var selectedRect: CGRect {
        let selectRectWH = bounds.width * options.scale
        let selectRectXY = bounds.width * (1 - options.scale) * 0.5
        return CGRect(x: selectRectXY, y: selectRectXY, width: selectRectWH, height: selectRectWH)
    }

    fileprivate var options: LockOptions!

    convenience init(options: LockOptions) {
        self.init(frame: .zero)
        self.options = options
        shapeLayer?.lineWidth = options.arcLineWidth
        backgroundColor = options.backgroundColor
    }
    
    private var shapeLayer: CAShapeLayer? {
        return layer as? CAShapeLayer
    }
    
    private var mainPath = UIBezierPath()

    override class var layerClass: AnyClass {
        return CAShapeLayer.self
    }

    override func draw(_ rect: CGRect) {
        // 上下文属性设置
        mainPath.removeAllPoints()
        propertySetting()
        // 外环：普通
        renderRing(with: rect)
        // 选中情况下，绘制背景色
        guard selected else {
            return
        }
        // 实心圆
        renderSolidCircle()
        // 三角形：方向标识
        renderDirect(with: rect)
    }

    private func propertySetting() {
        shapeLayer?.strokeColor = (selected ? options.circleLineSelectedColor : options.circleLineNormalColor).cgColor
    }

    // 绘制外环
    private func renderRing(with rect: CGRect) {
        let loopPath = UIBezierPath()
        loopPath.addEllipse(in: rect)
        shapeLayer?.fillColor = UIColor.clear.cgColor
        mainPath.append(loopPath)
        shapeLayer?.path = mainPath.cgPath
    }

    // 绘制实心圆
    private func renderSolidCircle() {
        let circlePath = UIBezierPath()
        circlePath.addEllipse(in: selectedRect)
        options.circleLineSelectedCircleColor.set()
        circlePath.fill()
        mainPath.append(circlePath)<commit_msg>修复三角绘制问题<commit_after>//
//  Copyright © 2016年 xiAo_Ju. All rights reserved.
//

enum LockItemViewDirection: Int {
    case none
    case top
    case rightTop
    case right
    case rightBottom
    case bottom
    case leftBottom
    case left
    case leftTop
    
    var angle: CGFloat {
        if case .none = self {
            return 0
        }
        return CGFloat.pi / 4 * CGFloat(rawValue - 1)
    }
}

final class LockItemView: UIView {
    public var direction: LockItemViewDirection = .none {
        willSet {
            layer.setAffineTransform(CGAffineTransform(rotationAngle: newValue.angle))
            setNeedsDisplay()
        }
    }

    public var selected: Bool = false {
        willSet {
            setNeedsDisplay()
        }
    }
    
    public func reset() {
        direction = .none
        selected = false
    }

    fileprivate var selectedRect: CGRect {
        let selectRectWH = bounds.width * options.scale
        let selectRectXY = bounds.width * (1 - options.scale) * 0.5
        return CGRect(x: selectRectXY, y: selectRectXY, width: selectRectWH, height: selectRectWH)
    }

    fileprivate var options: LockOptions!

    convenience init(options: LockOptions) {
        self.init(frame: .zero)
        self.options = options
        shapeLayer?.lineWidth = options.arcLineWidth
        backgroundColor = options.backgroundColor
    }
    
    private var shapeLayer: CAShapeLayer? {
        return layer as? CAShapeLayer
    }
    
    private var mainPath = UIBezierPath()

    override class var layerClass: AnyClass {
        return CAShapeLayer.self
    }

    override func draw(_ rect: CGRect) {
        // 上下文属性设置
        mainPath.removeAllPoints()
        propertySetting()
        // 外环：普通
        renderRing(with: rect)
        // 实心圆
        guard selected else { return }
        renderSolidCircle()
        if case .none = direction { return }
        // 三角形：方向标识
        renderDirect(with: rect)
    }

    private func propertySetting() {
        shapeLayer?.strokeColor = (selected ? options.circleLineSelectedColor : options.circleLineNormalColor).cgColor
    }

    // 绘制外环
    private func renderRing(with rect: CGRect) {
        let loopPath = UIBezierPath()
        loopPath.addEllipse(in: rect)
        shapeLayer?.fillColor = UIColor.clear.cgColor
        mainPath.append(loopPath)
        shapeLayer?.path = mainPath.cgPath
    }

    // 绘制实心圆
    private func renderSolidCircle() {
        let circlePath = UIBezierPath()
        circlePath.addEllipse(in: selectedRect)
        options.circleLineSelectedCircleColor.set()
        circlePath.fill()
        mainPath.append(circlePath)
{'fraction_non_alphanumeric': 0.08012760367798837, 'fraction_numerical': 0.0037530493525989865, 'mean_word_length': 2.0738177623990772, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2863991', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1589, 'n_words': 369}