Skip to content

Commit

Permalink
Change all M_PI to .pi
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeLin committed Jul 2, 2016
1 parent 850d5dc commit 10104cd
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions IBAnimatable/Animatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ public extension Animatable where Self: UIView {
public func rotate(_ clockwise: Bool = true, completion: AnimatableCompletion? = nil) {
CALayer.animate({
let animation = CABasicAnimation(keyPath: "transform.rotation")
animation.fromValue = clockwise ? 0 : ((360 * M_PI) / 180)
animation.toValue = clockwise ? ((360 * M_PI) / 180) : 0
animation.fromValue = clockwise ? 0 : CGFloat.pi * 2
animation.toValue = clockwise ? CGFloat.pi * 2 : 0
animation.duration = CFTimeInterval(self.duration)
animation.repeatCount = self.repeatCount
animation.autoreverses = false
Expand Down
2 changes: 1 addition & 1 deletion IBAnimatable/AnimatableButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import UIKit
@IBInspectable private var maskType: String? {
didSet {
if let maskType = maskType {
eMaskType = MaskType(string:maskType);
eMaskType = MaskType(string:maskType)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion IBAnimatable/AnimatableCheckBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ import UIKit
@IBInspectable private var maskType: String? {
didSet {
if let maskType = maskType {
eMaskType = MaskType(string:maskType);
eMaskType = MaskType(string:maskType)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion IBAnimatable/AnimatableStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ import UIKit
@IBInspectable private var maskType: String? {
didSet {
if let maskType = maskType {
eMaskType = MaskType(string:maskType);
eMaskType = MaskType(string:maskType)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion IBAnimatable/AnimatableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ import UIKit
@IBInspectable private var maskType: String? {
didSet {
if let maskType = maskType {
eMaskType = MaskType(string:maskType);
eMaskType = MaskType(string:maskType)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion IBAnimatable/CardsAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private extension CardsAnimator {
var t1 = CATransform3DIdentity
t1.m34 = 1.0 / -900
t1 = CATransform3DScale(t1, 0.95, 0.95, 1)
t1 = CATransform3DRotate(t1, 15.0 * CGFloat(M_PI) / 180.0, 1, 0, 0)
t1 = CATransform3DRotate(t1, 15.0 * .pi / 180.0, 1, 0, 0)
return t1
}

Expand Down
4 changes: 2 additions & 2 deletions IBAnimatable/FlipAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private extension FlipAnimator {
axesValues = valuesForAxe(reverse ? 1.0 : 0.0, reverseValue: 0.5)
updateAnchorPointAndOffset(CGPoint(x: axesValues.0, y: axesValues.1), view: flippedSectionOfToView)

flippedSectionOfToView.layer.transform = rotate(reverse ? M_PI_2 : -M_PI_2)
flippedSectionOfToView.layer.transform = rotate(reverse ? .pi * 2 : -.pi * 2)
return ((flippedSectionOfFromView, flippedSectionOfFromViewShadow), (flippedSectionOfToView, flippedSectionOfToViewShadow))
}

Expand Down Expand Up @@ -177,7 +177,7 @@ private extension FlipAnimator {
func animateFlipTransition(_ flippedSectionOfFromView: (UIView, UIView), flippedSectionOfToView: (UIView, UIView), completion: AnimatableCompletion) {
UIView.animateKeyframes(withDuration: transitionDuration, delay: 0, options: .layoutSubviews, animations: {
UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.5, animations: {
flippedSectionOfFromView.0.layer.transform = self.rotate(self.reverse ? -M_PI_2 : M_PI_2)
flippedSectionOfFromView.0.layer.transform = self.rotate(self.reverse ? -.pi * 2 : .pi * 2)
flippedSectionOfFromView.1.alpha = 1.0
})

Expand Down
8 changes: 4 additions & 4 deletions IBAnimatable/FoldAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ private extension FoldAnimator {
axesValues = valuesForAxe(self.reverse ? width : 0.0, reverseValue: height / 2)
leftToViewFold.layer.position = CGPoint(x: axesValues.0, y: axesValues.1)
axesValues = valuesForAxe(0.0, reverseValue: 1.0)
leftToViewFold.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI_2), axesValues.0, axesValues.1, 0.0)
leftToViewFold.layer.transform = CATransform3DMakeRotation(.pi * 2, axesValues.0, axesValues.1, 0.0)
toViewFolds.append(leftToViewFold)

let rightToViewFold = createSnapshot(fromView: toView, afterUpdates: true, offset: offset + foldSize, left: false)
axesValues = valuesForAxe(self.reverse ? width : 0.0, reverseValue: height / 2)
rightToViewFold.layer.position = CGPoint(x: axesValues.0, y: axesValues.1)
axesValues = valuesForAxe(0.0, reverseValue: 1.0)
rightToViewFold.layer.transform = CATransform3DMakeRotation(CGFloat(-M_PI_2), axesValues.0, axesValues.1, 0.0)
rightToViewFold.layer.transform = CATransform3DMakeRotation(-.pi * 2, axesValues.0, axesValues.1, 0.0)
toViewFolds.append(rightToViewFold)
}
return [toViewFolds, fromViewFolds]
Expand Down Expand Up @@ -204,14 +204,14 @@ private extension FoldAnimator {
var axesValues = self.valuesForAxe(self.reverse ? 0.0 : self.width, reverseValue: self.height / 2)
leftFromView.layer.position = CGPoint(x: axesValues.0, y: axesValues.1)
axesValues = self.valuesForAxe(0.0, reverseValue: 1.0)
leftFromView.layer.transform = CATransform3DRotate(self.transform, CGFloat(M_PI_2), axesValues.0, axesValues.1, 0)
leftFromView.layer.transform = CATransform3DRotate(self.transform, .pi * 2, axesValues.0, axesValues.1, 0)
leftFromView.subviews[1].alpha = 1.0

let rightFromView = fromViewFolds[i * 2 + 1]
axesValues = self.valuesForAxe(self.reverse ? 0.0 : self.width, reverseValue: self.height / 2)
rightFromView.layer.position = CGPoint(x: axesValues.0, y: axesValues.1)
axesValues = self.valuesForAxe(0.0, reverseValue: 1.0)
rightFromView.layer.transform = CATransform3DRotate(self.transform, CGFloat(-M_PI_2), axesValues.0, axesValues.1, 0)
rightFromView.layer.transform = CATransform3DRotate(self.transform, -.pi * 2, axesValues.0, axesValues.1, 0)
rightFromView.subviews[1].alpha = 1.0

let leftToView = toViewFolds[i * 2]
Expand Down
8 changes: 4 additions & 4 deletions IBAnimatable/IBEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public extension IBEnum {
/// this method will return "wave"
static func extractNameAndParams(_ string:String) -> (name:String, params:[String]) {
let tokens = string.components(separatedBy: CharacterSet(charactersIn: "()")).filter({!$0.isEmpty}) // extract params list self.enumName
let maskName = tokens.first ?? "";
let paramsString = tokens.count >= 2 ? tokens[1] : "";
let params = paramsString.components(separatedBy: ","); // params list
return (name:maskName, params:params);
let maskName = tokens.first ?? ""
let paramsString = tokens.count >= 2 ? tokens[1] : ""
let params = paramsString.components(separatedBy: ",") // params list
return (name:maskName, params:params)
}

}
30 changes: 15 additions & 15 deletions IBAnimatable/MaskDesignable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public extension MaskDesignable where Self: UIView {
case .triangle:
maskTriangle()
case .none:
return;
return
}
}

Expand All @@ -54,8 +54,8 @@ public extension MaskDesignable where Self: UIView {
private func maskPolygonBezierPath(_ sides: Int) -> UIBezierPath {
let path = UIBezierPath()
let center = CGPoint(x: bounds.width / 2.0, y: bounds.height / 2.0)
var angle: CGFloat = -CGFloat(M_PI / 2.0)
let angleIncrement = CGFloat(M_PI * 2.0 / Double(sides))
var angle: CGFloat = -.pi / 2
let angleIncrement = .pi * 2 / CGFloat(sides)
let length = min(bounds.width, bounds.height)
let radius = length / 2.0

Expand Down Expand Up @@ -88,9 +88,9 @@ public extension MaskDesignable where Self: UIView {
let path = UIBezierPath()
let radius = min(bounds.size.width, bounds.size.height) / 2 - borderWidth
let starExtrusion = radius / 2
let angleIncrement = CGFloat(M_PI * 2.0 / Double(points))
let angleIncrement = .pi * 2 / CGFloat(points)
let center = CGPoint(x: bounds.width / 2.0, y: bounds.height / 2.0)
var angle = -CGFloat(M_PI / 2.0)
var angle: CGFloat = -.pi / 2
var firstPoint = true
for _ in 1...points {
let point = pointFrom(angle, radius: radius, offset: center)
Expand All @@ -114,28 +114,28 @@ public extension MaskDesignable where Self: UIView {
// MARK: - Parallelogram

private func maskParallelogram(_ topLeftAngle:Double = 60) {
let parallelogramPath = maskParallelogramBezierPath(topLeftAngle);
let parallelogramPath = maskParallelogramBezierPath(topLeftAngle)
drawPath(parallelogramPath)
}

private func maskParallelogramBezierPath(_ topLeftAngle:Double) -> UIBezierPath {
let topLeftAngleRad = Double(topLeftAngle) * M_PI / 180;
let path = UIBezierPath();
let offset = abs(CGFloat(tan(topLeftAngleRad - M_PI / 2)) * bounds.height);
let topLeftAngleRad = topLeftAngle * .pi / 180
let path = UIBezierPath()
let offset = abs(CGFloat(tan(topLeftAngleRad - .pi / 2)) * bounds.height)

if topLeftAngle <= 90 {
path.move(to: CGPoint(x:0, y:0));
if topLeftAngle <= 90 {
path.move(to: CGPoint(x:0, y:0))
path.addLine(to: CGPoint(x: bounds.width - offset, y: 0))
path.addLine(to: CGPoint(x:bounds.width, y:bounds.height))
path.addLine(to: CGPoint(x: offset, y: bounds.height))
} else {
path.move(to: CGPoint(x:offset, y:0))
path.addLine(to: CGPoint(x:bounds.width, y:0))
path.addLine(to: CGPoint(x:bounds.width - offset, y:bounds.height));
path.addLine(to: CGPoint(x:0, y:bounds.height));
path.addLine(to: CGPoint(x:bounds.width - offset, y:bounds.height))
path.addLine(to: CGPoint(x:0, y:bounds.height))
}
path.close()
return path;
return path
}

// MARK: - Triangle
Expand Down Expand Up @@ -206,7 +206,7 @@ public extension MaskDesignable where Self: UIView {
}

private func degree2radian(_ degree: CGFloat) -> CGFloat {
let radian = CGFloat(M_PI) * degree / 180
let radian = .pi * degree / 180
return radian
}

Expand Down
18 changes: 9 additions & 9 deletions IBAnimatable/MaskType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ public enum MaskType: IBEnum {
public extension MaskType {
init(string:String) {
let paramsAndName = MaskType.extractNameAndParams(string)
let name = paramsAndName.name;
let params = paramsAndName.params;
let name = paramsAndName.name
let params = paramsAndName.params

switch name.lowercased() {
case "circle":
self = MaskType.circle
self = .circle
case "polygon":
self = MaskType.polygon(sides: nil)
self = .polygon(sides: nil)
case "star":
self = MaskType.star(points: Int(params[0]))
self = .star(points: Int(params[0]))
case "triangle":
self = MaskType.triangle;
self = .triangle
case "wave":
self = MaskType.wave(direction: WaveDirection(rawValue:params[0].lowercased()), width: Float(params[1]), offset:Float(params[2]))
self = .wave(direction: WaveDirection(rawValue:params[0].lowercased()), width: Float(params[1]), offset:Float(params[2]))
case "parallelogram":
self = MaskType.parallelogram(angle: Double(params[0]))
self = .parallelogram(angle: Double(params[0]))
default:
self = MaskType.none
self = .none
}
}
}
2 changes: 1 addition & 1 deletion IBAnimatable/NatGeoAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private extension NatGeoAnimator {
}

func radianFromDegree(_ degrees: Double) -> CGFloat {
return CGFloat((degrees / 180) * M_PI)
return CGFloat((degrees / 180) * .pi)
}

func animationDidFinish(_ transitionContext: UIViewControllerContextTransitioning, containerView: UIView, fromView: UIView, toView: UIView) {
Expand Down
2 changes: 1 addition & 1 deletion IBAnimatable/RotationDesignable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public protocol RotationDesignable {
public extension RotationDesignable where Self: UIView {
public func configRotate() {
if !rotate.isNaN && rotate > -360 && rotate < 360 {
self.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI) * rotate / 180)
self.transform = CGAffineTransform(rotationAngle: .pi * rotate / 180)
}
}
}
4 changes: 2 additions & 2 deletions IBAnimatable/TurnAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ extension TurnAnimator: UIViewControllerAnimatedTransitioning {

private func animateTurnTransition(_ fromView: UIView, toView: UIView, completion: AnimatableCompletion) {
let factor = reverse ? 1.0 : -1.0
toView.layer.transform = rotate(factor * -M_PI_2)
toView.layer.transform = rotate(factor * -.pi * 2)
UIView.animateKeyframes(withDuration: transitionDuration, delay: 0.0, options: .layoutSubviews, animations: {
UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.5) {
fromView.layer.transform = self.rotate(factor * M_PI_2)
fromView.layer.transform = self.rotate(factor * .pi * 2)
}

UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5) {
Expand Down

0 comments on commit 10104cd

Please sign in to comment.