Skip to content

Instantly share code, notes, and snippets.

@armcknight
Created March 16, 2017 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armcknight/1fc2b992607093e8a6cbb698b6ad8003 to your computer and use it in GitHub Desktop.
Save armcknight/1fc2b992607093e8a6cbb698b6ad8003 to your computer and use it in GitHub Desktop.
First attempt at snapping to angle intervals in Trgnmtry
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