Skip to content

Instantly share code, notes, and snippets.

@sssbohdan
Last active May 25, 2017 14:35
Show Gist options
  • Save sssbohdan/650d6a9bc26f2aa936200448a1d30bb7 to your computer and use it in GitHub Desktop.
Save sssbohdan/650d6a9bc26f2aa936200448a1d30bb7 to your computer and use it in GitHub Desktop.
WorldSideEnum
//
// WorldSide.swift
//
//
// Created by Bohdan Savych on 5/16/17.
// Copyright © 2017 Bohdan Savych. All rights reserved.
//
import UIKit
enum WorldSide {
case north,
south,
east,
west
var opposite: WorldSide {
switch self {
case .north:
return .south
case .south:
return .north
case .west:
return .east
case .east:
return .west
}
}
func getAngleByRotating(to side: WorldSide) -> Double {
if self == side {
return 0
}
if self == opposite {
return -M_PI
}
switch self {
case .east:
return side == .north ? M_PI_2 : -M_PI_2
case .west:
return side == .south ? M_PI_2 : -M_PI_2
case .north:
return side == .west ? M_PI_2 : -M_PI_2
case .south:
return side == .east ? M_PI_2 : -M_PI_2
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment