<commit_before>//
//  ViewExtensions.swift
//  Dove
//
//  Created by <NAME> on 08/06/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import UIKit

public extension UIView {
	public func render() -> UIImage? {
		UIGraphicsBeginImageContextWithOptions(self.frame.size, false, UIScreen.main.scale)
		
		defer {
			UIGraphicsEndImageContext()
		}
		
		guard let context = UIGraphicsGetCurrentContext() else {
			return nil
		}
		
		self.layer.render(in: context)
		
		return UIGraphicsGetImageFromCurrentImageContext()
	}
}

public extension UIImage {
	public func apply(filter: CIFilter, options: [String: Any]? = nil) -> UIImage? {
		guard let image = self.cgImage else {
			return nil
		}
		
		filter.setValue(CoreImage.CIImage(cgImage: image), forKey: kCIInputImageKey)
		
		if let options = options {
			for (option, value) in options {
				filter.setValue(value, forKey: option)
			}
		}
		
		if let output = filter.outputImage {
			if let output = context.createCGImage(output, from: output.extent) {
				return UIImage(cgImage: output, scale: self.scale, orientation: self.imageOrientation)
			}
		}
		
		return nil
	}
	
	public func flip(orientation: UIImageOrientation) -> UIImage? {
		guard let image = self.cgImage else {
			return nil
		}
		
		return UIImage(cgImage: image, scale: self.scale, orientation: orientation)
	}
	
	public func isEqualData(image: UIImage) -> Bool {
		if let first = UIImagePNGRepresentation(self), let second = UIImagePNGRepresentation(image) {
			if first.count != second.count {
				return first == second
			} else {
				return true
			}
		}
		
		return false
	}
}

public extension UIColor {
	func adjust(amount: CGFloat) -> UIColor {
		var red = CGFloat(0)
		var green = CGFloat(0)
		var blue = CGFloat(0)
		
		var alpha = CGFloat(0)
		
		if self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) {
			return UIColor(red: red + amount, green: green + amount, blue: blue + amount, alpha: alpha)
		}
		
		return self
	}
}

public extension UITableViewCell {
	public var selectedColour: UIColor? {
		get {
			return self.selectedBackgroundView?.backgroundColor
		}
		set {
			self.selectedBackgroundView = self.selectedBackgroundView ?? UIView()
			self.selectedBackgroundView?.backgroundColor = newValue
		}
	}
}

public extension UICollectionViewCell {
	public var selectedColour: UIColor? {
		get {
			return self.selectedBackgroundView?.backgroundColor
		}
		set {
			self.selectedBackgroundView = self.selectedBackgroundView ?? UIView()
			self.selectedBackgroundView?.backgroundColor = newValue
		}
	}
}

public extension UITraitCollection {
	public func equals(_ horizontal: UIUserInterfaceSizeClass, _ vertical: UIUserInterfaceSizeClass) -> Bool {
		return self.horizontalSizeClass == horizontal && self.verticalSizeClass == vertical
	}
	
	public func equals(_ horizontal: [UIUserInterfaceSizeClass], _ vertical: [UIUserInterfaceSizeClass]) -> Bool {
		return horizontal.contains(self.horizontalSizeClass) && vertical.contains(self.verticalSizeClass)
	}
}

private let context = CIContext()<commit_msg>Maybe this will work now.<commit_after>//
//  ViewExtensions.swift
//  Dove
//
//  Created by <NAME> on 08/06/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import UIKit

public extension UIView {
	public func render() -> UIImage? {
		UIGraphicsBeginImageContextWithOptions(self.frame.size, false, UIScreen.main.scale)
		
		defer {
			UIGraphicsEndImageContext()
		}
		
		guard let context = UIGraphicsGetCurrentContext() else {
			return nil
		}
		
		self.layer.render(in: context)
		
		return UIGraphicsGetImageFromCurrentImageContext()
	}
}

public extension UIImage {
	public func apply(filter: CIFilter, options: [String: Any]? = nil) -> UIImage? {
		guard let image = self.cgImage else {
			return nil
		}
		
		filter.setValue(CoreImage.CIImage(cgImage: image), forKey: kCIInputImageKey)
		
		if let options = options {
			for (option, value) in options {
				filter.setValue(value, forKey: option)
			}
		}
		
		if let output = filter.outputImage {
			if let output = context.createCGImage(output, from: output.extent) {
				return UIImage(cgImage: output, scale: self.scale, orientation: self.imageOrientation)
			}
		}
		
		return nil
	}
	
	public func flip(orientation: UIImageOrientation) -> UIImage? {
		guard let image = self.cgImage else {
			return nil
		}
		
		return UIImage(cgImage: image, scale: self.scale, orientation: orientation)
	}
	
	public func isEqualData(image: UIImage) -> Bool {
		if let first = UIImagePNGRepresentation(self), let second = UIImagePNGRepresentation(image) {
			if first.count != second.count {
				return first == second
			} else {
				return true
			}
		}
		
		return false
	}
}

public extension UIColor {
	func adjust(amount: CGFloat) -> UIColor {
		var red = CGFloat(0)
		var green = CGFloat(0)
		var blue = CGFloat(0)
		
		var alpha = CGFloat(0)
		
		if self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) {
			return UIColor(red: red + amount, green: green + amount, blue: blue + amount, alpha: alpha)
		}
		
		return self
	}
}

public extension UITableViewCell {
	public var selectedColour: UIColor? {
		get {
			return self.selectedBackgroundView?.backgroundColor
		}
		set {
			self.selectedBackgroundView = UIView(colour: newValue)
		}
	}
}

public extension UICollectionViewCell {
	public var selectedColour: UIColor? {
		get {
			return self.selectedBackgroundView?.backgroundColor
		}
		set {
			self.selectedBackgroundView = UIView(colour: newValue)
		}
	}
}

public extension UITraitCollection {
	public func equals(_ horizontal: UIUserInterfaceSizeClass, _ vertical: UIUserInterfaceSizeClass) -> Bool {
		return self.horizontalSizeClass == horizontal && self.verticalSizeClass == vertical
	}
	
	public func equals(_ horizontal: [UIUserInterfaceSizeClass], _ vertical: [UIUserInterfaceSizeClass]) -> Bool {
		return horizontal.contains(self.horizontalSizeClass) && vertical.contains(self.verticalSizeClass)
	}
}

private extension UIView {
	convenience init(colour: UIColor) {
		self.init()
		
		self.backgroundColor = colour
	}
}

private let context = CIContext()
{'fraction_non_alphanumeric': 0.10190151145782544, 'fraction_numerical': 0.00520071509832602, 'mean_word_length': 3.815336463223787, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '3381129', 'n_tokens_mistral': 2176, 'n_tokens_neox': 1890, 'n_words': 492}