<commit_before>//
//  Gradient.swift
//  SunriseSunset
//
//  Created by <NAME> on 2016-05-18.
//  Copyright © 2016 Puddllee. All rights reserved.
//

import Foundation
import UIKit
import EDSunriseSet
import CoreLocation

struct SunTimeLine: Comparable {
    var suntime: Suntime
    var sunline: Sunline
    
    init(suntime: Suntime, sunline: Sunline) {
        self.suntime = suntime
        self.sunline = sunline
    }
}

func < (lhs: SunTimeLine, rhs: SunTimeLine) -> Bool {
    return lhs.suntime < rhs.suntime
}

func == (lhs: SunTimeLine, rhs: SunTimeLine) -> Bool {
    return lhs.suntime == rhs.suntime
}

struct SunTimeMarker: Comparable {
    var sunTimeLine: SunTimeLine
    var percent: Float
    
    init(sunTimeLine: SunTimeLine, percent: Float) {
        self.sunTimeLine = sunTimeLine
        self.percent = percent
    }
}

func < (lhs: SunTimeMarker, rhs: SunTimeMarker) -> Bool {
    return lhs.sunTimeLine.suntime < rhs.sunTimeLine.suntime
}

func == (lhs: SunTimeMarker, rhs: SunTimeMarker) -> Bool {
    return lhs.sunTimeLine.suntime == rhs.sunTimeLine.suntime
}

protocol SunProtocol {
    func collisionIsHappening()
    func collisionNotHappening()
}

class Sun {
    
    // Number of minutes a full screen height is
    let screenMinutes: Float
    
    // Height of the screen
    var screenHeight: Float
    
    // Height of the view where the gradient lives
    var sunHeight: Float
    
    // Ratio between screen height and sun view
    var sunViewScale: Float
    
    // View where the gradient lives
    var sunView: UIView
    
    // Gradient that animates to show time of day
    var gradientLayer: CAGradientLayer
    
    // The label for displaying current time
    var nowTimeLabel: UILabel
    
    // The label for displaying "now" text
    var nowLabel: UILabel
    
    // Formatter for now label text
    let nowTextFormatter = NSDateFormatter()
    
    var offset: NSTimeInterval = 0
    
    // Whether or not the sun areas or visible
    var sunAreasVisible = true
    
    let defaults = NSUserDefaults.standardUserDefaults()
    var now: NSDate = NSDate()
    var location: CLLocationCoordinate2D!
    let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
    
    var delegate: SunProtocol?
    
//    var suntimes: [Suntime] = []
//    var sunlines: [Sunline] = []
    var sunTimeLines: [SunTimeLine] = []
    var sunAreas: [SunArea] = []
    
