<commit_before>//
//  CubicLinePathGenerator.swift
//  SwiftCharts
//
//  Created by ischuetz on 28/04/15.
//  Copyright (c) 2015 ivanschuetz. All rights reserved.
//

import UIKit

public class CubicLinePathGenerator: ChartLinesViewPathGenerator {
    
    private let tension1: CGFloat
    private let tension2: CGFloat
    
    /**
    - parameter tension1: p1 tension, where 0 is straight line. A value higher than 0.3 is not recommended.
    - parameter tension2: p2 tension, where 0 is straight line. A value higher than 0.3 is not recommended.
    */
    public init(tension1: CGFloat, tension2: CGFloat) {
        self.tension1 = tension1
        self.tension2 = tension2
    }
    
    // src: http://stackoverflow.com/a/29876400/930450 (modified)
    public func generatePath(points points: [CGPoint], lineWidth: CGFloat) -> UIBezierPath {
        
        let path = UIBezierPath()
        var p0: CGPoint
        var p1: CGPoint
        var p2: CGPoint
        var p3: CGPoint
        var tensionBezier1: CGFloat
        var tensionBezier2: CGFloat
        
        path.lineCapStyle = .Round
        path.lineJoinStyle = .Round
        
        var previousPoint1: CGPoint = CGPointZero
        
        path.moveToPoint(points.first!)
        
        for i in 0..<(points.count - 1) {
            p1 = points[i]
            p2 = points[i + 1]
            
            tensionBezier1 = self.tension1
            tensionBezier2 = self.tension2
            
            if i > 0 {  // Exception for first line because there is no previous point
                p0 = previousPoint1
                
                if p2.y - p1.y =~ p2.y - p0.y {
                    tensionBezier1 = 0
                }
                
            } else {
                tensionBezier1 = 0<commit_msg>Add guard for empty line<commit_after>//
//  CubicLinePathGenerator.swift
//  SwiftCharts
//
//  Created by ischuetz on 28/04/15.
//  Copyright (c) 2015 ivanschuetz. All rights reserved.
//

import UIKit

public class CubicLinePathGenerator: ChartLinesViewPathGenerator {
    
    private let tension1: CGFloat
    private let tension2: CGFloat
    
    /**
    - parameter tension1: p1 tension, where 0 is straight line. A value higher than 0.3 is not recommended.
    - parameter tension2: p2 tension, where 0 is straight line. A value higher than 0.3 is not recommended.
    */
    public init(tension1: CGFloat, tension2: CGFloat) {
        self.tension1 = tension1
        self.tension2 = tension2
    }
    
    // src: http://stackoverflow.com/a/29876400/930450 (modified)
    public func generatePath(points points: [CGPoint], lineWidth: CGFloat) -> UIBezierPath {
        
        let path = UIBezierPath()
        
        guard !points.isEmpty else {return path}
        
        var p0: CGPoint
        var p1: CGPoint
        var p2: CGPoint
        var p3: CGPoint
        var tensionBezier1: CGFloat
        var tensionBezier2: CGFloat
        
        path.lineCapStyle = .Round
        path.lineJoinStyle = .Round
        
        var previousPoint1: CGPoint = CGPointZero
        
        path.moveToPoint(points.first!)
        
        for i in 0..<(points.count - 1) {
            p1 = points[i]
            p2 = points[i + 1]
            
            tensionBezier1 = self.tension1
            tensionBezier2 = self.tension2
            
            if i > 0 {  // Exception for first line because there is no previous point
                p0 = previousPoint1
                
                if p2.y - p1.y =~ p2.y - p0.y {
                    tensionBezier1 = 0
                }
                
            } else {
                tensionBezier1 = 0
{'fraction_non_alphanumeric': 0.07671381936887922, 'fraction_numerical': 0.03754080522306855, 'mean_word_length': 1.5985865724381625, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4731067', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1088, 'n_words': 312}