<commit_before>import UIKit


/// UIView subclass to draw one segment in a 7Segment display.
class Segment: UIView {
    
    enum Orientation {
        case horizontal
        case vertical
    }
    
    /// How 'thick' the segment is. This is always the smaller value between length and thickness.
    var thickness: CGFloat = 5.0
    
    /// Length of the segment. It is always the longer value between length and thickness.
    var length: CGFloat = 25.0
    
    /// The side of triangle at each corner that is cutoff to give the 'tip' of the segment. Otherwise it is 1/15th of the length.
    var cutoff: CGFloat = 5.0
    
    /// Indicates whether the segment is "upright": vertical or "sideways": horizontal. This is ONLY to indicate which dimension is longer to help draw the segment.
    var orientation: Orientation
    
    /// The dominant color of each segment. Defaults to red.
    var fillColor: UIColor = UIColor.red
    
    /// The outline color of each segment. Defaults to white.
    var strokeColor: UIColor = UIColor.white
    
    /// The width used to stroke the outline of each segment. It is always thickness/10.
    var strokeWidth: CGFloat = 0.5
    
    override init(frame: CGRect) {
        let h = frame.size.height
        let w = frame.size.width
        
        orientation = w > h ? .horizontal : .vertical
        switch orientation {
        case .horizontal:
            length = w
            thickness = h
        case .vertical:
            length = h
            thickness = w
        }
        
        cutoff = length/10
        strokeWidth = thickness/10
        
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func draw(_ rect: CGRect) {
        super.draw(rect)
        
        let context = UIGraphicsGetCurrentContext()
        
        // Set up the stroke/fill color and stroke width.
        context?.setStrokeColor(strokeColor.cgColor)
        context?.setLineWidth(strokeWidth)
        context?.setFillColor(fillColor.cgColor)
        
        // Create an offset to account for the stroke thickness and prevent drawing outside the rect.
        let offset = strokeWidth/2
        
        switch orientation {
        case .horizontal:
            context?.move(to: CGPoint(x: cutoff, y: offset))
            context?.addLine(to: CGPoint(x: length - cutoff, y: offset))
            context?.addLine(to: CGPoint(x: length - offset, y: thickness/2))
            context?.addLine(to: CGPoint(x: length - cutoff, y: thickness - offset))
            context?.addLine(to: CGPoint(x: cutoff, y: thickness - offset))
            context?.addLine(to: CGPoint(x: offset, y: thickness/2))
            
        case .vertical:
            context?.move(to: CGPoint(x: offset, y: cutoff))
            context?.addLine(to: CGPoint(x: offset, y: length - cutoff))
            context?.addLine(to: CGPoint(x: thickness/2, y: length - offset))
            context?.addLine(to: CGPoint(x: thickness - offset, y: length - cutoff))
            context?.addLine(to: CGPoint(x: thickness - offset, y: cutoff))
            context?.addLine(to: CGPoint(x: thickness/2, y: offset))
        }

        context?.closePath()
        context?.drawPath(using: .fillStroke)
    }
    
    override var description: String {
        return "\(orientation) > (\(thickness), \(length))"
    }
}

let seg = Segment(frame: CGRect.init(x: 0, y: 0, width: 30, height: 150))

let hseg = Segment(frame: CGRect.init(x: 0, y: 0, width: 150, height: 30))

<commit_msg>Added property observers to fill and stroke color and made orientation, cutoff and strokeWidth private.<commit_after>import UIKit


/// UIView subclass to draw one segment in a 7Segment display.
class Segment: UIView {
    
    enum Orientation {
        case horizontal
        case vertical
    }
    
    /// How 'thick' the segment is. This is always the smaller value between length and breadth.
    var breadth: CGFloat = 5.0
    
    /// Length of the segment. It is always the longer value between length and breadth.
    var length: CGFloat = 25.0
    
    /// The dominant color of each segment. Defaults to red.
    var fillColor: UIColor = UIColor.red {
        didSet {
            setNeedsDisplay()
        }
    }
    
    /// The outline color of each segment. Defaults to white.
    var strokeColor: UIColor = UIColor.white {
        didSet {
            setNeedsDisplay()
        }
    }
    
    /// The side of triangle at each corner that is cutoff to give the 'tip' of the segment. Otherwise it is 1/15th of the length.
    private var cutoff: CGFloat { return length/10 }
    
    /// The width used to stroke the outline of each segment. It is always breadth/10.
    private var strokeWidth: CGFloat { return breadth/10 }
    
    /// Indicates whether the segment is "upright": vertical or "sideways": horizontal. This is ONLY to indicate which dimension is longer to help draw the segment.
    private var orientation: Orientation
    
    override init(frame: CGRect) {
        let h = frame.size.height
        let w = frame.size.width
        
        orientation = w > h ? .horizontal : .vertical
        switch orientation {
        case .horizontal:
            length = w
            breadth = h
        case .vertical:
            length = h
            breadth = w
        }
        
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func draw(_ rect: CGRect) {
        super.draw(rect)
        
        let context = UIGraphicsGetCurrentContext()
        
        // Set up the stroke/fill color and stroke width.
        context?.setStrokeColor(strokeColor.cgColor)
        context?.setLineWidth(strokeWidth)
        context?.setFillColor(fillColor.cgColor)
        
        // Create an offset to account for the stroke thickness and prevent drawing outside the rect.
        let offset = strokeWidth/2
        
        switch orientation {
        case .horizontal:
            context?.move(to: CGPoint(x: cutoff, y: offset))
            context?.addLine(to: CGPoint(x: length - cutoff, y: offset))
            context?.addLine(to: CGPoint(x: length - offset, y: breadth/2))
            context?.addLine(to: CGPoint(x: length - cutoff, y: breadth - offset))
            context?.addLine(to: CGPoint(x: cutoff, y: breadth - offset))
            context?.addLine(to: CGPoint(x: offset, y: breadth/2))
            
        case .vertical:
            context?.move(to: CGPoint(x: offset, y: cutoff))
            context?.addLine(to: CGPoint(x: offset, y: length - cutoff))
            context?.addLine(to: CGPoint(x: breadth/2, y: length - offset))
            context?.addLine(to: CGPoint(x: breadth - offset, y: length - cutoff))
            context?.addLine(to: CGPoint(x: breadth - offset, y: cutoff))
            context?.addLine(to: CGPoint(x: breadth/2, y: offset))
        }

        context?.closePath()
        context?.drawPath(using: .fillStroke)
    }
    
    override var description: String {
        return "\(orientation) > (\(breadth), \(length))"
    }
}

let seg = Segment(frame: CGRect.init(x: 0, y: 0, width: 30, height: 150))

let hseg = Segment(frame: CGRect.init(x: 0, y: 0, width: 150, height: 30))


{'fraction_non_alphanumeric': 0.09743726641751202, 'fraction_numerical': 0.009610250934329953, 'mean_word_length': 2.0860790774299836, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 7, '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': '3422616', 'n_tokens_mistral': 2206, 'n_tokens_neox': 2084, 'n_words': 717}