Skip to content

Instantly share code, notes, and snippets.

@kourge
Created August 12, 2014 21:22
Show Gist options
  • Save kourge/46f6c8b90e25997485e2 to your computer and use it in GitHub Desktop.
Save kourge/46f6c8b90e25997485e2 to your computer and use it in GitHub Desktop.
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