Created
March 16, 2017 08:00
-
-
Save armcknight/1fc2b992607093e8a6cbb698b6ad8003 to your computer and use it in GitHub Desktop.
First attempt at snapping to angle intervals in Trgnmtry
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
public func snappedAngle(snappingAngle: Angle) -> Angle { | |
if snappingAngle.radians == 0 { | |
return self | |
} | |
let interval = Int(degrees / (snappingAngle.degrees / 2)) | |
if interval == 0 { | |
return .zero | |
} else if interval == Int(360 / (snappingAngle.degrees / 2) - 1) { | |
return Angle(degrees: 360) | |
} else { | |
let factor = interval / 2 | |
return Angle(radians: snappingAngle.radians * Radian(factor)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment