Created
June 29, 2019 21:36
-
-
Save alo9507/8875090cd3de0c1dcc6a49b7512ac90e to your computer and use it in GitHub Desktop.
getCardinalDirectionFromYaw
This file contains 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 CardinalDirection: String { | |
case North = "North" | |
case South = "South" | |
case East = "East" | |
case West = "West" | |
case InBetween = "InBetween" | |
} | |
enum RotationDirection { | |
case Clockwise | |
case Counterclockwise | |
} | |
func getCardinalDirectionFromYaw(yaw: Double, accuracy: Double) { | |
let cardinalDirection: CardinalDirection | |
let OFFSET: Double = 23.5 | |
if (accuracy >= 1.91) { | |
let rotationDirection: RotationDirection = yaw < 0 ? RotationDirection.Counterclockwise : RotationDirection.Clockwise | |
switch yaw { | |
case 360-OFFSET..<OFFSET: | |
cardinalDirection = CardinalDirection.North | |
case 90-OFFSET..<90+OFFSET: | |
cardinalDirection = CardinalDirection.East | |
case 180-OFFSET..<180+OFFSET: | |
cardinalDirection = CardinalDirection.South | |
case 270-OFFSET..<270+OFFSET: | |
cardinalDirection = CardinalDirection.West | |
default: | |
cardinalDirection = CardinalDirection.InBetween | |
} | |
headingValue.text = cardinalDirection.rawValue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment