This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension CGRect | |
| { | |
| func aspectFitInRect(target target: CGRect) -> CGRect | |
| { | |
| let scale: CGFloat = | |
| { | |
| let scale = target.width / self.width | |
| return self.height * scale <= target.height ? | |
| scale : |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension UIBezierPath | |
| { | |
| func interpolatePointsWithHermite(interpolationPoints : [CGPoint]) | |
| { | |
| let n = interpolationPoints.count - 1 | |
| for var ii = 0; ii < n; ++ii | |
| { | |
| var currentPoint = interpolationPoints[ii] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension CGPoint | |
| { | |
| func distanceTo(point: CGPoint) -> CGFloat | |
| { | |
| return hypot(self.x - point.x, self.y - point.y) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ThresholdFilter: CIFilter | |
| { | |
| var inputImage : CIImage? | |
| var threshold: CGFloat = 0.75 | |
| let thresholdKernel = CIColorKernel(string: | |
| "kernel vec4 thresholdFilter(__sample image, float threshold)" + | |
| "{" + | |
| " float luma = (image.r * 0.2126) + (image.g * 0.7152) + (image.b * 0.0722);" + | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| typealias RGBA = (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) | |
| extension UIColor | |
| { | |
| func multiply(value: CGFloat) -> UIColor | |
| { | |
| let newRed = getRGBA().red * value | |
| let newGreen = getRGBA().green * value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension CIVector | |
| { | |
| func toArray() -> [CGFloat] | |
| { | |
| var returnArray = [CGFloat]() | |
| for i in 0 ..< self.count | |
| { | |
| returnArray.append(self.valueAtIndex(i)) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension CGRect | |
| { | |
| /// Return corners in order of top left, top right, bottom left, bottom right | |
| var corners: [CGPoint] | |
| { | |
| return [ | |
| CGPoint(x: minX, y: minY), | |
| CGPoint(x: maxX, y: minY), | |
| CGPoint(x: minX, y: maxY), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func UIImageEqualToImage(image1: UIImage, _ image2: UIImage, ciContext: CIContext? = nil) -> Bool | |
| { | |
| guard let | |
| ciImage1 = CIImage(image: image1), | |
| ciImage2 = CIImage(image: image2) where image1.size == image2.size else | |
| { | |
| return false | |
| } | |
| let ctx = ciContext ?? CIContext() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Could benefit from some defensive coding :) | |
| import Photos | |
| let url = info[UIImagePickerControllerReferenceURL] as! NSURL | |
| let fetchResult = PHAsset.fetchAssetsWithALAssetURLs([url], options: nil) | |
| let asset = fetchResult.firstObject as! PHAsset |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension CGFloat | |
| { | |
| func saturate() -> CGFloat | |
| { | |
| return self < 0 ? 0 : self > 1 ? 1 : self | |
| } | |
| func smootherStep() -> CGFloat | |
| { | |
| let x = self.saturate() |
OlderNewer