Created
August 12, 2014 21:22
-
-
Save kourge/46f6c8b90e25997485e2 to your computer and use it in GitHub Desktop.
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
enum Quadrant { | |
case BottomLeft | |
case TopLeft | |
case BottomRight | |
case TopRight | |
static func forPoint(point: CGPoint) -> Quadrant { | |
switch (point.x, point.y) { | |
case (let x, let y) where x >= 0 && y >= 0: | |
return .TopRight | |
case (let x, let y) where x >= 0 && y < 0: | |
return .BottomRight | |
case (let x, let y) where x < 0 && y >= 0: | |
return .TopLeft | |
case (let x, let y) where x < 0 && y < 0: | |
return .BottomLeft | |
default: | |
return .TopRight | |
} | |
} | |
// Abusing Unit for fun and profit | |
static func forPoint2(point: CGPoint) -> Quadrant { | |
let (x, y) = (point.x, point.y) | |
switch () { | |
case () where x >= 0 && y >= 0: | |
return .TopRight | |
case () where x >= 0 && y < 0: | |
return .BottomRight | |
case () where x < 0 && y >= 0: | |
return .TopLeft | |
case () where x < 0 && y < 0: | |
return .BottomLeft | |
default: | |
return .TopRight | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment