Skip to content

Commit

Permalink
Merge pull request #25 from emouawad/master
Browse files Browse the repository at this point in the history
Updates to support Swift 3
  • Loading branch information
yoavlt committed Jan 19, 2017
2 parents efd1ee4 + e1ef3b2 commit d62ee85
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 160 deletions.
2 changes: 1 addition & 1 deletion Example/Pods/Local Podspecs/LiquidLoader.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 27 additions & 7 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions Pod/Classes/ArrayEx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

extension Array {
func take(n: Int) -> [Element] {
func take(_ n: Int) -> [Element] {
if self.count == 0 {
return []
}
Expand All @@ -21,13 +21,13 @@ extension Array {
return result
}

func each(f: (Element) -> ()) {
func each(_ f: (Element) -> ()) {
for item in self {
f(item)
}
}

func eachWithIndex(f: (Int, Element) -> ()) {
func eachWithIndex(_ f: (Int, Element) -> ()) {
if self.count <= 0 {
return
}
Expand All @@ -36,23 +36,23 @@ extension Array {
}
}

func zip<U>(other: [U]) -> [(Element, U)] {
func zip<U>(_ other: [U]) -> [(Element, U)] {
var result = [(Element, U)]()
for (p, q) in Swift.zip(self, other) {
result.append((p, q))
}
return result
}

func indexOf <U: Equatable> (item: U) -> Int? {
func indexOf <U: Equatable> (_ item: U) -> Int? {
if item is Element {
return unsafeBitCast(self, [U].self).indexOf(item)
return unsafeBitCast(self, to: [U].self).indexOf(item)
}

return nil
}

func find (f: (Element) -> Bool) -> Element? {
func find (_ f: (Element) -> Bool) -> Element? {
for value in self {
if f(value) {
return value
Expand All @@ -61,7 +61,7 @@ extension Array {
return nil
}

func mapWithIndex<U>(f: (Int, Element) -> U) -> [U] {
func mapWithIndex<U>(_ f: (Int, Element) -> U) -> [U] {
if self.isEmpty {
return []
}
Expand All @@ -74,7 +74,7 @@ extension Array {
return elements
}

func without<U: Equatable>(target: U) -> [U] {
func without<U: Equatable>(_ target: U) -> [U] {
var results: [U] = []
for item in self {
if item as! U != target {
Expand All @@ -84,7 +84,7 @@ extension Array {
return results
}

func at(index: Int) -> Element? {
func at(_ index: Int) -> Element? {
if count > index {
return self[index]
}
Expand Down
38 changes: 19 additions & 19 deletions Pod/Classes/CGPointEx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@ import UIKit
extension CGPoint {

// 足し算
func plus(point: CGPoint) -> CGPoint {
func plus(_ point: CGPoint) -> CGPoint {
return CGPoint(x: self.x + point.x, y: self.y + point.y)
}

func plusX(dx: CGFloat) -> CGPoint {
func plusX(_ dx: CGFloat) -> CGPoint {
return CGPoint(x: self.x + dx, y: self.y)
}

func plusY(dy: CGFloat) -> CGPoint {
func plusY(_ dy: CGFloat) -> CGPoint {
return CGPoint(x: self.x, y: self.y + dy)
}

// 引き算
func minus(point: CGPoint) -> CGPoint {
func minus(_ point: CGPoint) -> CGPoint {
return CGPoint(x: self.x - point.x, y: self.y - point.y)
}

func minusX(dx: CGFloat) -> CGPoint {
func minusX(_ dx: CGFloat) -> CGPoint {
return CGPoint(x: self.x - dx, y: self.y)
}

func minusY(dy: CGFloat) -> CGPoint {
func minusY(_ dy: CGFloat) -> CGPoint {
return CGPoint(x: self.x, y: self.y - dy)
}

// 掛け算
func mul(rhs: CGFloat) -> CGPoint {
func mul(_ rhs: CGFloat) -> CGPoint {
return CGPoint(x: self.x * rhs, y: self.y * rhs)
}

// 割り算
func div(rhs: CGFloat) -> CGPoint {
func div(_ rhs: CGFloat) -> CGPoint {
return CGPoint(x: self.x / rhs, y: self.y / rhs)
}

Expand All @@ -67,13 +67,13 @@ extension CGPoint {
}

// リフレクション
func refX(target: CGPoint) -> CGPoint {
func refX(_ target: CGPoint) -> CGPoint {
let distance = target.x - self.x
return CGPoint(x: self.x - distance, y: self.y)
}

// リフレクション
func refY(target: CGPoint) -> CGPoint {
func refY(_ target: CGPoint) -> CGPoint {
let distance = target.y - self.y
return CGPoint(x: self.x, y: self.y - distance)
}
Expand All @@ -88,37 +88,37 @@ extension CGPoint {
}

// 内積
func dot(point: CGPoint) -> CGFloat {
func dot(_ point: CGPoint) -> CGFloat {
return self.x * point.x + self.y * point.y
}

// 外積
func cross(point: CGPoint) -> CGFloat {
func cross(_ point: CGPoint) -> CGFloat {
return self.x * point.y - self.y * point.x
}

func split(point: CGPoint, ratio: CGFloat) -> CGPoint {
func split(_ point: CGPoint, ratio: CGFloat) -> CGPoint {
return self.mul(ratio).plus(point.mul(1.0 - ratio))
}

func mid(point: CGPoint) -> CGPoint {
func mid(_ point: CGPoint) -> CGPoint {
return split(point, ratio: 0.5)
}

func areaSize(point: CGPoint) -> CGSize {
func areaSize(_ point: CGPoint) -> CGSize {
return CGSize(width: abs(x - point.x), height: abs(y - point.y))
}

func area(point: CGPoint) -> CGFloat {
func area(_ point: CGPoint) -> CGFloat {
let size = areaSize(point)
return size.width * size.height
}

func origin(point: CGPoint) -> CGPoint {
func origin(_ point: CGPoint) -> CGPoint {
return CGPoint(x: min(x, point.x), y: min(y, point.y))
}

static func intersection(from: CGPoint, to: CGPoint, from2: CGPoint, to2: CGPoint) -> CGPoint? {
static func intersection(_ from: CGPoint, to: CGPoint, from2: CGPoint, to2: CGPoint) -> CGPoint? {
let ac = CGPoint(x: to.x - from.x, y: to.y - from.y)
let bd = CGPoint(x: to2.x - from2.x, y: to2.y - from2.y)
let ab = CGPoint(x: from2.x - from.x, y: from2.y - from.y)
Expand All @@ -139,4 +139,4 @@ extension CGPoint {
return CGSize(width: self.x, height: self.y)
}

}
}
11 changes: 7 additions & 4 deletions Pod/Classes/CircularGradientLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ class CircularGradientLayer : CALayer {
fatalError("init(coder:) has not been implemented")
}

override func drawInContext(ctx: CGContext) {
override func draw(in ctx: CGContext) {
var locations = CGMath.linSpace(0.0, to: 1.0, n: colors.count)
locations = Array(locations.map { 1.0 - $0 * $0 }.reverse())
let gradients = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), colors.map { $0.CGColor }, locations)
CGContextDrawRadialGradient(ctx, gradients!, self.frame.center, CGFloat(0.0), self.frame.center, max(self.frame.width, self.frame.height), CGGradientDrawingOptions(rawValue: 10))
locations = Array(locations.map { 1.0 - $0 * $0 }.reversed())

let cols = colors.map { $0.cgColor }
let gradients = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: cols as CFArray, locations: locations)

ctx.drawRadialGradient(gradients!, startCenter: self.frame.center, startRadius: CGFloat(0.0), endCenter: self.frame.center, endRadius: max(self.frame.width, self.frame.height), options: CGGradientDrawingOptions(rawValue: 10))
}
}
8 changes: 4 additions & 4 deletions Pod/Classes/LiquidCircleEffect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class LiquidCircleEffect : LiquidLoadEffect {
}
}

override func movePosition(key: CGFloat) -> CGPoint {
guard self.loader != nil else {return CGPointZero}
override func movePosition(_ key: CGFloat) -> CGPoint {
guard self.loader != nil else {return CGPoint.zero}

let frame = self.loader!.frame.center.minus(self.loader!.frame.origin)
return CGMath.circlePoint(
Expand Down Expand Up @@ -66,7 +66,7 @@ class LiquidCircleEffect : LiquidLoadEffect {
let moveVec = moveCircle!.center.minus(loader.center.minus(loader.frame.origin)).normalized()
circles.map { circle in
return (circle, moveVec.dot(circle.center.minus(self.loader.center.minus(self.loader.frame.origin)).normalized()))
}.each { (let circle, let dot) in
}.each { (circle, dot) in
if 0.75 < dot && dot <= 1.0 {
let normalized = (dot - 0.75) / 0.25
let scale = normalized * normalized
Expand All @@ -77,4 +77,4 @@ class LiquidCircleEffect : LiquidLoadEffect {
}
}

}
}
Loading

0 comments on commit d62ee85

Please sign in to comment.