    init(screenMinutes: Float, screenHeight: Float, sunHeight: Float, sunView: UIView, gradientLayer: CAGradientLayer, nowTimeLabel: UILabel, nowLabel: UILabel) {
        self.screenMinutes = screenMinutes
        self.screenHeight = screenHeight
        self.sunHeight = sunHeight
        self.sunViewScale = Float(Float(sunHeight) / Float(screenHeight))
        self.sunView = sunView
        self.gradientLayer = gradientLayer
        self.nowTimeLabel = nowTimeLabel
        self.nowLabel = nowLabel
        
        gradientLayer.frame = sunView.bounds
        
        nowTextFormatter.dateFormat = "MMMM d"
        
        timeFormatUpdate()
        
        calendar.timeZone = NSTimeZone.localTimeZone()
        
        createSunAreas()
        
        for dayNumber in 1...3 {
            createSuntime(.AstronomicalDusk, view: sunView, dayNumber: dayNumber)
            createSuntime(.NauticalDusk, view: sunView, dayNumber: dayNumber)
            createSuntime(.CivilDusk, view: sunView, dayNumber: dayNumber)
            createSuntime(.Sunrise, view: sunView, dayNumber: dayNumber)
            createSuntime(.Sunset, view: sunView, dayNumber: dayNumber)<commit_msg>sun areas off by default<commit_after>//
//  Gradient.swift
//  SunriseSunset
//
//  Created by <NAME> on 2016-05-18.
//  Copyright © 2016 Puddllee. All rights reserved.
//

import Foundation
import UIKit
import EDSunriseSet
import CoreLocation

struct SunTimeLine: Comparable {
    var suntime: Suntime
    var sunline: Sunline
    
    init(suntime: Suntime, sunline: Sunline) {
        self.suntime = suntime
        self.sunline = sunline
    }
}

func < (lhs: SunTimeLine, rhs: SunTimeLine) -> Bool {
    return lhs.suntime < rhs.suntime
}

func == (lhs: SunTimeLine, rhs: SunTimeLine) -> Bool {
    return lhs.suntime == rhs.suntime
}

struct SunTimeMarker: Comparable {
    var sunTimeLine: SunTimeLine
    var percent: Float
    
    init(sunTimeLine: SunTimeLine, percent: Float) {
        self.sunTimeLine = sunTimeLine
        self.percent = percent
    }
}

func < (lhs: SunTimeMarker, rhs: SunTimeMarker) -> Bool {
    return lhs.sunTimeLine.suntime < rhs.sunTimeLine.suntime
}

func == (lhs: SunTimeMarker, rhs: SunTimeMarker) -> Bool {
    return lhs.sunTimeLine.suntime == rhs.sunTimeLine.suntime
}

protocol SunProtocol {
    func collisionIsHappening()
    func collisionNotHappening()
}

class Sun {
    
    // Number of minutes a full screen height is
    let screenMinutes: Float
    
    // Height of the screen
    var screenHeight: Float
    
    // Height of the view where the gradient lives
    var sunHeight: Float
    
    // Ratio between screen height and sun view
    var sunViewScale: Float
    
    // View where the gradient lives
    var sunView: UIView
    
    // Gradient that animates to show time of day
    var gradientLayer: CAGradientLayer
    
    // The label for displaying current time
    var nowTimeLabel: UILabel
    
    // The label for displaying "now" text
    var nowLabel: UILabel
    
    // Formatter for now label text
    let nowTextFormatter = NSDateFormatter()
    
    var offset: NSTimeInterval = 0
    
    // Whether or not the sun areas or visible
    var sunAreasVisible = true
    
    let defaults = NSUserDefaults.standardUserDefaults()
    var now: NSDate = NSDate()
    var location: CLLocationCoordinate2D!
    let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
    
    var delegate: SunProtocol?
    
//    var suntimes: [Suntime] = []
//    var sunlines: [Sunline] = []
    var sunTimeLines: [SunTimeLine] = []
    var sunAreas: [SunArea] = []
    
    init(screenMinutes: Float, screenHeight: Float, sunHeight: Float, sunView: UIView, gradientLayer: CAGradientLayer, nowTimeLabel: UILabel, nowLabel: UILabel) {
        self.screenMinutes = screenMinutes
        self.screenHeight = screenHeight
        self.sunHeight = sunHeight
        self.sunViewScale = Float(Float(sunHeight) / Float(screenHeight))
        self.sunView = sunView
        self.gradientLayer = gradientLayer
        self.nowTimeLabel = nowTimeLabel
        self.nowLabel = nowLabel
        
        gradientLayer.frame = sunView.bounds
        
        nowTextFormatter.dateFormat = "MMMM d"
        
        timeFormatUpdate()
        
        calendar.timeZone = NSTimeZone.localTimeZone()
        
        createSunAreas()
        toggleSunAreas()
        
        for dayNumber in 1...3 {
            createSuntime(.AstronomicalDusk, view: sunView, dayNumber: dayNumber)
            createSuntime(.NauticalDusk, view: sunView, dayNumber: dayNumber)
            createSuntime(.CivilDusk, view: sunView, dayNumber: dayNumber)
            createSuntime(.Sunrise, view: sunView, dayNumber: dayNumber)
            createSuntime(.Sunset, view: sunView, dayNumber: dayNumber)
{'fraction_non_alphanumeric': 0.0828972734783806, 'fraction_numerical': 0.004406499586890664, 'mean_word_length': 2.609840954274354, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '7212417', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2158, 'n_words': 600}